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 array_subclass;
78pub mod borrow;
79pub mod convert;
80pub mod datetime;
81pub mod dlpack;
82pub mod dlpack_cuda;
88mod dtype;
89mod error;
90pub mod extended_int;
91pub mod masked;
92pub mod npyffi;
93pub mod simd_copy;
99mod slice_container;
100mod strings;
101mod structured;
102mod sum_products;
103pub mod untyped;
104mod untyped_array;
105
106pub use ndarray;
107pub use pyo3;
108
109#[cfg(feature = "nalgebra")]
110pub use nalgebra;
111
112pub use crate::array::{
113 get_array_module, PyArray, PyArray0, PyArray0Methods, PyArray1, PyArray2, PyArray3, PyArray4,
114 PyArray5, PyArray6, PyArrayDyn, PyArrayMethods,
115};
116pub use crate::array_like::{
117 AllowTypeChange, PyArrayLike, PyArrayLike0, PyArrayLike1, PyArrayLike2, PyArrayLike3,
118 PyArrayLike4, PyArrayLike5, PyArrayLike6, PyArrayLikeDyn, TypeMustMatch,
119};
120pub use crate::array_protocol::{
121 parse_typestr, register_array_protocol_module, ArrayInterfaceDict, ArrayProtocol,
122 ArrayProtocolError, NdArrayWrapper,
123};
124pub use crate::array_subclass::{
125 from_array_like_f32, from_array_like_f64, register_array_subclass_module, SubclassArrayWrapper,
126};
127pub use crate::borrow::{
128 PyReadonlyArray, PyReadonlyArray0, PyReadonlyArray1, PyReadonlyArray2, PyReadonlyArray3,
129 PyReadonlyArray4, PyReadonlyArray5, PyReadonlyArray6, PyReadonlyArrayDyn, PyReadwriteArray,
130 PyReadwriteArray0, PyReadwriteArray1, PyReadwriteArray2, PyReadwriteArray3, PyReadwriteArray4,
131 PyReadwriteArray5, PyReadwriteArray6, PyReadwriteArrayDyn,
132};
133pub use crate::convert::{IntoPyArray, NpyIndex, ToNpyDims, ToPyArray};
134pub use crate::dlpack::{
135 array_from_dlpack_f32, array_from_dlpack_f64, check_tensor_contiguous, dlarray_from_torch_f32,
136 dlarray_from_torch_f64, dlpack_from_slice, dlpack_to_vec_f64, jax_device_type,
137 register_dlpack_module, validate_dlpack_tensor, validate_jax_dlpack_tensor,
138 validate_torch_dlpack_tensor, DLDataType, DLDataTypeCode, DLDevice, DLDeviceType,
139 DLManagedTensor, DLPackCapsule, DLTensor, DLTensorInfo, DlpackError, JaxDeviceType,
140 DL_DEVICE_TYPE_TPU,
141};
142pub use crate::dlpack_cuda::{
143 cuda_tensor_info, cuda_tensor_info_from_dltensor, get_cuda_tensor_info,
144 register_dlpack_cuda_module, CudaTensorInfo, DLPackDispatchResult,
145};
146pub use crate::dtype::{dtype, Complex32, Complex64, Element, PyArrayDescr, PyArrayDescrMethods};
147pub use crate::error::{BorrowError, FromVecError, NotContiguousError};
148pub use crate::extended_int::{
149 from_i128, from_u128, register_extended_int_module, to_i128, to_u128, I128Array, U128Array,
150};
151pub use crate::masked::{masked_array, masked_less, register_masked_module, MaskedArray};
152pub use crate::npyffi::{PY_ARRAY_API, PY_UFUNC_API};
153pub use crate::strings::{PyFixedString, PyFixedUnicode};
154pub use crate::structured::{
155 register_structured_module, DtypeField, StructuredArray, StructuredDtype,
156};
157pub use crate::sum_products::{dot, einsum, inner};
158pub use crate::untyped::{register_untyped_module, UntypedArray};
159pub use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
160
161pub use ndarray::{array, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn};
162
163pub mod prelude {
173 pub use crate::array::{PyArray0Methods, PyArrayMethods};
174 pub use crate::convert::{IntoPyArray, ToPyArray};
175 pub use crate::dtype::PyArrayDescrMethods;
176 pub use crate::untyped_array::PyUntypedArrayMethods;
177}
178
179#[cfg(doctest)]
180mod doctest {
181 macro_rules! doc_comment {
182 ($doc_string:expr, $mod_name:ident) => {
183 #[doc = $doc_string]
184 mod $mod_name {}
185 };
186 }
187 doc_comment!(include_str!("../README.md"), readme);
188}
189
190#[cold]
191#[inline(always)]
192fn cold() {}
193
194#[macro_export]
214macro_rules! pyarray {
215 ($py: ident, $([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{
216 $crate::IntoPyArray::into_pyarray($crate::array![$([$([$($x,)*],)*],)*], $py)
217 }};
218 ($py: ident, $([$($x:expr),* $(,)*]),+ $(,)*) => {{
219 $crate::IntoPyArray::into_pyarray($crate::array![$([$($x,)*],)*], $py)
220 }};
221 ($py: ident, $($x:expr),* $(,)*) => {{
222 $crate::IntoPyArray::into_pyarray($crate::array![$($x,)*], $py)
223 }};
224}