pub struct VecKind {}
Expand description
Arrays backed by a Vec<T>
.
Trait Implementations§
Source§impl<T: Clone> Array<VecKind, T> for VecArray<T>
impl<T: Clone> Array<VecKind, T> for VecArray<T>
Source§fn get_range<R: RangeBounds<usize>>(&self, rb: R) -> &[T]
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>
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 concatenate(&self, other: &Self) -> Self
fn concatenate(&self, other: &Self) -> Self
Concatenate two arrays
Source§fn fill(x: T, n: usize) -> Self
fn fill(x: T, n: usize) -> Self
fill(x, n)
returns the array length n containing repeated element x.Source§fn set_range<R: RangeBounds<usize>>(
&mut self,
rb: R,
v: &<VecKind as ArrayKind>::Type<T>,
)
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
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
fn from_slice(slice: &[T]) -> Self
Source§fn scatter_assign_constant(&mut self, ixs: &VecArray<usize>, arg: T)
fn scatter_assign_constant(&mut self, ixs: &VecArray<usize>, arg: T)
Numpy
self[ixs] = arg
fn scatter_assign(&mut self, ixs: &<VecKind as ArrayKind>::Index, values: Self)
Source§impl ArrayKind for VecKind
impl ArrayKind for VecKind
Source§impl NaturalArray<VecKind> for VecArray<usize>
impl NaturalArray<VecKind> for VecArray<usize>
Source§fn quot_rem(&self, d: usize) -> (Self, Self)
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
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>
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);
fn max(&self) -> Option<usize>
Source§fn mul_constant_add(&self, c: usize, x: &Self) -> Self
fn mul_constant_add(&self, c: usize, x: &Self) -> Self
Source§fn connected_components(
sources: &Self,
targets: &Self,
n: usize,
) -> (Self, <VecKind as ArrayKind>::I)
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 moreSource§fn bincount(&self, size: usize) -> VecArray<usize>
fn bincount(&self, size: usize) -> VecArray<usize>
Count occurrences of each value in the range [0, size)
Source§fn sparse_bincount(&self) -> (VecArray<usize>, VecArray<usize>)
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>)
fn scatter_sub_assign(&mut self, ixs: &VecArray<usize>, rhs: &VecArray<usize>)
Compute
self[ixs] -= rhs
fn sum(&self) -> K::I
Source§fn segmented_sum(&self, x: &Self) -> Self
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 moreSource§fn segmented_arange(&self) -> Self
fn segmented_arange(&self) -> Self
Given an array of sizes compute the concatenation of
arange
arrays of each size. Read moreSource§impl<T: Ord + Clone> OrdArray<VecKind, T> for VecArray<T>
impl<T: Ord + Clone> OrdArray<VecKind, T> for VecArray<T>
Source§fn argsort(&self) -> VecArray<usize>
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§impl<O: Clone + PartialEq, A: Clone + PartialEq> Spider<VecKind> for OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone + PartialEq> Spider<VecKind> for OpenHypergraph<O, A>
Source§fn dagger(&self) -> Self
fn dagger(&self) -> Self
Given an
Arrow
with type f : A → B
,
construct its dagger f† : B → A
by using Hypergraph structure to bend sources to targets and vice-versa.Source§fn spider(
s: FiniteFunction<VecKind>,
t: FiniteFunction<VecKind>,
w: Self::Object,
) -> Option<Self>
fn spider( s: FiniteFunction<VecKind>, t: FiniteFunction<VecKind>, w: Self::Object, ) -> Option<Self>
Construct a spider using a type
w
, and source s
and target t
interface maps.Source§fn half_spider(s: FiniteFunction<K>, w: Self::Object) -> Option<Self>
fn half_spider(s: FiniteFunction<K>, w: Self::Object) -> Option<Self>
Construct a “half-spider”: a spider whose
t
leg is identity.impl Eq for VecKind
impl StructuralPartialEq for VecKind
Auto Trait Implementations§
impl Freeze for VecKind
impl RefUnwindSafe for VecKind
impl Send for VecKind
impl Sync for VecKind
impl Unpin for VecKind
impl UnwindSafe for VecKind
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
Mutably borrows from an owned value. Read more