MCPcopy Create free account
hub / github.com/PyO3/rust-numpy / polymorphic_add

Function polymorphic_add

examples/simple/src/lib.rs:120–148  ·  view source on GitHub ↗
(
        x: SupportedArray<'py>,
        y: SupportedArray<'py>,
    )

Source from the content-addressed store, hash-verified

118
119 #[pyfunction]
120 fn polymorphic_add<'py>(
121 x: SupportedArray<'py>,
122 y: SupportedArray<'py>,
123 ) -> PyResult<Bound<'py, PyAny>> {
124 match (x, y) {
125 (SupportedArray::F64(x), SupportedArray::F64(y)) => Ok(generic_add(
126 x.readonly().as_array(),
127 y.readonly().as_array(),
128 )
129 .into_pyarray(x.py())
130 .into_any()),
131 (SupportedArray::I64(x), SupportedArray::I64(y)) => Ok(generic_add(
132 x.readonly().as_array(),
133 y.readonly().as_array(),
134 )
135 .into_pyarray(x.py())
136 .into_any()),
137 (SupportedArray::F64(x), SupportedArray::I64(y))
138 | (SupportedArray::I64(y), SupportedArray::F64(x)) => {
139 let y = y.cast_array::<f64>(false)?;
140
141 Ok(
142 generic_add(x.readonly().as_array(), y.readonly().as_array())
143 .into_pyarray(x.py())
144 .into_any(),
145 )
146 }
147 }
148 }
149}

Callers 1

test_polymorphic_addFunction · 0.85

Calls 4

generic_addFunction · 0.85
into_pyarrayMethod · 0.80
readonlyMethod · 0.80
as_arrayMethod · 0.45

Tested by 1

test_polymorphic_addFunction · 0.68