Struct VecKind

Source
pub struct VecKind {}
Expand description

Arrays backed by a Vec<T>.

Trait Implementations§

Source§

impl<T: Clone + PartialEq> Array<VecKind, T> for VecArray<T>

Source§

fn get_range<R: RangeBounds<usize>>(&self, rb: R) -> &[T]

Get a contiguous subrange of the array

use open_hypergraphs::array::{*, vec::*};
let v = VecArray(vec![0, 1, 2, 3, 4]);
assert_eq!(v.get_range(..), &[0, 1, 2, 3, 4]);
assert_eq!(v.get_range(..v.len()), &[0, 1, 2, 3, 4]);
Source§

fn scatter(&self, idx: &[usize], n: usize) -> VecArray<T>

Scatter values over the specified indices self[idx[i]] = v[i].

use open_hypergraphs::array::{*, vec::*};
let idx = VecArray(vec![2, 1, 0, 2]);
let v = VecArray(vec![0, 2, 1, 2]);

let expected = VecArray(vec![1, 2, 2]);

let actual = v.scatter(idx.get_range(..), 3);
assert_eq!(actual, expected);
Source§

fn empty() -> Self

The empty array
Source§

fn len(&self) -> usize

Length of an array
Source§

fn concatenate(&self, other: &Self) -> Self

Concatenate two arrays
Source§

fn fill(x: T, n: usize) -> Self

fill(x, n) returns the array length n containing repeated element x.
Source§

fn get(&self, i: usize) -> T

Retrieve a single element by its index.
Source§

fn set_range<R: RangeBounds<usize>>( &mut self, rb: R, v: &<VecKind as ArrayKind>::Type<T>, )

Write to a contiguous range of data in an array
Source§

fn gather(&self, idx: &[usize]) -> Self

Gather elements of this array according to the indices. https://en.wikipedia.org/wiki/Gather/scatter_(vector_addressing)#Gather Read more
Source§

fn from_slice(slice: &[T]) -> Self

Source§

fn scatter_assign_constant(&mut self, ixs: &VecArray<usize>, arg: T)

Numpy self[ixs] = arg
Source§

fn scatter_assign(&mut self, ixs: &<VecKind as ArrayKind>::Index, values: Self)

Source§

fn is_empty(&self) -> bool

Test if an array is empty
Source§

fn to_range<R: RangeBounds<K::I>>(&self, r: R) -> Range<K::I>

Clamp any R: RangeBounds<K::I> into the range of valid indices for this array.
Source§

impl ArrayKind for VecKind

Source§

type Type<T> = VecArray<T>

The type of arrays containing elements type T
Source§

type I = usize

The type of index elements. For super::vec::VecKind, this is usize.
Source§

type Index = VecArray<usize>

Arrays of indices (isomorphic to Type<I>) must implement NaturalArray
Source§

type Slice<'a, T: 'a> = &'a [T]

a Slice is a read-only view into another array’s data. For VecKind this is &[T].
Source§

impl AsMut<<VecKind as ArrayKind>::Index> for VecArray<usize>

Source§

fn as_mut(&mut self) -> &mut <VecKind as ArrayKind>::Index

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<<VecKind as ArrayKind>::Index> for VecArray<usize>

Source§

fn as_ref(&self) -> &<VecKind as ArrayKind>::Index

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for VecKind

Source§

fn clone(&self) -> VecKind

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 VecKind

Source§

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

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

impl NaturalArray<VecKind> for VecArray<usize>

Source§

fn quot_rem(&self, d: usize) -> (Self, Self)

let x = VecArray(vec![0, 1, 2, 3, 4, 5]);
let d = 3;
let expected_q = VecArray(vec![0, 0, 0, 1, 1, 1]);
let expected_r = VecArray(vec![0, 1, 2, 0, 1, 2]);
let (q, r) = x.quot_rem(d);
assert_eq!(expected_q, q);
assert_eq!(expected_r, r);
Source§

fn cumulative_sum(&self) -> Self

let input = VecArray(vec![1, 2, 3, 4]);
let expected = VecArray(vec![0, 1, 3, 6, 10]);

assert_eq!(input.cumulative_sum(), expected);
Source§

fn repeat(&self, x: &[usize]) -> VecArray<usize>

let repeats: VecArray<usize> = VecArray(vec![1, 2, 0, 3]);
let values: &[usize] = &[5, 6, 7, 8];
let actual = repeats.repeat(values);
let expected = VecArray::<usize>(vec![5, 6, 6, 8, 8, 8]);
assert_eq!(actual, expected);
Source§

fn max(&self) -> Option<usize>

Source§

fn mul_constant_add(&self, c: usize, x: &Self) -> Self

Compute self * c + x, where c is a constant (scalar) and x is an array. Read more
Source§

fn arange(start: &usize, stop: &usize) -> Self

Indices from start to stop Read more
Source§

fn connected_components( sources: &Self, targets: &Self, n: usize, ) -> (Self, <VecKind as ArrayKind>::I)

Compute the connected components of a graph with n nodes. Edges are stored as a pair of arrays of nodes (sources, targets) meaning that for each i there is an edge sources[i] → targets[i]. Read more
Source§

fn bincount(&self, size: usize) -> VecArray<usize>

Count occurrences of each value in the range [0, size)
Source§

fn zero(&self) -> VecArray<usize>

Return indices of elements which are zero
Source§

fn sparse_bincount(&self) -> (VecArray<usize>, VecArray<usize>)

Compute index of unique values and their counts
Source§

fn scatter_sub_assign(&mut self, ixs: &VecArray<usize>, rhs: &VecArray<usize>)

Compute self[ixs] -= rhs
Source§

fn sum(&self) -> K::I

Source§

fn segmented_sum(&self, x: &Self) -> Self

Segmented sum of input. For example, for self = [1 2 0], self.segmented_sum([1 | 2 3]) = [1 5 0]. Read more
Source§

fn segmented_arange(&self) -> Self

Given an array of sizes compute the concatenation of arange arrays of each size. Read more
Source§

impl<T: Ord + Clone> OrdArray<VecKind, T> for VecArray<T>

Source§

fn argsort(&self) -> VecArray<usize>

let values: VecArray<usize> = VecArray(vec![1, 2, 0, 3]);
let actual: VecArray<usize> = values.argsort();
let expected = VecArray::<usize>(vec![2, 0, 1, 3]);
assert_eq!(actual, expected);

// Check monotonicity
let monotonic = values.gather(actual.as_slice());
for i in 0..(monotonic.len()-1) {
    assert!(monotonic[i] <= monotonic[i+1]);
}
Source§

fn sort_by(&self, key: &Self) -> Self

Sort this array by the given keys Read more
Source§

impl PartialEq for VecKind

Source§

fn eq(&self, other: &VecKind) -> 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.
Source§

impl Eq for VecKind

Source§

impl StructuralPartialEq for VecKind

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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<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.