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

Method borrow_from_array

src/array.rs:334–353  ·  view source on GitHub ↗

Creates a NumPy array backed by `array` and ties its ownership to the Python object `container`. The resulting NumPy array will be writeable from Python space. If this is undesirable, use [PyReadwriteArray::make_nonwriteable]. # Safety `container` is set as a base object of the returned array which must not be dropped until `container` is dropped. Furthermore, `array` must not be reallocated f

(
        array: &ArrayBase<S, D>,
        container: Bound<'py, PyAny>,
    )

Source from the content-addressed store, hash-verified

332 /// }
333 /// ```
334 pub unsafe fn borrow_from_array<'py, S>(
335 array: &ArrayBase<S, D>,
336 container: Bound<'py, PyAny>,
337 ) -> Bound<'py, Self>
338 where
339 S: Data<Elem = T>,
340 {
341 let (strides, dims) = (array.npy_strides(), array.raw_dim());
342 let data_ptr = array.as_ptr();
343
344 let py = container.py();
345
346 Self::new_with_data(
347 py,
348 dims,
349 strides.as_ptr(),
350 data_ptr,
351 container.into_ptr().cast(),
352 )
353 }
354
355 /// Construct a new NumPy array filled with zeros.
356 ///

Callers

nothing calls this directly

Calls 2

npy_stridesMethod · 0.80
castMethod · 0.80

Tested by

no test coverage detected