1#![cfg_attr(
16 feature = "nalgebra",
17 doc = "Integration with [`nalgebra`] is provided via an implementation of [`ToPyArray`] for [`nalgebra::Matrix`] to convert nalgebra matrices into NumPy arrays
18as well as the [`PyReadonlyArray::try_as_matrix`] and [`PyReadwriteArray::try_as_matrix_mut`] methods to treat NumPy array as nalgebra matrix slices.
19"
20)]
21#![cfg_attr(feature = "nalgebra", doc = "```")]
39#![cfg_attr(not(feature = "nalgebra"), doc = "```rust,ignore")]
40#![doc = "```"]
69#![deny(missing_docs)]
73
74pub mod array;
75mod array_like;
76pub mod array_protocol;
77pub mod borrow;
78pub mod convert;
79pub mod datetime;
80pub mod dlpack;
81mod dtype;
82mod error;
83pub mod masked;
84pub mod npyffi;
85mod slice_container;
86mod strings;
87mod structured;
88mod sum_products;
89pub mod untyped;
90mod untyped_array;
91
92pub use ndarray;
93pub use pyo3;
94
95#[cfg(feature = "nalgebra")]
96pub use nalgebra;
97
98pub use crate::array::{
99 get_array_module, PyArray, PyArray0, PyArray0Methods, PyArray1, PyArray2, PyArray3, PyArray4,
100 PyArray5, PyArray6, PyArrayDyn, PyArrayMethods,
101};
102pub use crate::array_like::{
103 AllowTypeChange, PyArrayLike, PyArrayLike0, PyArrayLike1, PyArrayLike2, PyArrayLike3,
104 PyArrayLike4, PyArrayLike5, PyArrayLike6, PyArrayLikeDyn, TypeMustMatch,
105};
106pub use crate::array_protocol::{
107 parse_typestr, register_array_protocol_module, ArrayInterfaceDict, ArrayProtocol,
108 ArrayProtocolError, NdArrayWrapper,
109};
110pub use crate::borrow::{
111 PyReadonlyArray, PyReadonlyArray0, PyReadonlyArray1, PyReadonlyArray2, PyReadonlyArray3,
112 PyReadonlyArray4, PyReadonlyArray5, PyReadonlyArray6, PyReadonlyArrayDyn, PyReadwriteArray,
113 PyReadwriteArray0, PyReadwriteArray1, PyReadwriteArray2, PyReadwriteArray3, PyReadwriteArray4,
114 PyReadwriteArray5, PyReadwriteArray6, PyReadwriteArrayDyn,
115};
116pub use crate::convert::{IntoPyArray, NpyIndex, ToNpyDims, ToPyArray};
117pub use crate::dlpack::{
118 dlpack_from_slice, dlpack_to_vec_f64, register_dlpack_module, validate_dlpack_tensor,
119 DLDataType, DLDataTypeCode, DLDevice, DLDeviceType, DLManagedTensor, DLPackCapsule, DLTensor,
120 DLTensorInfo, DlpackError,
121};
122pub use crate::dtype::{dtype, Complex32, Complex64, Element, PyArrayDescr, PyArrayDescrMethods};
123pub use crate::error::{BorrowError, FromVecError, NotContiguousError};
124pub use crate::masked::{masked_array, masked_less, register_masked_module, MaskedArray};
125pub use crate::npyffi::{PY_ARRAY_API, PY_UFUNC_API};
126pub use crate::strings::{PyFixedString, PyFixedUnicode};
127pub use crate::structured::{
128 register_structured_module, DtypeField, StructuredArray, StructuredDtype,
129};
130pub use crate::sum_products::{dot, einsum, inner};
131pub use crate::untyped::{register_untyped_module, UntypedArray};
132pub use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
133
134pub use ndarray::{array, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn};
135
136pub mod prelude {
146 pub use crate::array::{PyArray0Methods, PyArrayMethods};
147 pub use crate::convert::{IntoPyArray, ToPyArray};
148 pub use crate::dtype::PyArrayDescrMethods;
149 pub use crate::untyped_array::PyUntypedArrayMethods;
150}
151
152#[cfg(doctest)]
153mod doctest {
154 macro_rules! doc_comment {
155 ($doc_string:expr, $mod_name:ident) => {
156 #[doc = $doc_string]
157 mod $mod_name {}
158 };
159 }
160 doc_comment!(include_str!("../README.md"), readme);
161}
162
163#[cold]
164#[inline(always)]
165fn cold() {}
166
167#[macro_export]
187macro_rules! pyarray {
188 ($py: ident, $([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{
189 $crate::IntoPyArray::into_pyarray($crate::array![$([$([$($x,)*],)*],)*], $py)
190 }};
191 ($py: ident, $([$($x:expr),* $(,)*]),+ $(,)*) => {{
192 $crate::IntoPyArray::into_pyarray($crate::array![$([$($x,)*],)*], $py)
193 }};
194 ($py: ident, $($x:expr),* $(,)*) => {{
195 $crate::IntoPyArray::into_pyarray($crate::array![$($x,)*], $py)
196 }};
197}