diff --git a/help.html b/help.html index d79fc34eb..c48a36f80 100644 --- a/help.html +++ b/help.html @@ -1,2 +1,2 @@ -
pub fn get_array_module<'py>(py: Python<'py>) -> PyResult<Bound<'_, PyModule>>
Returns a handle to NumPy’s multiarray module.
Safe interface for NumPy’s N-dimensional arrays
-ndarray
class.PyArray0<T>
.PyArray<T, D>
.Safe interface for NumPy’s N-dimensional arrays
+ndarray
class.PyArray0<T>
.PyArray<T, D>
.pub struct PyArray<T, D>(/* private fields */);
A safe, statically-typed wrapper for NumPy’s ndarray
class.
IntoPyArray
or
from_vec
or from_owned_array
.These methods allocate memory in Python’s private heap via NumPy’s API.
In both cases, PyArray
is managed by Python so it can neither be moved from
nor deallocated manually.
Like new
, all constructor methods of PyArray
return a shared reference &PyArray
instead of an owned value. This design follows PyO3’s ownership concept,
i.e. the return value is GIL-bound owning reference into Python’s heap.
PyArray
has two type parametes T
and D
.
-T
represents the type of its elements, e.g. f32
or [PyObject
].
+T
represents the type of its elements, e.g. f32
or [PyObject
].
D
represents its dimensionality, e.g Ix2
or IxDyn
.
Element types are Rust types which implement the Element
trait.
Dimensions are represented by the ndarray::Dimension
trait.
PyArray1
or PyArrayDyn
.
To specify concrete dimension like 3×4×5
, types which implement the ndarray::IntoDimension
trait are used. Typically, this means arrays like [3, 4, 5]
or tuples like (3, 4, 5)
.
use numpy::{PyArray, PyArrayMethods};
use ndarray::{array, Array};
use pyo3::Python;
@@ -50,7 +50,7 @@ Example
i.e. a pointer into Python’s heap which is independent of the GIL lifetime.
This method can be used to avoid lifetime annotations of function arguments
or return values.
-Example
+§Example
use numpy::{PyArray1, PyArrayMethods};
use pyo3::{Py, Python};
@@ -63,31 +63,31 @@ Example
});
Constructs a reference to a PyArray
from a raw pointer to a Python object.
Constructs a reference to a PyArray
from a raw pointer to a Python object.
This is a wrapper around [pyo3::FromPyPointer::from_owned_ptr_or_opt
] and inherits its safety contract.
Constructs a reference to a PyArray
from a raw point to a Python object.
Constructs a reference to a PyArray
from a raw point to a Python object.
This is a wrapper around [pyo3::FromPyPointer::from_borrowed_ptr_or_opt
] and inherits its safety contract.
PyArray::new_bound
in the futureCreates a new uninitialized NumPy array.
If is_fortran
is true, then it has Fortran/column-major order,
otherwise it has C/row-major order.
The returned array will always be safe to be dropped as the elements must either
be trivially copyable (as indicated by <T as Element>::IS_COPY
) or be pointers
into Python’s heap, which NumPy will automatically zero-initialize.
uget_raw
. Before that, all methods
which produce references to the elements invoke undefined behaviour. In particular,
zero-initialized pointers are not valid instances of PyObject
.
-use numpy::prelude::*;
use numpy::PyArray3;
use pyo3::Python;
@@ -120,19 +120,19 @@ Example
PyArray::borrow_from_array_bound
in the futureCreates a NumPy array backed by array
and ties its ownership to the Python object container
.
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 from the time this method is called and until container
is dropped.
#[pyclass]
struct Owner {
array: Array1<f64>,
@@ -149,12 +149,12 @@ Example
unsafe { PyArray1::borrow_from_array_bound(array, this.into_any()) }
}
}
PyArray::zeros_bound
in the futureDeprecated form of PyArray<T, D>::zeros_bound
Construct a new NumPy array filled with zeros.
If is_fortran
is true, then it has Fortran/column-major order,
@@ -162,7 +162,7 @@
For arrays of Python objects, this will fill the array with valid pointers to zero-valued Python integer objects.
See also numpy.zeros
and PyArray_Zeros
.
use numpy::{PyArray2, PyArrayMethods};
use pyo3::Python;
@@ -171,25 +171,25 @@ Example
assert_eq!(pyarray.readonly().as_slice().unwrap(), [0; 4]);
});
Returns an immutable view of the internal data as a slice.
-Returns an immutable view of the internal data as a slice.
+Calling this method is undefined behaviour if the underlying array
is aliased mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Please consider the safe alternative PyReadonlyArray::as_slice
.
Returns a mutable view of the internal data as a slice.
-Returns a mutable view of the internal data as a slice.
+Calling this method is undefined behaviour if the underlying array
is aliased immutably or mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Please consider the safe alternative PyReadwriteArray::as_slice_mut
.
Deprecated form of PyArray<T, D>::from_owned_array_bound
Deprecated form of PyArray<T, D>::from_owned_array_bound
Constructs a NumPy from an ndarray::Array
This method uses the internal Vec
of the ndarray::Array
as the base object of the NumPy array.
This method uses the internal Vec
of the ndarray::Array
as the base object of the NumPy array.
use numpy::{PyArray, PyArrayMethods};
use ndarray::array;
use pyo3::Python;
@@ -199,13 +199,13 @@ Example
assert_eq!(pyarray.readonly().as_array(), array![[1, 2], [3, 4]]);
});
Get a reference of the specified element if the given index is valid.
-Get a reference of the specified element if the given index is valid.
+Calling this method is undefined behaviour if the underlying array
is aliased mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Consider using safe alternatives like PyReadonlyArray::get
.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -214,13 +214,13 @@ Example
assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
});
Same as get
, but returns Option<&mut T>
.
Calling this method is undefined behaviour if the underlying array
is aliased immutably or mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Consider using safe alternatives like PyReadwriteArray::get_mut
.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -233,16 +233,16 @@ Example
assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 42);
});
Get an immutable reference of the specified element, without checking the given index.
See NpyIndex
for what types can be used as the index.
Passing an invalid index is undefined behavior. The element must also have been initialized and all other references to it is must also be shared.
See PyReadonlyArray::get
for a safe alternative.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -251,21 +251,21 @@ Example
assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
});
Same as uget
, but returns &mut T
.
Passing an invalid index is undefined behavior. The element must also have been initialized and other references to it must not exist.
See PyReadwriteArray::get_mut
for a safe alternative.
Turn an array with fixed dimensionality into one with dynamic dimensionality.
-Returns a copy of the internal data of the array as a Vec
.
Deprecated form of PyArray<T, D>::from_array_bound
Construct a NumPy array from a ndarray::ArrayBase
.
This method allocates memory in Python’s heap via the NumPy API, and then copies all elements of the array there.
-use numpy::PyArray;
+§Example
+use numpy::{PyArray, PyArrayMethods};
use ndarray::array;
use pyo3::Python;
Python::with_gil(|py| {
- let pyarray = PyArray::from_array(py, &array![[1, 2], [3, 4]]);
+ let pyarray = PyArray::from_array_bound(py, &array![[1, 2], [3, 4]]);
assert_eq!(pyarray.readonly().as_array(), array![[1, 2], [3, 4]]);
});
-
Get an immutable borrow of the NumPy array
-Get an immutable borrow of the NumPy array
-Get an immutable borrow of the NumPy array
+Get an immutable borrow of the NumPy array
+Panics if the allocation backing the array is currently mutably borrowed.
For a non-panicking variant, use try_readonly
.
Get a mutable borrow of the NumPy array
-Get a mutable borrow of the NumPy array
-Get a mutable borrow of the NumPy array
+Get a mutable borrow of the NumPy array
+Panics if the allocation backing the array is currently borrowed or if the array is flagged as not writeable.
For a non-panicking variant, use try_readwrite
.
Returns an ArrayView
of the internal array.
Returns an ArrayView
of the internal array.
See also PyReadonlyArray::as_array
.
Calling this method invalidates all exclusive references to the internal data, e.g. &mut [T]
or ArrayViewMut
.
Returns an ArrayViewMut
of the internal array.
Returns an ArrayViewMut
of the internal array.
See also PyReadwriteArray::as_array_mut
.
Calling this method invalidates all other references to the internal data, e.g. ArrayView
or ArrayViewMut
.
Returns the internal array as RawArrayView
enabling element access via raw pointers
Returns the internal array as RawArrayViewMut
enabling element access via raw pointers
Get a copy of the array as an ndarray::Array
.
Returns the internal array as RawArrayView
enabling element access via raw pointers
Returns the internal array as RawArrayViewMut
enabling element access via raw pointers
Get a copy of the array as an ndarray::Array
.
use numpy::{PyArray, PyArrayMethods};
use ndarray::array;
use pyo3::Python;
@@ -339,38 +344,38 @@ Example
array![[0, 1], [2, 3]]
)
});
Try to convert this array into a nalgebra::MatrixView
using the given shape and strides.
See PyReadonlyArray::try_as_matrix
for a discussion of the memory layout requirements.
Calling this method invalidates all exclusive references to the internal data, e.g. ArrayViewMut
or MatrixSliceMut
.
Try to convert this array into a nalgebra::MatrixViewMut
using the given shape and strides.
See PyReadonlyArray::try_as_matrix
for a discussion of the memory layout requirements.
Calling this method invalidates all other references to the internal data, e.g. ArrayView
, MatrixSlice
, ArrayViewMut
or MatrixSliceMut
.
Deprecated form of PyArray<T, D>::from_owned_object_array_bound
Deprecated form of PyArray<T, D>::from_owned_object_array_bound
Construct a NumPy array containing objects stored in a ndarray::Array
This method uses the internal Vec
of the ndarray::Array
as the base object of the NumPy array.
This method uses the internal Vec
of the ndarray::Array
as the base object of the NumPy array.
use ndarray::array;
use pyo3::{pyclass, Py, Python};
use numpy::{PyArray, PyArrayMethods};
@@ -397,11 +402,11 @@ Example
assert!(pyarray.readonly().as_array().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>());
});
PyArray::from_slice_bound
in the futureDeprecated form of PyArray<T, Ix1>::from_slice_bound
PyArray::from_slice_bound
in the futureDeprecated form of PyArray<T, Ix1>::from_slice_bound
Construct a one-dimensional array from a Vec<T>
.
use numpy::PyArray;
+
PyArray::from_vec_bound
in the futureDeprecated form of PyArray<T, Ix1>::from_vec_bound
Construct a one-dimensional array from a Vec<T>
.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
Python::with_gil(|py| {
let vec = vec![1, 2, 3, 4, 5];
- let pyarray = PyArray::from_vec(py, vec);
+ let pyarray = PyArray::from_vec_bound(py, vec);
assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]);
});
Deprecated form of PyArray<T, Ix1>::from_iter_bound
Construct a one-dimensional array from an Iterator
.
If no reliable size_hint
is available,
this method can allocate memory multiple times, which can hurt performance.
use numpy::PyArray;
+§Example
+use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
Python::with_gil(|py| {
- let pyarray = PyArray::from_iter(py, "abcde".chars().map(u32::from));
+ let pyarray = PyArray::from_iter_bound(py, "abcde".chars().map(u32::from));
assert_eq!(pyarray.readonly().as_slice().unwrap(), &[97, 98, 99, 100, 101]);
});
-
PyArray::from_vec2_bound
in the futureDeprecated form of PyArray<T, Ix2>::from_vec2_bound
Construct a two-dimension array from a Vec<Vec<T>>
.
Construct a two-dimension array from a Vec<Vec<T>>
.
This function checks all dimensions of the inner vectors and returns an error if they are not all equal.
-use numpy::PyArray;
+§Example
+use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
use ndarray::array;
Python::with_gil(|py| {
let vec2 = vec![vec![11, 12], vec![21, 22]];
- let pyarray = PyArray::from_vec2(py, &vec2).unwrap();
+ let pyarray = PyArray::from_vec2_bound(py, &vec2).unwrap();
assert_eq!(pyarray.readonly().as_array(), array![[11, 12], [21, 22]]);
let ragged_vec2 = vec![vec![11, 12], vec![21]];
- assert!(PyArray::from_vec2(py, &ragged_vec2).is_err());
+ assert!(PyArray::from_vec2_bound(py, &ragged_vec2).is_err());
});
-
PyArray::from_vec3_bound
in the futureDeprecated form of PyArray<T, Ix3>::from_vec3_bound
Construct a three-dimensional array from a Vec<Vec<Vec<T>>>
.
Construct a three-dimensional array from a Vec<Vec<Vec<T>>>
.
This function checks all dimensions of the inner vectors and returns an error if they are not all equal.
-use numpy::PyArray;
+§Example
+use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
use ndarray::array;
@@ -467,7 +483,7 @@ Example
vec![vec![111, 112], vec![121, 122]],
vec![vec![211, 212], vec![221, 222]],
];
- let pyarray = PyArray::from_vec3(py, &vec3).unwrap();
+ let pyarray = PyArray::from_vec3_bound(py, &vec3).unwrap();
assert_eq!(
pyarray.readonly().as_array(),
array![[[111, 112], [121, 122]], [[211, 212], [221, 222]]]
@@ -477,11 +493,11 @@ Example
vec![vec![111, 112], vec![121, 122]],
vec![vec![211], vec![221, 222]],
];
- assert!(PyArray::from_vec3(py, &ragged_vec3).is_err());
+ assert!(PyArray::from_vec3_bound(py, &ragged_vec3).is_err());
});
-
Copies self
into other
, performing a data type conversion if necessary.
See also PyArray_CopyInto
.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -493,12 +509,12 @@ Example
assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
});
Cast the PyArray<T>
to PyArray<U>
, by allocating a new array.
See also PyArray_CastToType
.
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -509,7 +525,7 @@ Example
assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
});
dims
and a possibly different memory order specified by order
.
See also numpy.reshape
and PyArray_Newshape
.
use numpy::{npyffi::NPY_ORDER, PyArray};
+§Example
+use numpy::prelude::*;
+use numpy::{npyffi::NPY_ORDER, PyArray};
use pyo3::Python;
use ndarray::array;
Python::with_gil(|py| {
let array =
- PyArray::from_iter(py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
+ PyArray::from_iter_bound(py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
assert!(array.is_fortran_contiguous());
assert!(array.reshape([5]).is_err());
});
-
Special case of reshape_with_order
which keeps the memory order the same.
Extends or truncates the dimensions of an array.
+Extends or truncates the dimensions of an array.
This method works only on contiguous arrays.
Missing elements will be initialized as if calling zeros
.
See also ndarray.resize
and PyArray_Resize
.
There should be no outstanding references (shared or exclusive) into the array as this method might re-allocate it and thereby invalidate all pointers into it.
-use numpy::prelude::*;
use numpy::PyArray;
use pyo3::Python;
@@ -556,15 +573,15 @@ Example
}
assert_eq!(pyarray.shape(), [100, 100]);
});
Deprecated form of PyArray<T, Ix1>::arange_bound
Deprecated form of PyArray<T, Ix1>::arange_bound
Return evenly spaced values within a given interval.
See numpy.arange for the Python API and PyArray_Arange for the C API.
-use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -575,21 +592,22 @@ Example
let pyarray = PyArray::arange_bound(py, -2, 4, 3);
assert_eq!(pyarray.readonly().as_slice().unwrap(), &[-2, 1]);
});
Returns a raw pointer to the underlying PyArrayObject
.
Returns the dtype
of the array.
Returns a raw pointer to the underlying PyArrayObject
.
Returns the dtype
of the array.
See also ndarray.dtype
and PyArray_DTYPE
.
use numpy::{dtype_bound, PyArray};
+§Example
+use numpy::prelude::*;
+use numpy::{dtype_bound, PyArray};
use pyo3::Python;
Python::with_gil(|py| {
- let array = PyArray::from_vec(py, vec![1_i32, 2, 3]);
+ let array = PyArray::from_vec_bound(py, vec![1_i32, 2, 3]);
- assert!(array.dtype().is_equiv_to(dtype_bound::<i32>(py).as_gil_ref()));
+ assert!(array.dtype().is_equiv_to(&dtype_bound::<i32>(py)));
});
-
Returns true
if the internal data of the array is contiguous,
+
Returns true
if the internal data of the array is contiguous,
indepedently of whether C-style/row-major or Fortran-style/column-major.
use numpy::{PyArray1, PyUntypedArrayMethods};
use pyo3::{types::{IntoPyDict, PyAnyMethods}, Python};
@@ -604,11 +622,11 @@ Example
.unwrap();
assert!(!view.is_contiguous());
});
Returns true
if the internal data of the array is Fortran-style/column-major contiguous.
Returns true
if the internal data of the array is C-style/row-major contiguous.
Returns true
if the internal data of the array is Fortran-style/column-major contiguous.
Returns true
if the internal data of the array is C-style/row-major contiguous.
Returns the number of dimensions of the array.
See also ndarray.ndim
and PyArray_NDIM
.
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;
@@ -617,9 +635,9 @@ Example
assert_eq!(arr.ndim(), 3);
});
Returns a slice indicating how many bytes to advance when iterating along each axis.
+Returns a slice indicating how many bytes to advance when iterating along each axis.
See also ndarray.strides
and PyArray_STRIDES
.
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;
@@ -628,9 +646,9 @@ Example
assert_eq!(arr.strides(), &[240, 48, 8]);
});
Returns a slice which contains dimmensions of the array.
See also [ndarray.shape
][ndaray-shape] and PyArray_DIMS
.
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;
@@ -639,50 +657,50 @@ Example
assert_eq!(arr.shape(), &[4, 5, 6]);
});
Returns whether self
and other
point to the same object. To compare
the equality of two objects (the ==
operator), use eq
.
This is equivalent to the Python expression self is other
.
Determines whether this object has the given attribute.
This is equivalent to the Python expression hasattr(self, attr_name)
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern attr_name
.
intern!
ing the attribute nameintern!
ing the attribute name#[pyfunction]
fn has_version(sys: &Bound<'_, PyModule>) -> PyResult<bool> {
sys.hasattr(intern!(sys.py(), "version"))
}
Retrieves an attribute value.
This is equivalent to the Python expression self.attr_name
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern attr_name
.
intern!
ing the attribute nameintern!
ing the attribute name#[pyfunction]
fn version<'py>(sys: &Bound<'py, PyModule>) -> PyResult<Bound<'py, PyAny>> {
sys.getattr(intern!(sys.py(), "version"))
}
Sets an attribute value.
This is equivalent to the Python expression self.attr_name = value
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern name
.
intern!
ing the attribute nameintern!
ing the attribute name#[pyfunction]
fn set_answer(ob: &Bound<'_, PyAny>) -> PyResult<()> {
ob.setattr(intern!(ob.py(), "answer"), 42)
}
Deletes an attribute.
This is equivalent to the Python statement del self.attr_name
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern attr_name
.
Returns an Ordering
between self
and other
.
Returns an Ordering
between self
and other
.
This is equivalent to the following Python code:
if self == other:
return Equal
@@ -692,7 +710,7 @@ Examples
+
use pyo3::prelude::*;
use pyo3::types::PyFloat;
use std::cmp::Ordering;
@@ -718,7 +736,7 @@ Result<&PyAny, PyErr>where
+) -> Result<&PyAny, PyErr>where
O: ToPyObject,Tests whether two Python objects obey a given [CompareOp
].
lt
, le
, eq
, ne
,
gt
and ge
are the specialized versions
@@ -733,7 +751,7 @@
[CompareOp::Gt
]self > other
[CompareOp::Ge
] self >= other
-
Examples
+§Examples
use pyo3::class::basic::CompareOp;
use pyo3::prelude::*;
use pyo3::types::PyInt;
@@ -744,27 +762,27 @@ assert!(a.rich_compare(b, CompareOp::Le)?.is_truthy()?);
Ok(())
})?;
-
Tests whether this object is less than another.
This is equivalent to the Python expression self < other
.
Tests whether this object is less than or equal to another.
This is equivalent to the Python expression self <= other
.
Tests whether this object is equal to another.
This is equivalent to the Python expression self == other
.
Tests whether this object is not equal to another.
This is equivalent to the Python expression self != other
.
Tests whether this object is greater than another.
This is equivalent to the Python expression self > other
.
Tests whether this object is greater than or equal to another.
This is equivalent to the Python expression self >= other
.
Determines whether this object appears callable.
+Determines whether this object appears callable.
This is equivalent to Python’s callable()
function.
use pyo3::prelude::*;
Python::with_gil(|py| -> PyResult<()> {
@@ -781,10 +799,10 @@ Examples
Calls the object.
+ kwargs: Option<&PyDict> +) -> Result<&PyAny, PyErr>Calls the object.
This is equivalent to the Python expression self(*args, **kwargs)
.
use pyo3::prelude::*;
use pyo3::types::PyDict;
@@ -805,9 +823,9 @@ Examples
assert_eq!(result.extract::<String>()?, "called with args and kwargs");
Ok(())
})
Calls the object with only positional arguments.
+Calls the object with only positional arguments.
This is equivalent to the Python expression self(*args)
.
use pyo3::prelude::*;
const CODE: &str = r#"
@@ -841,14 +859,14 @@ Examples
&self,
name: N,
args: A,
- kwargs: Option<&PyDict>
-) -> Result<&PyAny, PyErr>where
+ kwargs: Option<&PyDict>
+) -> Result<&PyAny, PyErr>where
N: IntoPy<Py<PyString>>,
A: IntoPy<Py<PyTuple>>,Calls a method on the object.
This is equivalent to the Python expression self.name(*args, **kwargs)
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern name
.
-Examples
+§Examples
use pyo3::prelude::*;
use pyo3::types::PyDict;
@@ -871,12 +889,12 @@ Examples
assert_eq!(result.extract::<String>()?, "called with args and kwargs");
Ok(())
})
-pub fn call_method0<N>(&self, name: N) -> Result<&PyAny, PyErr>where
+
pub fn call_method0<N>(&self, name: N) -> Result<&PyAny, PyErr>where
N: IntoPy<Py<PyString>>,
Calls a method on the object without arguments.
This is equivalent to the Python expression self.name()
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern name
.
-Examples
+§Examples
use pyo3::prelude::*;
const CODE: &str = r#"
@@ -895,13 +913,13 @@ Examples
assert_eq!(result.extract::<String>()?, "called with no arguments");
Ok(())
})
-pub fn call_method1<N, A>(&self, name: N, args: A) -> Result<&PyAny, PyErr>where
+
pub fn call_method1<N, A>(&self, name: N, args: A) -> Result<&PyAny, PyErr>where
N: IntoPy<Py<PyString>>,
A: IntoPy<Py<PyTuple>>,
Calls a method on the object with only positional arguments.
This is equivalent to the Python expression self.name(*args)
.
To avoid repeated temporary allocations of Python strings, the [intern!
] macro can be used
to intern name
.
-Examples
+§Examples
use pyo3::prelude::*;
const CODE: &str = r#"
@@ -921,38 +939,38 @@ Examples
assert_eq!(result.extract::<String>()?, "called with args");
Ok(())
})
-pub fn is_true(&self) -> Result<bool, PyErr>
👎Deprecated since 0.21.0: use .is_truthy()
instead
Returns whether the object is considered to be true.
+pub fn is_true(&self) -> Result<bool, PyErr>
👎Deprecated since 0.21.0: use .is_truthy()
instead
Returns whether the object is considered to be true.
This is equivalent to the Python expression bool(self)
.
-pub fn is_truthy(&self) -> Result<bool, PyErr>
Returns whether the object is considered to be true.
+pub fn is_truthy(&self) -> Result<bool, PyErr>
Returns whether the object is considered to be true.
This applies truth value testing equivalent to the Python expression bool(self)
.
-pub fn is_none(&self) -> bool
Returns whether the object is considered to be None.
This is equivalent to the Python expression self is None
.
-pub fn is_ellipsis(&self) -> bool
👎Deprecated since 0.20.0: use .is(py.Ellipsis())
instead
Returns whether the object is Ellipsis, e.g. ...
.
+pub fn is_ellipsis(&self) -> bool
👎Deprecated since 0.20.0: use .is(py.Ellipsis())
instead
Returns whether the object is Ellipsis, e.g. ...
.
This is equivalent to the Python expression self is ...
.
-pub fn is_empty(&self) -> Result<bool, PyErr>
Returns true if the sequence or mapping has a length of 0.
+pub fn is_empty(&self) -> Result<bool, PyErr>
Returns true if the sequence or mapping has a length of 0.
This is equivalent to the Python expression len(self) == 0
.
-pub fn get_item<K>(&self, key: K) -> Result<&PyAny, PyErr>where
K: ToPyObject,
Gets an item from the collection.
This is equivalent to the Python expression self[key]
.
-pub fn set_item<K, V>(&self, key: K, value: V) -> Result<(), PyErr>where
K: ToPyObject,
V: ToPyObject,
Sets a collection item value.
This is equivalent to the Python expression self[key] = value
.
-pub fn del_item<K>(&self, key: K) -> Result<(), PyErr>where
K: ToPyObject,
Deletes an item from the collection.
This is equivalent to the Python expression del self[key]
.
-pub fn iter(&self) -> Result<&PyIterator, PyErr>
Takes an object and returns an iterator for it.
This is typically a new iterator but if the argument is an iterator,
this returns itself.
pub fn get_type(&self) -> &PyType
Returns the Python type object for this object’s type.
-pub fn get_type_ptr(&self) -> *mut PyTypeObject
Returns the Python type pointer for this object.
-pub fn get_type_ptr(&self) -> *mut PyTypeObject
Returns the Python type pointer for this object.
+pub fn downcast<T>(&self) -> Result<&T, PyDowncastError<'_>>where
T: PyTypeCheck<AsRefTarget = T>,
Downcast this PyAny
to a concrete Python type or pyclass.
Note that you can often avoid downcasting yourself by just specifying
the desired type in function or method signatures.
However, manual downcasting is sometimes necessary.
For extracting a Rust-only type, see PyAny::extract
.
-Example: Downcasting to a specific Python object
+§Example: Downcasting to a specific Python object
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList};
@@ -964,7 +982,7 @@ assert!(any.downcast::<PyDict>().is_ok());
assert!(any.downcast::<PyList>().is_err());
});
-Example: Getting a reference to a pyclass
+§Example: Getting a reference to a pyclass
This is useful if you want to mutate a PyObject
that
might actually be a pyclass.
@@ -987,7 +1005,7 @@ assert_eq!(class_ref.i, 1);
Ok(())
})
-pub fn downcast_exact<T>(&self) -> Result<&T, PyDowncastError<'_>>where
+
pub fn downcast_exact<T>(&self) -> Result<&T, PyDowncastError<'_>>where
T: PyTypeInfo<AsRefTarget = T>,
Downcast this PyAny
to a concrete Python type or pyclass (but not a subclass of it).
It is almost always better to use [PyAny::downcast
] because it accounts for Python
subtyping. Use this method only when you do not want to allow subtypes.
@@ -995,7 +1013,7 @@ PyAny::extract
.
-Example: Downcasting to a specific Python object but not a subtype
+§Example: Downcasting to a specific Python object but not a subtype
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyLong};
@@ -1011,92 +1029,93 @@ assert!(any.downcast_exact::<PyBool>().is_ok());
});
-
pub unsafe fn downcast_unchecked<T>(&self) -> &Twhere
+
pub unsafe fn downcast_unchecked<T>(&self) -> &Twhere
T: HasPyGilRef<AsRefTarget = T>,
pub fn extract<'py, D>(&'py self) -> Result<D, PyErr>where
- D: FromPyObject<'py>,
Extracts some type from the Python object.
-This is a wrapper function around [FromPyObject::extract()
].
-pub fn get_refcnt(&self) -> isize
Returns the reference count for the Python object.
-pub fn extract<'py, D>(&'py self) -> Result<D, PyErr>where
+ D: FromPyObjectBound<'py, 'py>,
Extracts some type from the Python object.
+This is a wrapper function around
+FromPyObject::extract()
.
+pub fn get_refcnt(&self) -> isize
Returns the reference count for the Python object.
+pub fn repr(&self) -> Result<&PyString, PyErr>
Computes the “repr” representation of self.
This is equivalent to the Python expression repr(self)
.
-pub fn str(&self) -> Result<&PyString, PyErr>
Computes the “str” representation of self.
This is equivalent to the Python expression str(self)
.
-pub fn hash(&self) -> Result<isize, PyErr>
Retrieves the hash code of self.
This is equivalent to the Python expression hash(self)
.
-pub fn len(&self) -> Result<usize, PyErr>
Returns the length of the sequence or mapping.
This is equivalent to the Python expression len(self)
.
pub fn dir(&self) -> &PyList
Returns the list of attributes of this object.
This is equivalent to the Python expression dir(self)
.
-pub fn is_instance(&self, ty: &PyAny) -> Result<bool, PyErr>
Checks whether this object is an instance of type ty
.
+pub fn is_instance(&self, ty: &PyAny) -> Result<bool, PyErr>
Checks whether this object is an instance of type ty
.
This is equivalent to the Python expression isinstance(self, ty)
.
-pub fn is_exact_instance(&self, ty: &PyAny) -> bool
Checks whether this object is an instance of exactly type ty
(not a subclass).
+pub fn is_exact_instance(&self, ty: &PyAny) -> bool
Checks whether this object is an instance of exactly type ty
(not a subclass).
This is equivalent to the Python expression type(self) is ty
.
-pub fn is_instance_of<T>(&self) -> boolwhere
+
pub fn is_instance_of<T>(&self) -> boolwhere
T: PyTypeInfo,
Checks whether this object is an instance of type T
.
This is equivalent to the Python expression isinstance(self, T)
,
if the type T
is known at compile time.
-pub fn is_exact_instance_of<T>(&self) -> boolwhere
+
pub fn is_exact_instance_of<T>(&self) -> boolwhere
T: PyTypeInfo,
Checks whether this object is an instance of exactly type T
.
This is equivalent to the Python expression type(self) is T
,
if the type T
is known at compile time.
-pub fn contains<V>(&self, value: V) -> Result<bool, PyErr>where
V: ToPyObject,
Determines if self contains value
.
This is equivalent to the Python expression value in self
.
pub fn py(&self) -> Python<'_>
Returns a GIL marker constrained to the lifetime of this type.
-pub fn as_ptr(&self) -> *mut PyObject
Returns the raw FFI pointer represented by self.
+§Safety
Callers are responsible for ensuring that the pointer does not outlive self.
The reference is borrowed; callers should not decrease the reference count
when they are finished with the pointer.
-pub fn into_ptr(&self) -> *mut PyObject
Returns an owned raw FFI pointer represented by self.
-Safety
+pub fn into_ptr(&self) -> *mut PyObject
Returns an owned raw FFI pointer represented by self.
+§Safety
The reference is owned; when finished the caller should either transfer ownership
of the pointer or decrease the reference count (e.g. with pyo3::ffi::Py_DecRef
).
-
Py<T>
smart pointer.object
is an instance of this type or a subclass of this type.object
is an instance of this type or a subclass of this type.object
is an instance of this type.object
is an instance of this type.Py<T>
smart pointer.object
is an instance of this type or a subclass of this type.object
is an instance of this type or a subclass of this type.object
is an instance of this type.object
is an instance of this type.PyObject
. Read morePyObject
. Read morePyObject
. Read morePyObject
. Read morePyObject
or panic. Read morePyObject
or panic. Read morePyObject
or panic. Read morePyObject
or panic. Read morePyObject
. Read morePyObject
. Read morePyObject
. Read morePyObject
. Read morePyObject
. Read morePyObject
. Read morevalue.downcast::<T>()
instead of T::try_from(value)
value.downcast_exact::<T>()
instead of T::try_from_exact(value)
value.downcast_unchecked::<T>()
instead of T::try_from_unchecked(value)
value.downcast::<T>()
instead of T::try_from(value)
value.downcast_exact::<T>()
instead of T::try_from_exact(value)
value.downcast_unchecked::<T>()
instead of T::try_from_unchecked(value)
self
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub trait PyArray0Methods<'py, T>: PyArrayMethods<'py, T, Ix0> {
+PyArray0Methods in numpy::array - Rust
+ Trait numpy::array::PyArray0Methods
source · pub trait PyArray0Methods<'py, T>: PyArrayMethods<'py, T, Ix0> {
// Provided method
fn item(&self) -> T
- where T: Element + Copy { ... }
+ where T: Element + Copy { ... }
}
Expand description
Implementation of functionality for PyArray0<T>
.
-Provided Methods§
\ No newline at end of file
+
pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
+PyArrayMethods in numpy::array - Rust
+ Trait numpy::array::PyArrayMethods
source · pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
Show 29 methods
// Required methods
fn as_untyped(&self) -> &Bound<'py, PyUntypedArray>;
- fn data(&self) -> *mut T;
- unsafe fn get(&self, index: impl NpyIndex<Dim = D>) -> Option<&T>
+ fn data(&self) -> *mut T;
+ unsafe fn get(&self, index: impl NpyIndex<Dim = D>) -> Option<&T>
where T: Element,
D: Dimension;
- unsafe fn get_mut(&self, index: impl NpyIndex<Dim = D>) -> Option<&mut T>
+ unsafe fn get_mut(&self, index: impl NpyIndex<Dim = D>) -> Option<&mut T>
where T: Element,
D: Dimension;
fn to_dyn(&self) -> &Bound<'py, PyArray<T, IxDyn>>
where T: Element,
D: Dimension;
- fn try_readonly(&self) -> Result<PyReadonlyArray<'py, T, D>, BorrowError>
+ fn try_readonly(&self) -> Result<PyReadonlyArray<'py, T, D>, BorrowError>
where T: Element,
D: Dimension;
- fn try_readwrite(&self) -> Result<PyReadwriteArray<'py, T, D>, BorrowError>
+ fn try_readwrite(&self) -> Result<PyReadwriteArray<'py, T, D>, BorrowError>
where T: Element,
D: Dimension;
unsafe fn as_array(&self) -> ArrayView<'_, T, D>
@@ -33,11 +33,11 @@
fn copy_to<U: Element>(
&self,
other: &Bound<'py, PyArray<U, D>>
- ) -> PyResult<()>
+ ) -> PyResult<()>
where T: Element;
fn cast<U: Element>(
&self,
- is_fortran: bool
+ is_fortran: bool
) -> PyResult<Bound<'py, PyArray<U, D>>>
where T: Element;
fn reshape_with_order<ID: IntoDimension>(
@@ -46,11 +46,11 @@
order: NPY_ORDER
) -> PyResult<Bound<'py, PyArray<T, ID::Dim>>>
where T: Element;
- unsafe fn resize<ID: IntoDimension>(&self, dims: ID) -> PyResult<()>
+ unsafe fn resize<ID: IntoDimension>(&self, dims: ID) -> PyResult<()>
where T: Element;
unsafe fn try_as_matrix<R, C, RStride, CStride>(
&self
- ) -> Option<MatrixView<'_, T, R, C, RStride, CStride>>
+ ) -> Option<MatrixView<'_, T, R, C, RStride, CStride>>
where T: Scalar + Element,
D: Dimension,
R: Dim,
@@ -59,7 +59,7 @@
CStride: Dim;
unsafe fn try_as_matrix_mut<R, C, RStride, CStride>(
&self
- ) -> Option<MatrixViewMut<'_, T, R, C, RStride, CStride>>
+ ) -> Option<MatrixViewMut<'_, T, R, C, RStride, CStride>>
where T: Scalar + Element,
D: Dimension,
R: Dim,
@@ -70,29 +70,29 @@
// Provided methods
fn dims(&self) -> D
where D: Dimension { ... }
- unsafe fn as_slice(&self) -> Result<&[T], NotContiguousError>
+ unsafe fn as_slice(&self) -> Result<&[T], NotContiguousError>
where T: Element,
D: Dimension { ... }
- unsafe fn as_slice_mut(&self) -> Result<&mut [T], NotContiguousError>
+ unsafe fn as_slice_mut(&self) -> Result<&mut [T], NotContiguousError>
where T: Element,
D: Dimension { ... }
- unsafe fn uget<Idx>(&self, index: Idx) -> &T
+ unsafe fn uget<Idx>(&self, index: Idx) -> &T
where T: Element,
D: Dimension,
Idx: NpyIndex<Dim = D> { ... }
- unsafe fn uget_mut<Idx>(&self, index: Idx) -> &mut T
+ unsafe fn uget_mut<Idx>(&self, index: Idx) -> &mut T
where T: Element,
D: Dimension,
Idx: NpyIndex<Dim = D> { ... }
- unsafe fn uget_raw<Idx>(&self, index: Idx) -> *mut T
+ unsafe fn uget_raw<Idx>(&self, index: Idx) -> *mut T
where T: Element,
D: Dimension,
Idx: NpyIndex<Dim = D> { ... }
- fn get_owned<Idx>(&self, index: Idx) -> Option<T>
+ fn get_owned<Idx>(&self, index: Idx) -> Option<T>
where T: Element,
D: Dimension,
Idx: NpyIndex<Dim = D> { ... }
- fn to_vec(&self) -> Result<Vec<T>, NotContiguousError>
+ fn to_vec(&self) -> Result<Vec<T>, NotContiguousError>
where T: Element,
D: Dimension { ... }
fn readonly(&self) -> PyReadonlyArray<'py, T, D>
@@ -110,17 +110,17 @@
) -> PyResult<Bound<'py, PyArray<T, ID::Dim>>>
where T: Element { ... }
}
Expand description
Implementation of functionality for PyArray<T, D>
.
-Required Methods§
sourcefn as_untyped(&self) -> &Bound<'py, PyUntypedArray>
Access an untyped representation of this array.
-Required Methods§
sourcefn as_untyped(&self) -> &Bound<'py, PyUntypedArray>
Access an untyped representation of this array.
+sourceunsafe fn get(&self, index: impl NpyIndex<Dim = D>) -> Option<&T>
Get a reference of the specified element if the given index is valid.
-Safety
+§Safety
Calling this method is undefined behaviour if the underlying array
is aliased mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Consider using safe alternatives like PyReadonlyArray::get
.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -129,15 +129,15 @@ Example
assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
});
-sourceunsafe fn get_mut(&self, index: impl NpyIndex<Dim = D>) -> Option<&mut T>
Same as get
, but returns Option<&mut T>
.
-Safety
+§Safety
Calling this method is undefined behaviour if the underlying array
is aliased immutably or mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Consider using safe alternatives like PyReadwriteArray::get_mut
.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -150,37 +150,37 @@ Example
assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 42);
});
-sourcefn to_dyn(&self) -> &Bound<'py, PyArray<T, IxDyn>>
Turn an array with fixed dimensionality into one with dynamic dimensionality.
-sourcefn try_readonly(&self) -> Result<PyReadonlyArray<'py, T, D>, BorrowError>where
+
sourcefn try_readonly(&self) -> Result<PyReadonlyArray<'py, T, D>, BorrowError>
Get an immutable borrow of the NumPy array
-sourcefn try_readwrite(&self) -> Result<PyReadwriteArray<'py, T, D>, BorrowError>where
+
sourcefn try_readwrite(&self) -> Result<PyReadwriteArray<'py, T, D>, BorrowError>
Get a mutable borrow of the NumPy array
-sourceunsafe fn as_array(&self) -> ArrayView<'_, T, D>
Returns an ArrayView
of the internal array.
See also PyReadonlyArray::as_array
.
-Safety
+§Safety
Calling this method invalidates all exclusive references to the internal data, e.g. &mut [T]
or ArrayViewMut
.
-sourceunsafe fn as_array_mut(&self) -> ArrayViewMut<'_, T, D>where
+
sourceunsafe fn as_array_mut(&self) -> ArrayViewMut<'_, T, D>
Returns an ArrayViewMut
of the internal array.
See also PyReadwriteArray::as_array_mut
.
-Safety
+§Safety
Calling this method invalidates all other references to the internal data, e.g. ArrayView
or ArrayViewMut
.
-sourcefn as_raw_array(&self) -> RawArrayView<T, D>where
+
sourcefn as_raw_array(&self) -> RawArrayView<T, D>
Returns the internal array as RawArrayView
enabling element access via raw pointers
-sourcefn as_raw_array_mut(&self) -> RawArrayViewMut<T, D>where
+
sourcefn as_raw_array_mut(&self) -> RawArrayViewMut<T, D>
Returns the internal array as RawArrayViewMut
enabling element access via raw pointers
-sourcefn copy_to<U: Element>(&self, other: &Bound<'py, PyArray<U, D>>) -> PyResult<()>where
T: Element,
Copies self
into other
, performing a data type conversion if necessary.
See also PyArray_CopyInto
.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -192,13 +192,13 @@ Example
assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
});
-sourcefn cast<U: Element>(
&self,
- is_fortran: bool
+ is_fortran: bool
) -> PyResult<Bound<'py, PyArray<U, D>>>where
T: Element,
Cast the PyArray<T>
to PyArray<U>
, by allocating a new array.
See also PyArray_CastToType
.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -209,7 +209,7 @@ Example
assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
});
-sourcefn reshape_with_order<ID: IntoDimension>(
+
sourcefn reshape_with_order<ID: IntoDimension>(
&self,
dims: ID,
order: NPY_ORDER
@@ -218,29 +218,30 @@ Example
but has different dimensions specified by dims
and a possibly different memory order specified by order
.
See also numpy.reshape
and PyArray_Newshape
.
-Example
-use numpy::{npyffi::NPY_ORDER, PyArray};
+§Example
+use numpy::prelude::*;
+use numpy::{npyffi::NPY_ORDER, PyArray};
use pyo3::Python;
use ndarray::array;
Python::with_gil(|py| {
let array =
- PyArray::from_iter(py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
+ PyArray::from_iter_bound(py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
assert!(array.is_fortran_contiguous());
assert!(array.reshape([5]).is_err());
});
-
sourceunsafe fn resize<ID: IntoDimension>(&self, dims: ID) -> PyResult<()>where
+
sourceunsafe fn resize<ID: IntoDimension>(&self, dims: ID) -> PyResult<()>where
T: Element,
Extends or truncates the dimensions of an array.
This method works only on contiguous arrays.
Missing elements will be initialized as if calling zeros
.
See also ndarray.resize
and PyArray_Resize
.
-Safety
+§Safety
There should be no outstanding references (shared or exclusive) into the array
as this method might re-allocate it and thereby invalidate all pointers into it.
-Example
+§Example
use numpy::prelude::*;
use numpy::PyArray;
use pyo3::Python;
@@ -254,58 +255,58 @@ Example
}
assert_eq!(pyarray.shape(), [100, 100]);
});
-sourceunsafe fn try_as_matrix<R, C, RStride, CStride>(
+
sourceunsafe fn try_as_matrix<R, C, RStride, CStride>(
&self
-) -> Option<MatrixView<'_, T, R, C, RStride, CStride>>where
+) -> Option<MatrixView<'_, T, R, C, RStride, CStride>>Try to convert this array into a nalgebra::MatrixView
using the given shape and strides.
-Safety
+§Safety
Calling this method invalidates all exclusive references to the internal data, e.g. ArrayViewMut
or MatrixSliceMut
.
-sourceunsafe fn try_as_matrix_mut<R, C, RStride, CStride>(
+
sourceunsafe fn try_as_matrix_mut<R, C, RStride, CStride>(
&self
-) -> Option<MatrixViewMut<'_, T, R, C, RStride, CStride>>where
+) -> Option<MatrixViewMut<'_, T, R, C, RStride, CStride>>Try to convert this array into a nalgebra::MatrixViewMut
using the given shape and strides.
-Safety
+§Safety
Calling this method invalidates all other references to the internal data, e.g. ArrayView
, MatrixSlice
, ArrayViewMut
or MatrixSliceMut
.
-Provided Methods§
Provided Methods§
sourceunsafe fn as_slice(&self) -> Result<&[T], NotContiguousError>where
+
sourceunsafe fn as_slice(&self) -> Result<&[T], NotContiguousError>
Returns an immutable view of the internal data as a slice.
-Safety
+§Safety
Calling this method is undefined behaviour if the underlying array
is aliased mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Please consider the safe alternative PyReadonlyArray::as_slice
.
-sourceunsafe fn as_slice_mut(&self) -> Result<&mut [T], NotContiguousError>where
+
sourceunsafe fn as_slice_mut(&self) -> Result<&mut [T], NotContiguousError>
Returns a mutable view of the internal data as a slice.
-Safety
+§Safety
Calling this method is undefined behaviour if the underlying array
is aliased immutably or mutably by other instances of PyArray
or concurrently modified by Python or other native code.
Please consider the safe alternative PyReadwriteArray::as_slice_mut
.
-sourceunsafe fn uget<Idx>(&self, index: Idx) -> &T
Get an immutable reference of the specified element,
without checking the given index.
See NpyIndex
for what types can be used as the index.
-Safety
+§Safety
Passing an invalid index is undefined behavior.
The element must also have been initialized and
all other references to it is must also be shared.
See PyReadonlyArray::get
for a safe alternative.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use pyo3::Python;
@@ -314,27 +315,27 @@ Example
assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
});
-sourceunsafe fn uget_mut<Idx>(&self, index: Idx) -> &mut T
Same as uget
, but returns &mut T
.
-Safety
+§Safety
Passing an invalid index is undefined behavior.
The element must also have been initialized and
other references to it must not exist.
See PyReadwriteArray::get_mut
for a safe alternative.
-sourcefn to_vec(&self) -> Result<Vec<T>, NotContiguousError>where
+
sourcefn to_vec(&self) -> Result<Vec<T>, NotContiguousError>
sourcefn readonly(&self) -> PyReadonlyArray<'py, T, D>where
+
sourcefn readonly(&self) -> PyReadonlyArray<'py, T, D>
Get an immutable borrow of the NumPy array
-Panics
+§Panics
Panics if the allocation backing the array is currently mutably borrowed.
For a non-panicking variant, use try_readonly
.
-sourcefn readwrite(&self) -> PyReadwriteArray<'py, T, D>where
+
sourcefn readwrite(&self) -> PyReadwriteArray<'py, T, D>
Get a mutable borrow of the NumPy array
-Panics
+§Panics
Panics if the allocation backing the array is currently borrowed or
if the array is flagged as not writeable.
For a non-panicking variant, use try_readwrite
.
-sourcefn to_owned_array(&self) -> Array<T, D>where
+
sourcefn to_owned_array(&self) -> Array<T, D>
Get a copy of the array as an ndarray::Array
.
-Example
+§Example
use numpy::{PyArray, PyArrayMethods};
use ndarray::array;
use pyo3::Python;
@@ -389,49 +390,49 @@ Example
array![[0, 1], [2, 3]]
)
});
-sourcefn reshape<ID: IntoDimension>(
+
sourcefn reshape<ID: IntoDimension>(
&self,
dims: ID
) -> PyResult<Bound<'py, PyArray<T, ID::Dim>>>where
T: Element,
Special case of reshape_with_order
which keeps the memory order the same.
-
Types to safely create references into NumPy arrays
It is assumed that unchecked code - which includes unsafe Rust and Python - is validated by its author which together with the dynamic borrow checking performed by this crate ensures that safe Rust code cannot cause undefined behaviour by creating references into NumPy arrays.
With these borrows established, references to individual elements or reference-based views of whole array can be created safely. These are then the starting point for algorithms iteraing over and operating on the elements of the array.
-The first example shows that dynamic borrow checking works to constrain both what safe Rust code can invoke and how it is invoked.
@@ -94,7 +94,7 @@Rust references require aliasing discipline to be maintained, i.e. there must always exist only a single mutable (aka exclusive) reference or multiple immutable (aka shared) references for each object, otherwise the program contains undefined behaviour.
@@ -118,7 +118,7 @@In summary, this crate takes the position that all unchecked code - unsafe Rust, Python, C, Fortran, etc. - must be checked for correctness by its author. Safe Rust code can then rely on this correctness, but should not be able to introduce memory safety issues on its own. Additionally, dynamic borrow checking can catch some mistakes introduced by unchecked code, e.g. Python calling a function with the same array as an input and as an output argument.
-Note that the current implementation of this is an over-approximation: It will consider borrows potentially conflicting if the initial arrays have the same object at the end of their base object chain. Then, multiple conditions which are sufficient but not necessary to show the absence of conflicts are checked.
@@ -130,4 +130,4 @@PyArray::as_array_mut
can be used as an escape hatch.
More involved cases like the example from above may be supported in the future.
-pub struct PyReadonlyArray<'py, T, D>{ /* private fields */ }
Read-only borrow of an array.
@@ -8,14 +8,14 @@Provides an immutable array view of the interior of the NumPy array.
-Provide an immutable slice view of the interior of the NumPy array if it is contiguous.
-Provide an immutable slice view of the interior of the NumPy array if it is contiguous.
+Convert this one-dimensional array into a nalgebra::DMatrixView
using dynamic strides.
Panics if the array has negative strides.
Convert this two-dimensional array into a nalgebra::DMatrixView
using dynamic strides.
Panics if the array has negative strides.
-Immutably borrows the value T
.
Immutably borrows the value T
.
This borrow lasts while the returned [PyRef
] exists.
Multiple immutable borrows can be taken out at the same time.
For frozen classes, the simpler [get
][Self::get] is available.
#[pyclass]
struct Foo {
inner: u8,
@@ -77,13 +77,13 @@ Examples
assert_eq!(*inner, 73);
Ok(())
})?;
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow
.
Mutably borrows the value T
.
This borrow lasts while the returned [PyRefMut
] exists.
#[pyclass]
struct Foo {
inner: u8,
@@ -96,21 +96,21 @@ Examples
assert_eq!(foo.borrow().inner, 35);
Ok(())
})?;
Panics if the value is currently borrowed. For a non-panicking variant, use
try_borrow_mut
.
Attempts to immutably borrow the value T
, returning an error if the value is currently mutably borrowed.
Attempts to immutably borrow the value T
, returning an error if the value is currently mutably borrowed.
The borrow lasts while the returned [PyRef
] exists.
This is the non-panicking variant of borrow
.
For frozen classes, the simpler [get
][Self::get] is available.
Attempts to mutably borrow the value T
, returning an error if the value is currently borrowed.
The borrow lasts while the returned [PyRefMut
] exists.
This is the non-panicking variant of borrow_mut
.
Provide an immutable borrow of the value T
without acquiring the GIL.
This is available if the class is [frozen
][macro@crate::pyclass] and Sync
.
use std::sync::atomic::{AtomicUsize, Ordering};
#[pyclass(frozen)]
@@ -126,40 +126,42 @@ Examples
py_counter.get().value.fetch_add(1, Ordering::Relaxed);
});
Returns the GIL token associated with this object.
-Returns the raw FFI pointer represented by self.
+Callers are responsible for ensuring that the pointer does not outlive self.
The reference is borrowed; callers should not decrease the reference count when they are finished with the pointer.
Helper to cast to Bound<'py, PyAny>
.
Casts this Bound<T>
to a Borrowed<T>
smart pointer.
Removes the connection for this Bound<T>
from the GIL, allowing
+it to cross thread boundaries, without transferring ownership.
Casts this Bound<T>
as the corresponding “GIL Ref” type.
This is a helper to be used for migration from the deprecated “GIL Refs” API.
-Calls U::from(self)
.
self
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct PyReadwriteArray<'py, T, D>{ /* private fields */ }
Read-write borrow of an array.
@@ -8,14 +8,14 @@Provides a mutable array view of the interior of the NumPy array.
-Provide a mutable slice view of the interior of the NumPy array if it is contiguous.
-Provide a mutable slice view of the interior of the NumPy array if it is contiguous.
+See PyReadonlyArray::try_as_matrix
for a discussion of the memory layout requirements.
Convert this one-dimensional array into a nalgebra::DMatrixViewMut
using dynamic strides.
Panics if the array has negative strides.
Convert this two-dimensional array into a nalgebra::DMatrixViewMut
using dynamic strides.
Panics if the array has negative strides.
Extends or truncates the dimensions of an array.
Safe wrapper for PyArray::resize
.
use numpy::{PyArray, PyArrayMethods, PyUntypedArrayMethods};
use pyo3::Python;
@@ -44,13 +44,13 @@ Example
let pyarray = pyarray.resize(100).unwrap();
assert_eq!(pyarray.len(), 100);
});
Provides an immutable array view of the interior of the NumPy array.
+Provide an immutable slice view of the interior of the NumPy array if it is contiguous.
+Provide an immutable reference to an element of the NumPy array if the index is within bounds.
Convert this one-dimensional array into a nalgebra::DMatrixView
using dynamic strides.
Panics if the array has negative strides.
Convert this two-dimensional array into a nalgebra::DMatrixView
using dynamic strides.
Panics if the array has negative strides.
-Immutably borrows the value T
.
Immutably borrows the value T
.
This borrow lasts while the returned [PyRef
] exists.
Multiple immutable borrows can be taken out at the same time.
For frozen classes, the simpler [get
][Self::get] is available.
#[pyclass]
struct Foo {
inner: u8,
@@ -110,13 +110,13 @@ Examples
assert_eq!(*inner, 73);
Ok(())
})?;
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow
.
Mutably borrows the value T
.
This borrow lasts while the returned [PyRefMut
] exists.
#[pyclass]
struct Foo {
inner: u8,
@@ -129,21 +129,21 @@ Examples
assert_eq!(foo.borrow().inner, 35);
Ok(())
})?;
Panics if the value is currently borrowed. For a non-panicking variant, use
try_borrow_mut
.
Attempts to immutably borrow the value T
, returning an error if the value is currently mutably borrowed.
Attempts to immutably borrow the value T
, returning an error if the value is currently mutably borrowed.
The borrow lasts while the returned [PyRef
] exists.
This is the non-panicking variant of borrow
.
For frozen classes, the simpler [get
][Self::get] is available.
Attempts to mutably borrow the value T
, returning an error if the value is currently borrowed.
The borrow lasts while the returned [PyRefMut
] exists.
This is the non-panicking variant of borrow_mut
.
Provide an immutable borrow of the value T
without acquiring the GIL.
This is available if the class is [frozen
][macro@crate::pyclass] and Sync
.
use std::sync::atomic::{AtomicUsize, Ordering};
#[pyclass(frozen)]
@@ -159,37 +159,39 @@ Examples
py_counter.get().value.fetch_add(1, Ordering::Relaxed);
});
Returns the GIL token associated with this object.
-Returns the raw FFI pointer represented by self.
+Callers are responsible for ensuring that the pointer does not outlive self.
The reference is borrowed; callers should not decrease the reference count when they are finished with the pointer.
Helper to cast to Bound<'py, PyAny>
.
Casts this Bound<T>
to a Borrowed<T>
smart pointer.
Removes the connection for this Bound<T>
from the GIL, allowing
+it to cross thread boundaries, without transferring ownership.
Casts this Bound<T>
as the corresponding “GIL Ref” type.
This is a helper to be used for migration from the deprecated “GIL Refs” API.
-Calls U::from(self)
.
self
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub type PyReadonlyArray0<'py, T> = PyReadonlyArray<'py, T, Ix0>;
Read-only borrow of a zero-dimensional array.
struct PyReadonlyArray0<'py, T> { /* private fields */ }
pub type PyReadonlyArray1<'py, T> = PyReadonlyArray<'py, T, Ix1>;
Read-only borrow of a one-dimensional array.
struct PyReadonlyArray1<'py, T> { /* private fields */ }
pub type PyReadonlyArray2<'py, T> = PyReadonlyArray<'py, T, Ix2>;
Read-only borrow of a two-dimensional array.
struct PyReadonlyArray2<'py, T> { /* private fields */ }
pub type PyReadonlyArray3<'py, T> = PyReadonlyArray<'py, T, Ix3>;
Read-only borrow of a three-dimensional array.
struct PyReadonlyArray3<'py, T> { /* private fields */ }
pub type PyReadonlyArray4<'py, T> = PyReadonlyArray<'py, T, Ix4>;
Read-only borrow of a four-dimensional array.
struct PyReadonlyArray4<'py, T> { /* private fields */ }
pub type PyReadonlyArray5<'py, T> = PyReadonlyArray<'py, T, Ix5>;
Read-only borrow of a five-dimensional array.
struct PyReadonlyArray5<'py, T> { /* private fields */ }
pub type PyReadonlyArray6<'py, T> = PyReadonlyArray<'py, T, Ix6>;
Read-only borrow of a six-dimensional array.
struct PyReadonlyArray6<'py, T> { /* private fields */ }
pub type PyReadonlyArrayDyn<'py, T> = PyReadonlyArray<'py, T, IxDyn>;
Read-only borrow of an array whose dimensionality is determined at runtime.
struct PyReadonlyArrayDyn<'py, T> { /* private fields */ }
pub type PyReadwriteArray0<'py, T> = PyReadwriteArray<'py, T, Ix0>;
Read-write borrow of a zero-dimensional array.
struct PyReadwriteArray0<'py, T> { /* private fields */ }
pub type PyReadwriteArray1<'py, T> = PyReadwriteArray<'py, T, Ix1>;
Read-write borrow of a one-dimensional array.
struct PyReadwriteArray1<'py, T> { /* private fields */ }
pub type PyReadwriteArray2<'py, T> = PyReadwriteArray<'py, T, Ix2>;
Read-write borrow of a two-dimensional array.
struct PyReadwriteArray2<'py, T> { /* private fields */ }
pub type PyReadwriteArray3<'py, T> = PyReadwriteArray<'py, T, Ix3>;
Read-write borrow of a three-dimensional array.
struct PyReadwriteArray3<'py, T> { /* private fields */ }
pub type PyReadwriteArray4<'py, T> = PyReadwriteArray<'py, T, Ix4>;
Read-write borrow of a four-dimensional array.
struct PyReadwriteArray4<'py, T> { /* private fields */ }
pub type PyReadwriteArray5<'py, T> = PyReadwriteArray<'py, T, Ix5>;
Read-write borrow of a five-dimensional array.
struct PyReadwriteArray5<'py, T> { /* private fields */ }
pub type PyReadwriteArray6<'py, T> = PyReadwriteArray<'py, T, Ix6>;
Read-write borrow of a six-dimensional array.
struct PyReadwriteArray6<'py, T> { /* private fields */ }
pub type PyReadwriteArrayDyn<'py, T> = PyReadwriteArray<'py, T, IxDyn>;
Read-write borrow of an array whose dimensionality is determined at runtime.
struct PyReadwriteArrayDyn<'py, T> { /* private fields */ }
Defines conversion traits between Rust types and NumPy data types.
-Defines conversion traits between Rust types and NumPy data types.
+pub trait IntoPyArray {
+IntoPyArray in numpy::convert - Rust
+ Trait numpy::convert::IntoPyArray
source · pub trait IntoPyArray: Sized {
type Item: Element;
type Dim: Dimension;
// Required method
- fn into_pyarray<'py>(
+ fn into_pyarray_bound<'py>(
self,
py: Python<'py>
- ) -> &'py PyArray<Self::Item, Self::Dim>;
+ ) -> Bound<'py, PyArray<Self::Item, Self::Dim>>;
+
+ // Provided method
+ fn into_pyarray<'py>(
+ self,
+ py: Python<'py>
+ ) -> &'py PyArray<Self::Item, Self::Dim> { ... }
}
Expand description
Conversion trait from owning Rust types into PyArray
.
This trait takes ownership of self
, which means it holds a pointer into the Rust heap.
In addition, some destructive methods like resize
cannot be used with NumPy arrays constructed using this trait.
-Example
-use numpy::{PyArray, IntoPyArray};
+§Example
+use numpy::{PyArray, IntoPyArray, PyArrayMethods};
use pyo3::Python;
Python::with_gil(|py| {
- let py_array = vec![1, 2, 3].into_pyarray(py);
+ let py_array = vec![1, 2, 3].into_pyarray_bound(py);
assert_eq!(py_array.readonly().as_slice().unwrap(), &[1, 2, 3]);
@@ -27,19 +33,23 @@ Example
});
Required Associated Types§
Required Methods§
sourcefn into_pyarray<'py>(
+
Required Methods§
sourcefn into_pyarray_bound<'py>(
+ self,
+ py: Python<'py>
+) -> Bound<'py, PyArray<Self::Item, Self::Dim>>
Consumes self
and moves its data into a NumPy array.
+Provided Methods§
sourcefn into_pyarray<'py>(
self,
py: Python<'py>
-) -> &'py PyArray<Self::Item, Self::Dim>
Consumes self
and moves its data into a NumPy array.
-Implementations on Foreign Types§
source§impl<A, D> IntoPyArray for ArrayBase<OwnedRepr<A>, D>where
+) -> &'py PyArray<Self::Item, Self::Dim>👎Deprecated since 0.21.0: will be replaced by IntoPyArray::into_pyarray_bound
in the futureDeprecated form of IntoPyArray::into_pyarray_bound
+Object Safety§
This trait is not object safe.Implementations on Foreign Types§
source§impl<T: Element> IntoPyArray for Vec<T>
source§impl<T: Element> IntoPyArray for Vec<T>
Implementors§
\ No newline at end of file
+) -> Bound<'py, PyArray<Self::Item, Self::Dim>>
pub trait NpyIndex: IntoDimension + Sealed { }
Trait implemented by types that can be used to index an array.
+pub trait NpyIndex: IntoDimension + Sealed { }
Trait implemented by types that can be used to index an array.
This is equivalent to ndarray::NdIndex
but accounts for
NumPy strides being in units of bytes instead of elements.
All types which implement IntoDimension
implement this trait as well.
@@ -9,4 +9,4 @@
pub trait ToNpyDims: Dimension + Sealed { }
Utility trait to specify the dimensions of an array.
-pub trait ToPyArray {
+ToPyArray in numpy::convert - Rust
+ pub trait ToPyArray {
type Item: Element;
type Dim: Dimension;
// Required method
- fn to_pyarray<'py>(
+ fn to_pyarray_bound<'py>(
&self,
py: Python<'py>
- ) -> &'py PyArray<Self::Item, Self::Dim>;
+ ) -> Bound<'py, PyArray<Self::Item, Self::Dim>>;
+
+ // Provided method
+ fn to_pyarray<'py>(
+ &self,
+ py: Python<'py>
+ ) -> &'py PyArray<Self::Item, Self::Dim> { ... }
}
Expand description
Conversion trait from borrowing Rust types to PyArray
.
This trait takes &self
by reference, which means it allocates in Python heap and then copies the elements there.
-Examples
-use numpy::{PyArray, ToPyArray};
+§Examples
+use numpy::{PyArray, ToPyArray, PyArrayMethods};
use pyo3::Python;
Python::with_gil(|py| {
- let py_array = vec![1, 2, 3].to_pyarray(py);
+ let py_array = vec![1, 2, 3].to_pyarray_bound(py);
assert_eq!(py_array.readonly().as_slice().unwrap(), &[1, 2, 3]);
});
Due to copying the elments, this method converts non-contiguous arrays to C-order contiguous arrays.
-use numpy::{PyArray, ToPyArray};
+use numpy::prelude::*;
+use numpy::{PyArray, ToPyArray};
use ndarray::{arr3, s};
use pyo3::Python;
Python::with_gil(|py| {
let array = arr3(&[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
- let py_array = array.slice(s![.., 0..1, ..]).to_pyarray(py);
+ let py_array = array.slice(s![.., 0..1, ..]).to_pyarray_bound(py);
assert_eq!(py_array.readonly().as_array(), arr3(&[[[1, 2, 3]], [[7, 8, 9]]]));
assert!(py_array.is_c_contiguous());
});
-
Required Associated Types§
Required Methods§
sourcefn to_pyarray<'py>(
+
Required Associated Types§
Required Methods§
sourcefn to_pyarray_bound<'py>(
+ &self,
+ py: Python<'py>
+) -> Bound<'py, PyArray<Self::Item, Self::Dim>>
Copies the content pointed to by &self
into a newly allocated NumPy array.
+Provided Methods§
sourcefn to_pyarray<'py>(
&self,
py: Python<'py>
-) -> &'py PyArray<Self::Item, Self::Dim>
Copies the content pointed to by &self
into a newly allocated NumPy array.
-Implementations on Foreign Types§
source§impl<N, R, C, S> ToPyArray for Matrix<N, R, C, S>where
+) -> &'py PyArray<Self::Item, Self::Dim>👎Deprecated since 0.21.0: will be replaced by ToPyArray::to_pyarray_bound
in the futureDeprecated form of ToPyArray::to_pyarray_bound
+Implementations on Foreign Types§
Implementors§
\ No newline at end of file
+) -> Bound<'py, PyArray<Self::Item, Self::Dim>>Implementors§
\ No newline at end of file
diff --git a/numpy/datetime/index.html b/numpy/datetime/index.html
index eb37d856e..d5a433f40 100644
--- a/numpy/datetime/index.html
+++ b/numpy/datetime/index.html
@@ -1,11 +1,11 @@
-numpy::datetime - Rust
+numpy::datetime - Rust
Expand description
Support datetimes and timedeltas
This module provides wrappers for NumPy’s datetime64
and timedelta64
types
which are used for time keeping with with an emphasis on scientific applications.
This means that while these types differentiate absolute and relative quantities, they ignore calendars (a month is always 30.44 days) and time zones.
On the other hand, their flexible units enable them to support either a large range (up to 264 years) or high precision (down to 10-18 seconds).
The corresponding section of the NumPy documentation contains more information.
-Example
+§Example
use numpy::{datetime::{units, Datetime, Timedelta}, PyArray1};
use pyo3::Python;
@@ -40,4 +40,4 @@ Example
Timedelta::<units::Days>::from(1_803)
);
});
-Modules
- Predefined implementors of the
Unit
trait
Structs
- Corresponds to the
datetime64
scalar type - Corresponds to the [
timedelta64
][scalars-datetime64] scalar type
Traits
- Represents the datetime units supported by NumPy
\ No newline at end of file
+
Unit
traitdatetime64
scalar typetimedelta64
][scalars-datetime64] scalar typepub struct Datetime<U: Unit>(/* private fields */);
Corresponds to the datetime64
scalar type
get_dtype_bound
in the future.self
and other
) and is used by the <=
-operator. Read moreget_dtype_bound
in the future.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Timedelta<U: Unit>(/* private fields */);
Corresponds to the [timedelta64
][scalars-datetime64] scalar type
get_dtype_bound
in the future.self
and other
) and is used by the <=
-operator. Read moreget_dtype_bound
in the future.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub trait Unit: Send + Sync + Clone + Copy + PartialEq + Eq + Hash + PartialOrd + Ord {
+Unit in numpy::datetime - Rust
+ pub trait Unit: Send + Sync + Clone + Copy + PartialEq + Eq + Hash + PartialOrd + Ord {
const UNIT: NPY_DATETIMEUNIT;
- const ABBREV: &'static str;
+ const ABBREV: &'static str;
}
Expand description
Represents the datetime units supported by NumPy
Required Associated Constants§
sourceconst UNIT: NPY_DATETIMEUNIT
The matching NumPy datetime unit code
-Object Safety§
This trait is not object safe.Implementors§
source§impl Unit for Attoseconds
source§impl Unit for Femtoseconds
source§impl Unit for Microseconds
source§impl Unit for Milliseconds
source§impl Unit for Nanoseconds
source§impl Unit for Picoseconds
\ No newline at end of file
+
The abbrevation used for debug formatting
+Predefined implementors of the Unit
trait
pub struct Attoseconds;
Attoseconds, i.e. 10^-18 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Days;
Days, i.e. 24 hours
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Femtoseconds;
Femtoseconds, i.e. 10^-15 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Hours;
Hours, i.e. 60 minutes
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Microseconds;
Microseconds, i.e. 10^-6 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Milliseconds;
Milliseconds, i.e. 10^-3 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Minutes;
Minutes, i.e. 60 seconds
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Months;
Months, i.e. 30 days
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Nanoseconds;
Nanoseconds, i.e. 10^-9 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Picoseconds;
Picoseconds, i.e. 10^-12 seconds
-source
. Read moreself
and other
values to be equal, and is used
-by ==
.self
and other
) and is used by the <=
-operator. Read moresource
. Read moreself
and other
values to be equal, and is used
+by ==
.self
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Seconds;
Seconds
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Weeks;
Weeks, i.e. 7 days
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub struct Years;
Years, i.e. 12 months
-self
and other
) and is used by the <=
-operator. Read moreself
and other
) and is used by the <=
+operator. Read moreself
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.#[non_exhaustive]pub enum BorrowError {
AlreadyBorrowed,
NotWriteable,
}
Inidcates why borrowing an array failed.
self
from the equivalent element of its
-superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.self
from the equivalent element of its
+superset. Read moreself
is actually part of its subset T
(and can be converted to it).self.to_subset
but without any property checks. Always succeeds.self
to the equivalent element of its superset.pub fn Ix1(i0: usize) -> Dim<[usize; 1]>
Create a one-dimensional index
+pub fn Ix2(i0: usize, i1: usize) -> Dim<[usize; 2]>
Create a two-dimensional index
+pub fn Ix3(i0: usize, i1: usize, i2: usize) -> Dim<[usize; 3]>
Create a three-dimensional index
+pub fn Ix4(i0: usize, i1: usize, i2: usize, i3: usize) -> Dim<[usize; 4]>
Create a four-dimensional index
+pub fn Ix5(
- i0: usize,
- i1: usize,
- i2: usize,
- i3: usize,
- i4: usize
-) -> Dim<[usize; 5]>
Create a five-dimensional index
+ i0: usize, + i1: usize, + i2: usize, + i3: usize, + i4: usize +) -> Dim<[usize; 5]>Create a five-dimensional index
pub fn Ix6(
- i0: usize,
- i1: usize,
- i2: usize,
- i3: usize,
- i4: usize,
- i5: usize
-) -> Dim<[usize; 6]>
Create a six-dimensional index
+ i0: usize, + i1: usize, + i2: usize, + i3: usize, + i4: usize, + i5: usize +) -> Dim<[usize; 6]>Create a six-dimensional index
pub fn IxDyn(ix: &[usize]) -> Dim<IxDynImpl>
Create a dynamic-dimensional index
+pub fn dot<'py, T, DIN1, DIN2, OUT>(
array1: &'py PyArray<T, DIN1>,
array2: &'py PyArray<T, DIN2>
@@ -8,7 +8,7 @@
DIN2: Dimension,
OUT: ArrayOrScalar<'py, T>,
Return the dot product of two arrays.
NumPy’s documentation has the details.
-Note that this function can either return an array…
use pyo3::Python;
diff --git a/numpy/fn.dtype.html b/numpy/fn.dtype.html
index bee07dae4..97a1259ad 100644
--- a/numpy/fn.dtype.html
+++ b/numpy/fn.dtype.html
@@ -1,3 +1,3 @@
-dtype in numpy - Rust
+dtype in numpy - Rust
pub fn dtype<'py, T: Element>(py: Python<'py>) -> &'py PyArrayDescr
👎Deprecated since 0.21.0: This will be replaced by dtype_bound
in the future.Expand description
Returns the type descriptor (“dtype”) for a registered type.
\ No newline at end of file
diff --git a/numpy/fn.dtype_bound.html b/numpy/fn.dtype_bound.html
index 3168e7e3f..c45ac9cee 100644
--- a/numpy/fn.dtype_bound.html
+++ b/numpy/fn.dtype_bound.html
@@ -1,3 +1,3 @@
-dtype_bound in numpy - Rust
+dtype_bound in numpy - Rust
Function numpy::dtype_bound
source · pub fn dtype_bound<'py, T: Element>(py: Python<'py>) -> Bound<'py, PyArrayDescr>
Expand description
Returns the type descriptor (“dtype”) for a registered type.
\ No newline at end of file
diff --git a/numpy/fn.einsum.html b/numpy/fn.einsum.html
index d0207dbbf..020e786eb 100644
--- a/numpy/fn.einsum.html
+++ b/numpy/fn.einsum.html
@@ -1,6 +1,6 @@
-einsum in numpy - Rust
+einsum in numpy - Rust
pub fn einsum<'py, T, OUT>(
- subscripts: &str,
+ subscripts: &str,
arrays: &[&'py PyArray<T, IxDyn>]
) -> PyResult<OUT>where
T: Element,
diff --git a/numpy/fn.inner.html b/numpy/fn.inner.html
index ebe0aa55f..c39a6f331 100644
--- a/numpy/fn.inner.html
+++ b/numpy/fn.inner.html
@@ -1,4 +1,4 @@
-inner in numpy - Rust
+inner in numpy - Rust
pub fn inner<'py, T, DIN1, DIN2, OUT>(
array1: &'py PyArray<T, DIN1>,
array2: &'py PyArray<T, DIN2>
@@ -8,7 +8,7 @@
DIN2: Dimension,
OUT: ArrayOrScalar<'py, T>,
Expand description
Return the inner product of two arrays.
NumPy’s documentation has the details.
-Examples
+§Examples
Note that this function can either return a scalar…
use pyo3::Python;
diff --git a/numpy/index.html b/numpy/index.html
index 3e9ea1796..2c432d683 100644
--- a/numpy/index.html
+++ b/numpy/index.html
@@ -1,6 +1,6 @@
-numpy - Rust