pub struct Array {
pub shape: Vec<usize>,
pub data: Data,
/* private fields */
}Expand description
An array: a logical shape, a flat buffer, and the layout joining them.
data is the buffer as it lies. A reader that indexes it must either
honour Array::layout or take Array::to_row_major first; the
runtime’s rule is that a value reaching a verb has already been made
row-major unless that verb asked for the other one.
A SPARSE array is the one exception to “the buffer holds every element”:
shape is still the logical shape, but data holds only the stored
cells and crate::sparse::Sparse says where they sit. Only $., the
display and ": read that form; every other reader takes
Array::densified first.
Fields§
§shape: Vec<usize>§data: DataImplementations§
Source§impl Array
impl Array
pub fn new(shape: Vec<usize>, data: Data) -> Array
Sourcepub fn sparse(shape: Vec<usize>, data: Data, sparse: Sparse) -> Array
pub fn sparse(shape: Vec<usize>, data: Data, sparse: Sparse) -> Array
A sparse array: the logical shape, the stored cells, and the
description of where they sit. data holds entries cells and not
one element per position, so this is the only constructor that does
not tie the buffer’s length to the shape.
Sourcepub fn proto(&self) -> Option<&Array>
pub fn proto(&self) -> Option<&Array>
The item an array with no items would have held — APL’s prototype.
A simple array’s type says what its fills look like, so nothing has
to be remembered; a nested one does, since an empty buffer of boxes
no longer says whether its items were pairs of numbers or of
characters. 0⍴⊂2 3⍴9 is such an array, and ↑ of it answers the
2 by 3 table of zeros this holds. Only the operations that make an
empty out of a nested array set it, and only APL reads it.
Sourcepub fn with_proto(self, proto: Array) -> Array
pub fn with_proto(self, proto: Array) -> Array
The same array, remembering what its items looked like.
Sourcepub fn sparse_parts(&self) -> Option<&Sparse>
pub fn sparse_parts(&self) -> Option<&Sparse>
How this array is stored sparsely, or None for a dense one.
Sourcepub fn densified(&self) -> Array
pub fn densified(&self) -> Array
This array with every position materialised. A dense array is a refcount bump; a sparse one is expanded here and nowhere else.
Sourcepub fn col_major(shape: Vec<usize>, data: Data) -> Array
pub fn col_major(shape: Vec<usize>, data: Data) -> Array
An array whose buffer holds its first axis fastest — the columns of a matrix, end to end. Rank 0 and 1 have only one layout and take it.
Sourcepub fn with_layout(self, layout: Layout) -> Array
pub fn with_layout(self, layout: Layout) -> Array
The same buffer read the other way round. The caller is asserting
that the buffer really is in layout order for this shape.
pub fn is_row_major(&self) -> bool
Sourcepub fn row_major_data(&self) -> &Data
pub fn row_major_data(&self) -> &Data
The flat buffer, for a reader that indexes it row-major. Debug builds refuse a buffer that is not in that order, which is what keeps a column-major table from being read as if it were rows.
Sourcepub fn to_row_major(&self) -> Array
pub fn to_row_major(&self) -> Array
This array with its elements in row-major order, materialising them once if they are not. Already row-major: a refcount bump.
pub fn scalar_i64(v: i64) -> Array
pub fn scalar_f64(v: f64) -> Array
pub fn scalar_bool(v: bool) -> Array
pub fn from_i64(values: Vec<i64>) -> Array
pub fn from_f64(values: Vec<f64>) -> Array
pub fn from_chars(values: Vec<char>) -> Array
pub fn empty(dtype: DType) -> Array
Sourcepub fn box_fill() -> Array
pub fn box_fill() -> Array
The element that fills a boxed array: J’s a:, a box holding an
empty numeric list.
pub fn dtype(&self) -> DType
pub fn rank(&self) -> usize
Sourcepub fn items(&self) -> usize
pub fn items(&self) -> usize
Number of items (major cells): leading axis length, 1 for a scalar.
Sourcepub fn cast(&self, to: DType) -> Option<Array>
pub fn cast(&self, to: DType) -> Option<Array>
Widen the elements. A cast reads and writes the buffer as it lies, so the layout comes through untouched.
Sourcepub fn cells(&self, frame_rank: usize) -> Vec<Array>
pub fn cells(&self, frame_rank: usize) -> Vec<Array>
Split into cells: the trailing cell_rank axes form the cell shape,
the leading axes form the frame.
Sourcepub fn cell_at(&self, frame_rank: usize, index: usize) -> Array
pub fn cell_at(&self, frame_rank: usize, index: usize) -> Array
One cell without materialising all of them.
pub fn as_i64_slice(&self) -> Option<&[i64]>
pub fn as_f64_slice(&self) -> Option<&[f64]>
Sourcepub fn as_ext_slice(&self) -> Option<&[Ext]>
pub fn as_ext_slice(&self) -> Option<&[Ext]>
The extended integers, if the array holds them.
Sourcepub fn as_rat_slice(&self) -> Option<&[Rat]>
pub fn as_rat_slice(&self) -> Option<&[Rat]>
The rationals, if the array holds them.
pub fn as_complex_slice(&self) -> Option<&[Cx]>
Sourcepub fn to_complex_vec(&self) -> Option<Vec<Cx>>
pub fn to_complex_vec(&self) -> Option<Vec<Cx>>
Numeric contents widened to complex. None for character or boxed data.
Sourcepub fn to_f64_vec(&self) -> Option<Vec<f64>>
pub fn to_f64_vec(&self) -> Option<Vec<f64>>
Numeric contents widened to f64. None for character data.
Sourcepub fn to_i64_vec(&self) -> Option<Vec<i64>>
pub fn to_i64_vec(&self) -> Option<Vec<i64>>
Numeric contents as i64 if exactly representable.
Sourcepub fn to_i64_vec_near(&self, near: NearInt) -> Option<Vec<i64>>
pub fn to_i64_vec_near(&self, near: NearInt) -> Option<Vec<i64>>
Numeric contents as i64 where a COUNT, a LENGTH or an INDEX is wanted, admitting a float that is merely near a whole number.
Both references round such a float to the whole number beside it
rather than refusing it — ⍳2-1E¯14 is 1 2 and (2-1e_14) {. 1 2 3
is 1 2 — and neither admission is the comparison tolerance:
⎕CT←0 and 9!:19 (0) leave both exactly where they are. The two
admissions differ in shape. NearInt::J is relative, a value
within 2^-44 of a whole number’s magnitude; NearInt::Apl is
absolute, 1e-10, whatever the magnitude; NearInt::Tolerant is
relative and follows the comparison tolerance in force. Everything a
full integer apart is still a refusal in all three.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Array
impl !UnwindSafe for Array
impl Freeze for Array
impl Send for Array
impl Sync for Array
impl Unpin for Array
impl UnsafeUnpin for Array
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more