pub struct MmapArray<F: MmapElement> { /* private fields */ }Expand description
A zero-copy, file-backed ndarray with optional Copy-on-Write semantics.
The array is stored in a flat binary file with a 64-byte header. Array
data is accessed via memmap2, so the OS manages paging automatically.
§Type Parameter
F must implement MmapElement (currently: f32, f64, i32, i64).
Implementations§
Source§impl<F: MmapElement> MmapArray<F>
impl<F: MmapElement> MmapArray<F>
Sourcepub fn create(path: &Path, data: &Array<F, IxDyn>) -> Result<Self, MmapError>
pub fn create(path: &Path, data: &Array<F, IxDyn>) -> Result<Self, MmapError>
Create a new memory-mapped file from an existing ndarray and return a
read-write MmapArray backed by that file.
The input array must be in standard C-order (contiguous) layout. A 64-byte header is written first, followed immediately by the raw element bytes.
§Errors
Returns MmapError::NonContiguous if data is not a contiguous array.
Sourcepub fn open_read_only(path: &Path) -> Result<Self, MmapError>
pub fn open_read_only(path: &Path) -> Result<Self, MmapError>
Open an existing .mmap file in read-only mode.
The returned array cannot be mutated; calls to view_mut
will return MmapError::ReadOnly.
Sourcepub fn open_read_write(path: &Path) -> Result<Self, MmapError>
pub fn open_read_write(path: &Path) -> Result<Self, MmapError>
Open an existing .mmap file in read-write mode.
Mutations are written directly to the file (no buffering).
Sourcepub fn open_cow(path: &Path) -> Result<Self, MmapError>
pub fn open_cow(path: &Path) -> Result<Self, MmapError>
Open an existing .mmap file in Copy-on-Write mode.
Reads are served zero-copy from the OS page cache. The first call to
view_mut triggers a full copy of the data into RAM,
after which all mutations happen in-memory. The original file is never
modified unless you later call flush (which, in COW mode,
is a no-op since there is no writable mapping to flush).
Sourcepub fn view(&self) -> Result<ArrayView<'_, F, IxDyn>, MmapError>
pub fn view(&self) -> Result<ArrayView<'_, F, IxDyn>, MmapError>
Return a read-only ndarray view.
For read-only and read-write modes, the view is zero-copy (backed by the mmap). For COW mode before any write, the view is also zero-copy. For COW mode after the first write, the view is backed by the in-RAM copy.
Sourcepub fn view_mut(&mut self) -> Result<ArrayViewMut<'_, F, IxDyn>, MmapError>
pub fn view_mut(&mut self) -> Result<ArrayViewMut<'_, F, IxDyn>, MmapError>
Return a mutable ndarray view.
- ReadOnly: always returns
MmapError::ReadOnly. - ReadWrite: the view is zero-copy and writes go directly to the file.
- COW: triggers a copy of the mmap data into RAM on the first call.
Sourcepub fn flush(&self) -> Result<(), MmapError>
pub fn flush(&self) -> Result<(), MmapError>
Flush changes to disk.
- ReadWrite: calls
MmapMut::flush(). - ReadOnly / COW: no-op (returns
Ok(())).
Sourcepub fn to_owned_array(&self) -> Result<Array<F, IxDyn>, MmapError>
pub fn to_owned_array(&self) -> Result<Array<F, IxDyn>, MmapError>
Copy all elements into a heap-allocated Array<F, IxDyn>.
This always copies; it is equivalent to .view()?.to_owned().
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for MmapArray<F>
impl<F> RefUnwindSafe for MmapArray<F>where
F: RefUnwindSafe,
impl<F> Send for MmapArray<F>where
F: Send,
impl<F> Sync for MmapArray<F>where
F: Sync,
impl<F> Unpin for MmapArray<F>where
F: Unpin,
impl<F> UnsafeUnpin for MmapArray<F>
impl<F> UnwindSafe for MmapArray<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.