Skip to content

Commit 2dc0848

Browse files
JRRudy1davidhewitt
authored andcommitted
Formatting and cleanup.
1 parent 6d25071 commit 2dc0848

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ impl<'py, T, D> PyArrayMethods<'py, T, D> for Bound<'py, PyArray<T, D>> {
22712271
as_view(self, |shape, ptr| unsafe {
22722272
RawArrayViewMut::from_shape_ptr(shape, ptr)
22732273
})
2274-
}
2274+
}
22752275

22762276
fn to_owned_array(&self) -> Array<T, D>
22772277
where

src/dtype.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::mem::size_of;
22
use std::os::raw::{c_int, c_long, c_longlong, c_short, c_uint, c_ulong, c_ulonglong, c_ushort};
33
use std::ptr;
4-
use ndarray::{Array, ArrayView, Dimension};
54

65
#[cfg(feature = "half")]
76
use half::{bf16, f16};
@@ -645,55 +644,56 @@ impl<'py> PyArrayDescrMethods<'py> for Bound<'py, PyArrayDescr> {
645644

646645
impl Sealed for Bound<'_, PyArrayDescr> {}
647646

648-
649647
/// Weaker form of `Clone` for types that can be cloned while the GIL is held.
650-
///
651-
/// Any type that implements `Clone` can trivially implement `PyClone` by forwarding
652-
/// to the `Clone::clone` method. However, some types (notably `PyObject`) can only
648+
///
649+
/// Any type that implements `Clone` can trivially implement `PyClone` by forwarding
650+
/// to the `Clone::clone` method. However, some types (notably `PyObject`) can only
653651
/// be safely cloned while the GIL is held, and therefore cannot implement `Clone`.
654652
/// This trait provides a mechanism for performing a clone while the GIL is held, as
655653
/// represented by the [`Python`] token provided as an argument to the [`py_clone`]
656-
/// method. All API's in the `numpy` crate require the GIL to be held, so this weaker
654+
/// method. All API's in the `numpy` crate require the GIL to be held, so this weaker
657655
/// alternative to `Clone` is a sufficient prerequisite for implementing the
658656
/// [`Element`] trait.
659-
///
657+
///
660658
/// # Implementing `PyClone`
661659
/// Implementing this trait is trivial for most types, and simply requires defining
662-
/// the `py_clone` method. The `vec_from_slice` and `array_from_view` methods have
663-
/// default implementations that simply map the `py_clone` method to each item in
660+
/// the `py_clone` method. The `vec_from_slice` and `array_from_view` methods have
661+
/// default implementations that simply map the `py_clone` method to each item in
664662
/// the collection, but types may want to override these implementations if there
665-
/// is a more efficient way to perform the conversion. In particular, `Clone` types
666-
/// may instead defer to the `ToOwned::to_owned` and `ArrayBase::to_owned` methods
663+
/// is a more efficient way to perform the conversion. In particular, `Clone` types
664+
/// may instead defer to the `ToOwned::to_owned` and `ArrayBase::to_owned` methods
667665
/// for increased performance.
668-
///
666+
///
669667
/// [`py_clone`]: Self::py_clone
670668
pub trait PyClone: Sized {
671669
/// Create a clone of the value while the GIL is guaranteed to be held.
672670
fn py_clone(&self, py: Python<'_>) -> Self;
673-
671+
674672
/// Create an owned copy of the slice while the GIL is guaranteed to be held.
675-
///
676-
/// Some types may provide implementations of this method that are more efficient
673+
///
674+
/// Some types may provide implementations of this method that are more efficient
677675
/// than simply mapping the `py_clone` method to each element in the slice.
678676
#[inline]
679677
fn vec_from_slice(py: Python<'_>, slc: &[Self]) -> Vec<Self> {
680678
slc.iter().map(|elem| elem.py_clone(py)).collect()
681679
}
682-
680+
683681
/// Create an owned copy of the array while the GIL is guaranteed to be held.
684-
///
685-
/// Some types may provide implementations of this method that are more efficient
682+
///
683+
/// Some types may provide implementations of this method that are more efficient
686684
/// than simply mapping the `py_clone` method to each element in the view.
687685
#[inline]
688-
fn array_from_view<D>(py: Python<'_>, view: ArrayView<'_, Self, D>) -> Array<Self, D>
686+
fn array_from_view<D>(
687+
py: Python<'_>,
688+
view: ::ndarray::ArrayView<'_, Self, D>,
689+
) -> ::ndarray::Array<Self, D>
689690
where
690-
D: Dimension
691+
D: ::ndarray::Dimension,
691692
{
692693
view.map(|elem| elem.py_clone(py))
693694
}
694695
}
695696

696-
697697
/// Represents that a type can be an element of `PyArray`.
698698
///
699699
/// Currently, only integer/float/complex/object types are supported. The [NumPy documentation][enumerated-types]
@@ -804,17 +804,17 @@ macro_rules! impl_py_clone {
804804
fn py_clone(&self, _py: ::pyo3::Python<'_>) -> Self {
805805
self.clone()
806806
}
807-
807+
808808
#[inline]
809809
fn vec_from_slice(_py: ::pyo3::Python<'_>, slc: &[Self]) -> Vec<Self> {
810810
slc.to_owned()
811811
}
812-
812+
813813
#[inline]
814814
fn array_from_view<D>(
815-
_py: ::pyo3::Python<'_>,
815+
_py: ::pyo3::Python<'_>,
816816
view: ::ndarray::ArrayView<'_, Self, D>
817-
) -> ::ndarray::Array<Self, D>
817+
) -> ::ndarray::Array<Self, D>
818818
where
819819
D: ::ndarray::Dimension
820820
{
@@ -930,7 +930,7 @@ mod tests {
930930

931931
#[test]
932932
fn test_dtype_names() {
933-
fn type_name<T: Element>(py: Python) -> Bound<PyString> {
933+
fn type_name<T: Element>(py: Python<'_>) -> Bound<'_, PyString> {
934934
dtype_bound::<T>(py).typeobj().qualname().unwrap()
935935
}
936936
Python::with_gil(|py| {

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ as well as the [`PyReadonlyArray::try_as_matrix`] and [`PyReadwriteArray::try_as
7070
//! [c-api]: https://numpy.org/doc/stable/reference/c-api
7171
//! [ndarray]: https://numpy.org/doc/stable/reference/arrays.ndarray.html
7272
#![deny(missing_docs)]
73-
// requiring `Debug` impls is not relevant without gil-refs since `&PyArray` and
74-
// similar aren't constructible and the `pyo3::pyobject_native_type_base` macro
75-
// does not provide a `Debug` impl
73+
// requiring `Debug` impls is not relevant without gil-refs since `&PyArray`
74+
// and similar aren't constructible
7675
#![cfg_attr(feature = "gil-refs", deny(missing_debug_implementations))]
7776

7877
#[cfg(all(target_os = "windows", target_arch = "x86"))]

src/strings.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ unsafe impl<const N: usize> Element for PyFixedString<N> {
8787
impl<const N: usize> PyClone for PyFixedString<N> {
8888
#[inline]
8989
fn py_clone(&self, _py: Python<'_>) -> Self {
90-
self.clone()
90+
*self
9191
}
9292

9393
#[inline]
@@ -98,10 +98,10 @@ impl<const N: usize> PyClone for PyFixedString<N> {
9898
#[inline]
9999
fn array_from_view<D>(
100100
_py: Python<'_>,
101-
view: ::ndarray::ArrayView<'_, Self, D>
101+
view: ::ndarray::ArrayView<'_, Self, D>,
102102
) -> ::ndarray::Array<Self, D>
103103
where
104-
D: ::ndarray::Dimension
104+
D: ::ndarray::Dimension,
105105
{
106106
view.to_owned()
107107
}
@@ -171,7 +171,7 @@ impl<const N: usize> From<[Py_UCS4; N]> for PyFixedUnicode<N> {
171171
impl<const N: usize> PyClone for PyFixedUnicode<N> {
172172
#[inline]
173173
fn py_clone(&self, _py: Python<'_>) -> Self {
174-
self.clone()
174+
*self
175175
}
176176

177177
#[inline]
@@ -182,10 +182,10 @@ impl<const N: usize> PyClone for PyFixedUnicode<N> {
182182
#[inline]
183183
fn array_from_view<D>(
184184
_py: Python<'_>,
185-
view: ::ndarray::ArrayView<'_, Self, D>
185+
view: ::ndarray::ArrayView<'_, Self, D>,
186186
) -> ::ndarray::Array<Self, D>
187187
where
188-
D: ::ndarray::Dimension
188+
D: ::ndarray::Dimension,
189189
{
190190
view.to_owned()
191191
}

0 commit comments

Comments
 (0)