Skip to content

Commit 147775d

Browse files
committed
Rename c* aliases to Complex*, add docstrings
1 parent 8e7c583 commit 147775d

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

examples/simple-extension/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
2-
use numpy::{c64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
2+
use numpy::{Complex64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
33
use pyo3::prelude::{pymodule, PyModule, PyResult, Python};
44

55
#[pymodule]
@@ -15,7 +15,7 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
1515
}
1616

1717
// complex example
18-
fn conj(x: ArrayViewD<'_, c64>) -> ArrayD<c64> {
18+
fn conj(x: ArrayViewD<'_, Complex64>) -> ArrayD<Complex64> {
1919
x.map(|c| c.conj())
2020
}
2121

@@ -44,7 +44,10 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
4444
// wrapper of `conj`
4545
#[pyfn(m)]
4646
#[pyo3(name = "conj")]
47-
fn conj_py<'py>(py: Python<'py>, x: PyReadonlyArrayDyn<'_, c64>) -> &'py PyArrayDyn<c64> {
47+
fn conj_py<'py>(
48+
py: Python<'py>,
49+
x: PyReadonlyArrayDyn<'_, Complex64>,
50+
) -> &'py PyArrayDyn<Complex64> {
4851
conj(x.as_array()).into_pyarray(py)
4952
}
5053

src/dtype.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use pyo3::{ffi, prelude::*, pyobject_native_type_core, types::PyType, AsPyPointe
77

88
use crate::npyffi::{NpyTypes, PyArray_Descr, NPY_TYPES, PY_ARRAY_API};
99

10-
pub use num_complex::Complex32 as c32;
11-
pub use num_complex::Complex64 as c64;
10+
pub use num_complex::{Complex32, Complex64};
1211

1312
/// Binding of [`numpy.dtype`](https://numpy.org/doc/stable/reference/generated/numpy.dtype.html).
1413
///
@@ -287,7 +286,8 @@ pub unsafe trait Element: Clone + Send {
287286
}
288287

289288
macro_rules! impl_num_element {
290-
($ty:ty, $data_type:expr) => {
289+
($ty:ty, $data_type:expr $(,#[$meta:meta])*) => {
290+
$(#[$meta])*
291291
unsafe impl Element for $ty {
292292
const IS_COPY: bool = true;
293293

@@ -309,8 +309,10 @@ impl_num_element!(u32, DataType::Uint32);
309309
impl_num_element!(u64, DataType::Uint64);
310310
impl_num_element!(f32, DataType::Float32);
311311
impl_num_element!(f64, DataType::Float64);
312-
impl_num_element!(c32, DataType::Complex32);
313-
impl_num_element!(c64, DataType::Complex64);
312+
impl_num_element!(Complex32, DataType::Complex32,
313+
#[doc = "Complex type with `f32` components which maps to `np.csingle` (`np.complex64`)."]);
314+
impl_num_element!(Complex64, DataType::Complex64,
315+
#[doc = "Complex type with `f64` components which maps to `np.cdouble` (`np.complex128`)."]);
314316

315317
cfg_if! {
316318
if #[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] {
@@ -331,7 +333,7 @@ unsafe impl Element for PyObject {
331333
mod tests {
332334
use std::mem::size_of;
333335

334-
use super::{c32, c64, Element, PyArrayDescr};
336+
use super::{Complex32, Complex64, Element, PyArrayDescr};
335337

336338
#[test]
337339
fn test_dtype_names() {
@@ -350,8 +352,8 @@ mod tests {
350352
assert_eq!(type_name::<u64>(py), "uint64");
351353
assert_eq!(type_name::<f32>(py), "float32");
352354
assert_eq!(type_name::<f64>(py), "float64");
353-
assert_eq!(type_name::<c32>(py), "complex64");
354-
assert_eq!(type_name::<c64>(py), "complex128");
355+
assert_eq!(type_name::<Complex32>(py), "complex64");
356+
assert_eq!(type_name::<Complex64>(py), "complex128");
355357
match size_of::<usize>() {
356358
32 => {
357359
assert_eq!(type_name::<usize>(py), "uint32");

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use crate::array::{
4646
PyArray6, PyArrayDyn,
4747
};
4848
pub use crate::convert::{IntoPyArray, NpyIndex, ToNpyDims, ToPyArray};
49-
pub use crate::dtype::{c32, c64, DataType, Element, PyArrayDescr};
49+
pub use crate::dtype::{Complex32, Complex64, DataType, Element, PyArrayDescr};
5050
pub use crate::error::{DimensionalityError, FromVecError, NotContiguousError, TypeError};
5151
pub use crate::npyffi::{PY_ARRAY_API, PY_UFUNC_API};
5252
pub use crate::npyiter::{

0 commit comments

Comments
 (0)