Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an array reference type #1440

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
99722fa
Adds an array reference type.
akern40 Oct 4, 2024
44079cc
Adds some documentation
akern40 Oct 4, 2024
3d32c08
Fixes some CI/CD issues
akern40 Oct 5, 2024
8bf86df
More CI/CD fixes
akern40 Oct 5, 2024
dda4b66
Last CI/CD fix?
akern40 Oct 5, 2024
3c75150
Switches to the "same-repr" approach to allow array views to still be…
akern40 Oct 6, 2024
28fea66
Changes back to Copy-capable ArrayBase and unchanged ArrayBase internals
akern40 Oct 6, 2024
3a180c1
Removes unused import
akern40 Oct 6, 2024
6b64678
Introduces LayoutRef and starts to move functionality from ArrayBase …
akern40 Oct 11, 2024
4c440a8
Working version of the conversion to reference types
akern40 Oct 13, 2024
c183903
Uses a new design with two reference types
akern40 Oct 13, 2024
476dac5
Satisfying CI/CD
akern40 Oct 13, 2024
68d6f53
Adds Index, equality, IntoIterator, and Hash traits, plus approximates
akern40 Oct 13, 2024
2fde998
Finishes conversions of all possible ArrayBase impls to ArrayRef
akern40 Oct 14, 2024
d63d26e
Satisfying CI/CD
akern40 Oct 14, 2024
b7281f5
Adds some aliases to avoid breaking changes, and adds an example of h…
akern40 Oct 14, 2024
663e2f9
Adds Borrow and ToOwned
akern40 Oct 14, 2024
5204f68
Tests that the *Assign operators work for slices via deref
akern40 Oct 14, 2024
6a3d131
Somehow missed a `use` for `ToOwned`
akern40 Oct 14, 2024
289130d
Implicitly use deref
akern40 Oct 14, 2024
db52eab
Adds documentation and aliases for `LayoutRef`
akern40 Oct 20, 2024
2b34bf8
Fixes doc links
akern40 Oct 20, 2024
a40307b
Adds formatting for ArrayRef
akern40 Oct 20, 2024
5adbb31
Change some examples over to ArrayRef
akern40 Oct 20, 2024
6e61e83
Adds missed #[repr(transparent)] for RawRef
akern40 Oct 20, 2024
0cd4334
Simplifies deref logic and avoids null check
akern40 Oct 20, 2024
f77ad96
Adds documentation to ArrayRef
akern40 Oct 20, 2024
3888399
Adds missing aliases to ArrayBase from RawRef and LayoutRef
akern40 Oct 21, 2024
0a3cad3
Adds a short snippet of documentation for `RawRef` and some top-level…
akern40 Oct 21, 2024
cbed837
Makes as_ref more explicit through methods on ArrayBase
akern40 Oct 26, 2024
945f70d
Restore remove_index to DataOwned
akern40 Oct 26, 2024
93dfb38
Fixes unused imports
akern40 Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Uses a new design with two reference types
akern40 committed Oct 14, 2024
commit c183903855824daaa56edd80a5a1079a9cde8e0d
7 changes: 0 additions & 7 deletions crates/blas-tests/tests/oper.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ use ndarray::prelude::*;
use ndarray::linalg::general_mat_mul;
use ndarray::linalg::general_mat_vec_mul;
use ndarray::Order;
use ndarray::Referent;
use ndarray::{Data, Ix, LinalgScalar};
use ndarray_gen::array_builder::ArrayBuilder;
use ndarray_gen::array_builder::ElementGenerator;
@@ -83,8 +82,6 @@ where
A: LinalgScalar,
S: Data<Elem = A>,
S2: Data<Elem = A>,
S::RefType: Referent,
S2::RefType: Referent,
{
let ((m, k), (k2, n)) = (lhs.dim(), rhs.dim());
assert!(m.checked_mul(n).is_some());
@@ -115,8 +112,6 @@ where
A: LinalgScalar,
S: Data<Elem = A>,
S2: Data<Elem = A>,
S::RefType: Referent,
S2::RefType: Referent,
{
let ((m, _), k) = (lhs.dim(), rhs.dim());
reference_mat_mul(
@@ -135,8 +130,6 @@ where
A: LinalgScalar,
S: Data<Elem = A>,
S2: Data<Elem = A>,
S::RefType: Referent,
S2::RefType: Referent,
{
let (m, (_, n)) = (lhs.dim(), rhs.dim());
reference_mat_mul(
4 changes: 1 addition & 3 deletions crates/numeric-tests/tests/accuracy.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};

use ndarray::linalg::general_mat_mul;
use ndarray::{prelude::*, Referent};
use ndarray::prelude::*;
use ndarray::{Data, LinalgScalar};

use num_complex::Complex;
@@ -44,8 +44,6 @@ where
A: LinalgScalar,
S: Data<Elem = A>,
S2: Data<Elem = A>,
S::RefType: Referent,
S2::RefType: Referent,
{
let ((m, k), (_, n)) = (lhs.dim(), rhs.dim());
let mut res_elems = Array::zeros(m * n);
2 changes: 0 additions & 2 deletions examples/rollaxis.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use ndarray::prelude::*;
use ndarray::Data;
use ndarray::Referent;

pub fn roll_axis<A, S, D>(mut a: ArrayBase<S, D>, to: Axis, from: Axis) -> ArrayBase<S, D>
where
S: Data<Elem = A>,
D: Dimension,
S::RefType: Referent,
{
let i = to.index();
let mut j = from.index();
6 changes: 1 addition & 5 deletions ndarray-rand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ use crate::rand::rngs::SmallRng;
use crate::rand::seq::index;
use crate::rand::{thread_rng, Rng, SeedableRng};

use ndarray::{Array, Axis, Referent, RemoveAxis, ShapeBuilder};
use ndarray::{Array, Axis, RemoveAxis, ShapeBuilder};
use ndarray::{ArrayBase, Data, DataOwned, Dimension, RawData};
#[cfg(feature = "quickcheck")]
use quickcheck::{Arbitrary, Gen};
@@ -168,7 +168,6 @@ where
where
A: Copy,
S: Data<Elem = A>,
S::RefType: Referent,
D: RemoveAxis;

/// Sample `n_samples` lanes slicing along `axis` using the specified RNG `rng`.
@@ -226,7 +225,6 @@ where
R: Rng + ?Sized,
A: Copy,
S: Data<Elem = A>,
S::RefType: Referent,
D: RemoveAxis;
}

@@ -258,7 +256,6 @@ where
where
A: Copy,
S: Data<Elem = A>,
S::RefType: Referent,
D: RemoveAxis,
{
self.sample_axis_using(axis, n_samples, strategy, &mut get_rng())
@@ -269,7 +266,6 @@ where
R: Rng + ?Sized,
A: Copy,
S: Data<Elem = A>,
S::RefType: Referent,
D: RemoveAxis,
{
let indices: Vec<_> = match strategy {
6 changes: 3 additions & 3 deletions src/alias_slicing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{iter::Axes, ArrayBase, Axis, AxisDescription, Dimension, RawData, Slice, SliceArg};
use crate::{iter::Axes, ArrayBase, Axis, AxisDescription, Dimension, LayoutRef, RawData, Slice, SliceArg};

impl<S: RawData, D: Dimension> ArrayBase<S, D>
{
@@ -95,7 +95,7 @@ impl<S: RawData, D: Dimension> ArrayBase<S, D>
/// preferring axes with len > 1.
pub fn max_stride_axis(&self) -> Axis
{
self.as_ref().max_stride_axis()
LayoutRef::max_stride_axis(&self.as_ref())
}

/// Reverse the stride of `axis`.
@@ -173,6 +173,6 @@ impl<S: RawData, D: Dimension> ArrayBase<S, D>
/// Return the strides of the array as a slice.
pub fn strides(&self) -> &[isize]
{
(**self).strides()
self.as_ref().strides()
}
}
12 changes: 1 addition & 11 deletions src/array_approx.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#[cfg(feature = "approx")]
mod approx_methods
{
use crate::{arrayref::Referent, imp_prelude::*};
use crate::imp_prelude::*;

impl<A, S, D> ArrayBase<S, D>
where
S: Data<Elem = A>,
D: Dimension,
S::RefType: Referent,
{
/// A test for equality that uses the elementwise absolute difference to compute the
/// approximate equality of two arrays.
@@ -18,7 +17,6 @@ mod approx_methods
A: ::approx::AbsDiffEq<S2::Elem>,
A::Epsilon: Clone,
S2: Data,
S2::RefType: Referent,
{
<Self as ::approx::AbsDiffEq<_>>::abs_diff_eq(self, other, epsilon)
}
@@ -32,7 +30,6 @@ mod approx_methods
A: ::approx::RelativeEq<S2::Elem>,
A::Epsilon: Clone,
S2: Data,
S2::RefType: Referent,
{
<Self as ::approx::RelativeEq<_>>::relative_eq(self, other, epsilon, max_relative)
}
@@ -44,7 +41,6 @@ macro_rules! impl_approx_traits {
mod $approx {
use crate::imp_prelude::*;
use crate::Zip;
use crate::Referent;
use $approx::{AbsDiffEq, RelativeEq, UlpsEq};

#[doc = $doc]
@@ -55,8 +51,6 @@ macro_rules! impl_approx_traits {
S: Data<Elem = A>,
S2: Data<Elem = B>,
D: Dimension,
S::RefType: Referent,
S2::RefType: Referent,
{
type Epsilon = A::Epsilon;

@@ -83,8 +77,6 @@ macro_rules! impl_approx_traits {
S: Data<Elem = A>,
S2: Data<Elem = B>,
D: Dimension,
S::RefType: Referent,
S2::RefType: Referent,
{
fn default_max_relative() -> A::Epsilon {
A::default_max_relative()
@@ -114,8 +106,6 @@ macro_rules! impl_approx_traits {
S: Data<Elem = A>,
S2: Data<Elem = B>,
D: Dimension,
S::RefType: Referent,
S2::RefType: Referent,
{
fn default_max_ulps() -> u32 {
A::default_max_ulps()
2 changes: 0 additions & 2 deletions src/array_serde.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ use alloc::vec::Vec;
use std::fmt;
use std::marker::PhantomData;

use crate::arrayref::Referent;
use crate::imp_prelude::*;

use super::arraytraits::ARRAY_FORMAT_VERSION;
@@ -84,7 +83,6 @@ where
A: Serialize,
D: Dimension + Serialize,
S: Data<Elem = A>,
S::RefType: Referent,
{
fn serialize<Se>(&self, serializer: Se) -> Result<Se::Ok, Se::Error>
where Se: Serializer
30 changes: 7 additions & 23 deletions src/arrayformat.rs
Original file line number Diff line number Diff line change
@@ -6,10 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer};
use crate::{
aliases::{Ix1, IxDyn},
arrayref::Referent,
};
use crate::aliases::{Ix1, IxDyn};
use alloc::format;
use std::fmt;

@@ -122,7 +119,6 @@ where
F: FnMut(&A, &mut fmt::Formatter<'_>) -> fmt::Result + Clone,
D: Dimension,
S: Data<Elem = A>,
S::RefType: Referent,
{
// Cast into a dynamically dimensioned view
// This is required to be able to use `index_axis` for the recursive case
@@ -177,9 +173,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::Display, S, D: Dimension> fmt::Display for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
@@ -193,9 +187,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::Debug, S, D: Dimension> fmt::Debug for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
@@ -223,9 +215,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::LowerExp, S, D: Dimension> fmt::LowerExp for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
@@ -239,9 +229,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::UpperExp, S, D: Dimension> fmt::UpperExp for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
@@ -254,9 +242,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::LowerHex, S, D: Dimension> fmt::LowerHex for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
@@ -270,9 +256,7 @@ where
///
/// The array is shown in multiline style.
impl<A: fmt::Binary, S, D: Dimension> fmt::Binary for ArrayBase<S, D>
where
S: Data<Elem = A>,
S::RefType: Referent,
where S: Data<Elem = A>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
87 changes: 0 additions & 87 deletions src/arrayref.rs

This file was deleted.

Loading