Struct Coords

Source
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§

Source§

impl Coords

Source

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

Source

pub fn from_iter<I: IntoIterator<Item = Coord>>(iter: I, ndim: usize) -> Self

Constructs a new Coords from an iterator of Coords.

Panics: if any Coord is not of length ndim, or if ndim is zero.

Source

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

Source

pub async fn from_stream<S: Stream<Item = Coord> + Unpin>( source: S, ndim: usize, size_hint: Option<usize>, ) -> Self

Constructs a new Coords from a Stream of Coords.

Panics: if any Coord has a length other than ndim, or if ndim is zero

Source

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 Coords.

Panics: if any Coord has a length other than ndim

Source

pub fn is_empty(&self) -> bool

Return true if the number of coordinates in these Coords is zero.

Source

pub fn is_sorted(&self, shape: &[u64]) -> bool

Return true if these Coords are in sorted order with respect to the given shape.

Source

pub fn len(&self) -> usize

Return the number of coordinates stored in these Coords.

Source

pub fn ndim(&self) -> usize

Return the number of dimensions of these Coords.

Source

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

Source

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()

Source

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()

Source

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()

Source

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.

Source

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.

Source

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.

Source

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()

Source

pub fn get(&self, axes: &[usize]) -> Self

Construct a new Coords from the selected indices.

Panics: if any index is out of bounds

Source

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()

Source

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()

Source

pub fn to_vec(&self) -> Vec<Coord>

Return a list of Coords from these Coords.

Panics: if the given number of dimensions does not fit the set of coordinates

Source

pub fn into_vec(self) -> Vec<Coord>

Convert these Coords into a list of Coords.

Panics: if the given number of dimensions does not fit the set of coordinates.

Methods from Deref<Target = Array<u64>>§

Source

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.

Source

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.

Source

pub fn elements(&self) -> usize

Returns the number of elements in the Array

Source

pub fn get_type(&self) -> DType

Returns the Array data type

Source

pub fn dims(&self) -> Dim4

Returns the dimensions of the Array

Source

pub fn strides(&self) -> Dim4

Returns the strides of the Array

Source

pub fn numdims(&self) -> u32

Returns the number of dimensions of the Array

Source

pub fn offset(&self) -> i64

Returns the offset to the pointer from where data begins

Source

pub unsafe fn get(&self) -> *mut c_void

Returns the native FFI handle for Rust object Array

Source

pub fn set(&mut self, handle: *mut c_void)

Set the native FFI handle for Rust object Array

Source

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);
Source

pub fn eval(&self)

Evaluates any pending lazy expressions that represent the data in the Array object

Source

pub fn copy(&self) -> Array<T>

Makes an copy of the Array

This does a deep copy of the data into a new Array

Source

pub fn is_empty(&self) -> bool

Check if Array is empty

Source

pub fn is_scalar(&self) -> bool

Check if Array is scalar

Source

pub fn is_row(&self) -> bool

Check if Array is a row

Source

pub fn is_column(&self) -> bool

Check if Array is a column

Source

pub fn is_vector(&self) -> bool

Check if Array is a vector

Source

pub fn is_real(&self) -> bool

Check if Array is of real (not complex) type

Source

pub fn is_complex(&self) -> bool

Check if Array is of complex type

Source

pub fn is_double(&self) -> bool

Check if Array’s numerical type is of double precision

Source

pub fn is_single(&self) -> bool

Check if Array’s numerical type is of single precision

Source

pub fn is_half(&self) -> bool

Check if Array’s numerical type is of half precision

Source

pub fn is_integer(&self) -> bool

Check if Array is of integral type

Source

pub fn is_bool(&self) -> bool

Check if Array is of boolean type

Source

pub fn is_realfloating(&self) -> bool

Check if Array is floating point real(not complex) data type

Source

pub fn is_floating(&self) -> bool

Check if Array is floating point type, either real or complex data

Source

pub fn is_linear(&self) -> bool

Check if Array’s memory layout is continuous and one dimensional

Source

pub fn is_sparse(&self) -> bool

Check if Array is a sparse matrix

Source

pub fn is_owner(&self) -> bool

Check if Array’s memory is owned by it and not a view of another Array

Source

pub fn cast<O>(&self) -> Array<O>
where O: HasAfEnum,

Cast the Array data type to target_type

Source

pub fn lock(&self)

Lock the device buffer in the memory manager

Locked buffers are not freed by memory manager until unlock is called.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Coords

Source§

fn clone(&self) -> Coords

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Coords

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Coords

Source§

type Target = Array<u64>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Coords

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl PartialEq for Coords

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Coords

§

impl RefUnwindSafe for Coords

§

impl Send for Coords

§

impl Sync for Coords

§

impl Unpin for Coords

§

impl UnwindSafe for Coords

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<F, T> CastFrom<F> for T
where T: From<F>,

Source§

fn cast_from(f: F) -> T

Cast an instance of T into an instance of Self.
Source§

impl<T, F> CastInto<F> for T
where F: CastFrom<T>,

Source§

fn cast_into(self) -> F

Cast an instance of Self into an instance of T.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> Match for F

Source§

fn matches<T>(&self) -> bool
where T: TryCastFrom<Self>,

Returns true if self can be cast into the target type T.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<F, T> TryCastFrom<F> for T
where T: CastFrom<F>,

Source§

fn can_cast_from(_: &F) -> bool

Test if value can be cast into Self.
Source§

fn opt_cast_from(f: F) -> Option<T>

Returns Some(Self) if the source value can be cast into Self, otherwise None.
Source§

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.
Source§

impl<F, T> TryCastInto<T> for F
where T: TryCastFrom<F>,

Source§

fn can_cast_into(&self) -> bool

Test if self can be cast into T.
Source§

fn opt_cast_into(self) -> Option<T>

Returns Some(T) if self can be cast into T, otherwise None.
Source§

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.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.