pub struct StaticCowVec<'a, T: Copy, const LEN: usize> { /* private fields */ }
Expand description

Vectors as copy-on-write smart pointers. Use full for situations where you don’t know, if you need mutable access to your data, at compile time. See moo for how to create a StaticCowVec.

Implementations

Cast StaticCowVec from pointer.

Safety

Is safe as long as *ptr is contiguous and *ptr has a length of LEN.

Cast StaticCowVec from pointer without checking if it is null. Very very very unsafe.

Safety

Is safe as long as *ptr is contiguous, *ptr has a length of LEN and ptr is not NULL.

Methods from Deref<Target = StaticVecUnion<'a, T, LEN>>

Example
use slas::prelude::*;

let a = moo![f32: 0..6].reshape(&[3, 2], slas_backend::Blas);
let b = [0.; 6].reshape(&[2, 3], slas_backend::Blas);

assert_eq!(a.matrix().matrix_mul(&b.matrix()), [0.; 4]);

In this example the matricies a and b have dynamic shapes. If you wan’t to create matricies with static shapes, you should use StaticVec::matrix.

Example
use slas::prelude::*;

let a = moo![f32: 0..6].reshape(&[3, 2], slas_backend::Blas);
let b = [0.; 6].reshape(&[2, 3], slas_backend::Blas);

assert_eq!(a.matrix().matrix_mul(&b.matrix()), [0.; 4]);

In this example the matricies a and b have dynamic shapes. If you wan’t to create matricies with static shapes, you should use StaticVec::matrix.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Basic element-wise vector operations, implemented automatically with macro.

Dot product for two complex vectors using blas. There is no rust backend for complex dot products at the moment.

Vector dot product.

This can be called on any StaticVec, by calling StaticVec::moo_ref on it first.

Example
use slas::prelude::*;

// There is some inaccuracy due to float rounding.
assert!(moo![f32: 0..4].dot([1.2; 4].moo_ref()) - 7.2 < 0.000003)

Dot product for two complex vectors using blas. There is no rust backend for complex dot products at the moment.

Vector dot product.

This can be called on any StaticVec, by calling StaticVec::moo_ref on it first.

Example
use slas::prelude::*;

// There is some inaccuracy due to float rounding.
assert!(moo![f32: 0..4].dot([1.2; 4].moo_ref()) - 7.2 < 0.000003)

Normalize vector. Uses rust by default, as Normalize is not implemented for blas yet.

Returns norm of vector. Uses rust by default, as Normalize is not implemented for blas yet.

Change type of elements. Can for example be used to convert between regular and fast floats.

Methods from Deref<Target = [T; LEN]>

Returns a slice containing the entire array. Equivalent to &s[..].

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

Example
#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element mutably and returns an array of mutable references with the same size as self.

Example
#![feature(array_methods)]

let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
🔬 This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
🔬 This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
🔬 This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
🔬 This is a nightly-only experimental API. (split_array)

Divides one mutable array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Return pointer to first element. Read more

Return mutable pointer to first element. Read more

Return a reference to self with the type of StaticVecUnion

Return a mutable reference to self with the type of StaticVecUnion. If you want to write to a StaticVec, this is the method that should be used. This method is re-implemented for StaticCowVecs, so it perserves cow behavior even when cows are borrowed as StaticVec’s. Read more

Return a cow vector containing a reference to self.

Indexing without bounds checking. Read more

Same as Self::get_unchecked but mutable. Read more

Returns a static slice spanning from index i to i+SLEN. Read more

Returns a mutable static slice spanning from index i to i+SLEN. Read more

Copies self into a StaticVecUnion.

Statically use B as a backend for self.

Example Read more

Return pointer to first element. Read more

Return mutable pointer to first element. Read more

Return a reference to self with the type of StaticVecUnion

Return a mutable reference to self with the type of StaticVecUnion. If you want to write to a StaticVec, this is the method that should be used. This method is re-implemented for StaticCowVecs, so it perserves cow behavior even when cows are borrowed as StaticVec’s. Read more

Return a cow vector containing a reference to self.

Indexing without bounds checking. Read more

Same as Self::get_unchecked but mutable. Read more

Returns a static slice spanning from index i to i+SLEN. Read more

Returns a mutable static slice spanning from index i to i+SLEN. Read more

Copies self into a StaticVecUnion.

Statically use B as a backend for self.

Example Read more

For StaticCowVec calling as_mut_ptr will dereference self and thereby copy the contents of self.borrowed into self, if self is borrowed.

For StaticCowVec calling mut_moo_ref will dereference self and thereby copy the contents of self.borrowed into self, if self is borrowed.

Return pointer to first element. Read more

Return a reference to self with the type of StaticVecUnion

Return a cow vector containing a reference to self.

Indexing without bounds checking. Read more

Same as Self::get_unchecked but mutable. Read more

Returns a static slice spanning from index i to i+SLEN. Read more

Returns a mutable static slice spanning from index i to i+SLEN. Read more

Copies self into a StaticVecUnion.

Statically use B as a backend for self.

Example Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.