pub struct Coords { /* private fields */ }
Expand description
A hardware-accelerated set of n-dimensional coordinates, all with the same dimension.
TODO: separate out a CoordBasis
struct
Implementations
sourceimpl Coords
impl Coords
sourcepub fn empty(shape: &[u64], size: usize) -> Self
pub fn empty(shape: &[u64], size: usize) -> Self
Constructs Coords
with the given size
full of zeros (origin points) for the given shape.
Panics: if shape is empty
sourcepub fn from_iter<I: IntoIterator<Item = Coord>>(iter: I, ndim: usize) -> Self
pub fn from_iter<I: IntoIterator<Item = Coord>>(iter: I, ndim: usize) -> Self
sourcepub fn from_offsets(offsets: Offsets, shape: &[u64]) -> Self
pub fn from_offsets(offsets: Offsets, shape: &[u64]) -> Self
Constructs a new Coords
from an ArrayExt
of offsets with respect to the given shape.
Panics: if shape
is empty
sourcepub async fn from_stream<S: Stream<Item = Coord> + Unpin>(
source: S,
ndim: usize,
size_hint: Option<usize>
) -> Self
pub async fn from_stream<S: Stream<Item = Coord> + Unpin>(
source: S,
ndim: usize,
size_hint: Option<usize>
) -> Self
sourcepub async fn try_from_stream<E, S: TryStream<Ok = Coord, Error = E> + Unpin>(
source: S,
ndim: usize,
size_hint: Option<usize>
) -> Result<Self, E>
pub async fn try_from_stream<E, S: TryStream<Ok = Coord, Error = E> + Unpin>(
source: S,
ndim: usize,
size_hint: Option<usize>
) -> Result<Self, E>
Constructs a new Coords
from a [TryStream
] of Coord
s.
Panics: if any Coord
has a length other than ndim
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true
if the number of coordinates in these Coords
is zero.
sourcepub fn is_sorted(&self, shape: &[u64]) -> bool
pub fn is_sorted(&self, shape: &[u64]) -> bool
Return true
if these Coords
are in sorted order with respect to the given shape
.
sourcepub fn contract_dim(&self, axis: usize) -> Self
pub fn contract_dim(&self, axis: usize) -> Self
Return a copy of these Coords
without the specified axis.
Panics: if there is no dimension at axis
sourcepub fn expand(&self, source_shape: &[u64], reduce_axis: usize) -> Self
pub fn expand(&self, source_shape: &[u64], reduce_axis: usize) -> Self
Return the Coords
of source elements to reduce along the given axis.
Panics: if reduce_axis <= source_shape.len()
sourcepub fn expand_dim(&self, axis: usize) -> Self
pub fn expand_dim(&self, axis: usize) -> Self
Return a copy of these Coords
with a new dimension at the given axis.
Panics: if axis
is greater than self.ndim()
sourcepub fn flip(self, shape: &[u64], axis: usize) -> Self
pub fn flip(self, shape: &[u64], axis: usize) -> Self
Return these Coords
as flipped around axis
with respect to the given shape
.
E.g. flipping axis 1 of coordinate [0, 1, 2]
in shape [5, 5, 5]
produces [0, 4, 2]
.
Panics: if self.ndim() != shape.len()
sourcepub fn slice(
&self,
shape: &[u64],
elided: &HashMap<usize, u64>,
offset: &HashMap<usize, u64>
) -> Self
pub fn slice(
&self,
shape: &[u64],
elided: &HashMap<usize, u64>,
offset: &HashMap<usize, u64>
) -> Self
Transform the coordinate basis of these Coords
from a source tensor to a slice.
sourcepub fn transpose<P: AsRef<[usize]>>(&self, permutation: Option<P>) -> Coords
pub fn transpose<P: AsRef<[usize]>>(&self, permutation: Option<P>) -> Coords
Transpose these Coords
according to the given permutation
.
If no permutation is given, the coordinate axes will be inverted.
sourcepub fn unbroadcast(&self, source_shape: &[u64], broadcast: &[bool]) -> Coords
pub fn unbroadcast(&self, source_shape: &[u64], broadcast: &[bool]) -> Coords
Invert the given broadcast of these Coords
.
Panics: if source_shape
and broadcast
are not the same length.
sourcepub fn unslice(
&self,
source_shape: &[u64],
elided: &HashMap<usize, u64>,
offset: &HashMap<usize, u64>
) -> Self
pub fn unslice(
&self,
source_shape: &[u64],
elided: &HashMap<usize, u64>,
offset: &HashMap<usize, u64>
) -> Self
Transform the coordinate basis of these Coords
from a slice to a source tensor.
Panics: if source_shape.len() - self.ndim()
does not match elided.len()
sourcepub fn get(&self, axes: &[usize]) -> Self
pub fn get(&self, axes: &[usize]) -> Self
Construct a new Coords
from the selected indices.
Panics: if any index is out of bounds
sourcepub fn set(&mut self, axes: &[usize], value: &Self)
pub fn set(&mut self, axes: &[usize], value: &Self)
Update these Coords
by writing the given value
at the given index
.
Panics: if any index is out of bounds, or if value.len()
does not match self.len()
sourcepub fn to_offsets(&self, shape: &[u64]) -> ArrayExt<u64>
pub fn to_offsets(&self, shape: &[u64]) -> ArrayExt<u64>
Return these Coords
as Offsets
with respect to the given shape.
Panics: if shape.len()
does not equal self.ndim()
Methods from Deref<Target = Array<u64>>
sourcepub fn get_backend(&self) -> Backend
pub fn get_backend(&self) -> Backend
Returns the backend of the Array
Return Values
Returns an value of type Backend
which indicates which backend
was active when Array was created.
sourcepub fn get_device_id(&self) -> i32
pub fn get_device_id(&self) -> i32
Returns the device identifier(integer) on which the Array was created
Return Values
Return the device id on which Array was created.
sourcepub fn host<O>(&self, data: &mut [O]) where
O: HasAfEnum,
pub fn host<O>(&self, data: &mut [O]) where
O: HasAfEnum,
Copies the data from the Array to the mutable slice data
Examples
Basic case
let a:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
let b = Array::<u8>::new(&a,Dim4::new(&[3,3,1,1]));
let mut c = vec!(u8::default();b.elements());
b.host(&mut c);
assert_eq!(c,a);
Generic case
fn to_vec<T:HasAfEnum+Default+Clone>(array:&Array<T>) -> Vec<T> {
let mut vec = vec!(T::default();array.elements());
array.host(&mut vec);
return vec;
}
let a = Array::<u8>::new(&[0,1,2,3,4,5,6,7,8],Dim4::new(&[3,3,1,1]));
let b:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
assert_eq!(to_vec(&a),b);
sourcepub fn eval(&self)
pub fn eval(&self)
Evaluates any pending lazy expressions that represent the data in the Array object
sourcepub fn copy(&self) -> Array<T>
pub fn copy(&self) -> Array<T>
Makes an copy of the Array
This does a deep copy of the data into a new Array
sourcepub fn is_complex(&self) -> bool
pub fn is_complex(&self) -> bool
Check if Array is of complex type
sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Check if Array is of integral type
sourcepub fn is_realfloating(&self) -> bool
pub fn is_realfloating(&self) -> bool
Check if Array is floating point real(not complex) data type
sourcepub fn is_floating(&self) -> bool
pub fn is_floating(&self) -> bool
Check if Array is floating point type, either real or complex data
sourcepub fn is_linear(&self) -> bool
pub fn is_linear(&self) -> bool
Check if Array’s memory layout is continuous and one dimensional
sourcepub fn is_owner(&self) -> bool
pub fn is_owner(&self) -> bool
Check if Array’s memory is owned by it and not a view of another Array
sourcepub fn lock(&self)
pub fn lock(&self)
Lock the device buffer in the memory manager
Locked buffers are not freed by memory manager until unlock is called.
sourcepub fn unlock(&self)
pub fn unlock(&self)
Unlock the device buffer in the memory manager
This function will give back the control over the device pointer to the memory manager.
sourcepub unsafe fn device_ptr(&self) -> *mut c_void
pub unsafe fn device_ptr(&self) -> *mut c_void
Get the device pointer and lock the buffer in memory manager
The device pointer is not freed by memory manager until unlock is called.
sourcepub fn get_allocated_bytes(&self) -> usize
pub fn get_allocated_bytes(&self) -> usize
Get the size of physical allocated bytes.
This function will return the size of the parent/owner if the current Array object is an indexed Array.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Coords
impl Send for Coords
impl Sync for Coords
impl Unpin for Coords
impl UnwindSafe for Coords
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> Match for F
impl<F> Match for F
sourcefn matches<T>(&self) -> bool where
T: TryCastFrom<Self>,
fn matches<T>(&self) -> bool where
T: TryCastFrom<Self>,
Returns true
if self
can be cast into the target type T
.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<F, T> TryCastFrom<F> for T where
T: CastFrom<F>,
impl<F, T> TryCastFrom<F> for T where
T: CastFrom<F>,
sourcefn can_cast_from(&F) -> bool
fn can_cast_from(&F) -> bool
Test if value
can be cast into Self
.
sourcefn opt_cast_from(f: F) -> Option<T>
fn opt_cast_from(f: F) -> Option<T>
Returns Some(Self)
if the source value can be cast into Self
, otherwise None
.
sourcefn try_cast_from<Err, OnErr>(value: T, on_err: OnErr) -> Result<Self, Err> where
OnErr: FnOnce(&T) -> Err,
fn try_cast_from<Err, OnErr>(value: T, on_err: OnErr) -> Result<Self, Err> where
OnErr: FnOnce(&T) -> Err,
Returns Ok(Self)
if the source value can be cast into Self
, otherwise calls on_err
.
sourceimpl<F, T> TryCastInto<T> for F where
T: TryCastFrom<F>,
impl<F, T> TryCastInto<T> for F where
T: TryCastFrom<F>,
sourcefn can_cast_into(&self) -> bool
fn can_cast_into(&self) -> bool
Test if self
can be cast into T
.
sourcefn opt_cast_into(self) -> Option<T>
fn opt_cast_into(self) -> Option<T>
Returns Some(T)
if self
can be cast into T
, otherwise None
.
sourcefn try_cast_into<Err, OnErr>(self, on_err: OnErr) -> Result<T, Err> where
OnErr: FnOnce(&Self) -> Err,
fn try_cast_into<Err, OnErr>(self, on_err: OnErr) -> Result<T, Err> where
OnErr: FnOnce(&Self) -> Err,
Returns Ok(T)
if self
can be cast into T
, otherwise calls on_err
.