8000 Generalize ref-to-ref ops by akern40 · Pull Request #1468 · rust-ndarray/ndarray · GitHub
[go: up one dir, main page]

Skip to content

Generalize ref-to-ref ops #1468

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

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 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
1d5d6f4
Generalize ref-to-ref ops to work with arbitrary output types
akern40 Dec 23, 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
Switches to the "same-repr" approach to allow array views to still be…
… Copy
  • Loading branch information
akern40 committed Oct 14, 2024
commit 3c75150a8ff971293555614c0a9e677411109712
22 changes: 20 additions & 2 deletions src/arrayref.rs
< 8000 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ where S: RawData

fn deref(&self) -> &Self::Target
{
&self.aref
// SAFETY: The pointer will hold all the guarantees of `as_ref`:
// - The pointer is aligned because neither type use repr(align)
// - It is "dereferencable" because it just points to self
// - For the same reason, it is initialized
unsafe {
(self as *const Self)
.cast::<RefBase<S::Elem, D, S::Referent>>()
.as_ref()
}
.expect("Pointer to self will always be non-null")
}
}

Expand All @@ -64,6 +73,15 @@ where
fn deref_mut(&mut self) -> &mut Self::Target
{
self.try_ensure_unique();
&mut self.aref
// SAFETY: The pointer will hold all the guarantees of `as_ref`:
// - The pointer is aligned because neither type use repr(align)
// - It is "dereferencable" because it just points to self
// - For the same reason, it is initialized
unsafe {
(self as *mut Self)
.cast::<RefBase<S::Elem, D, S::Referent>>()
.as_mut()
}
.expect("Pointer to self will always be non-null")
}
}
2 changes: 1 addition & 1 deletion src/impl_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ impl<S: RawDataClone, D: Clone> Clone for ArrayBase<S, D>
}
}

// impl<S: RawDataClone + Copy, D: Copy> Copy for ArrayBase<S, D> {}
impl<S: RawDataClone + Copy, D: Copy> Copy for ArrayBase<S, D> {}
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,14 +1284,20 @@ pub type Ixs = isize;
// may change in the future.
//
// [`.offset()`]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset-1
#[repr(C)]
pub struct ArrayBase<S, D>
where S: RawData
{
/// A non-null pointer into the buffer held by `data`; may point anywhere
/// in its range. If `S: Data`, this pointer must be aligned.
ptr: std::ptr::NonNull<S::Elem>,
/// The lengths of the axes.
dim: D,
/// The element count stride per axis. To be parsed as `isize`.
strides: D,
/// Data buffer / ownership information. (If owned, contains the data
/// buffer; if borrowed, contains the lifetime and mutability.)
data: S,
/// Array reference type
aref: RefBase<S::Elem, D, S::Referent>,
}

/// A reference to an *n*-dimensional array.
Expand Down Expand Up @@ -1344,6 +1350,7 @@ where S: RawData
/// #[allow(dead_code)]
/// unsafe fn write_unchecked<A, D, R: RawReferent>(arr: &mut RefBase<A, D, R>) {}
/// ```
#[repr(C)]
pub struct RefBase<A, D, R>
where R: RawReferent
{
Expand Down
0