Vector class abstract

An algebraic vector with SIMD (single instruction, multiple data) architecture support and extended functionality, adapted for data science applications

The vector's components are represented by special data type, that allows to perform vector operations extremely fast due to hardware assisted computations.

Implemented types
Available Extensions

Constructors

Vector.empty({DType dtype = DType.float32})
Creates a vector of zero length
factory
Vector.filled(int length, num value, {DType dtype = DType.float32})
Creates a vector of length equal to length filled with value.
factory
Vector.fromJson(Map<String, dynamic> json)
factory
Vector.fromList(List<num> source, {DType dtype = DType.float32})
Creates a vector from a source.
factory
Vector.fromSimdList(List source, int actualLength, {DType dtype = DType.float32})
Creates a vector from a simd-typed collection. It accepts only Float32x4List or Float64x2List lists as a source.
factory
Vector.randomFilled(int length, {int? seed, num min = 0, num max = 1, DType dtype = DType.float32})
Creates a vector of length equal to length, filled with random values within the range min (inclusive) - max (exclusive). If min greater than or equal to max - an argument error will be thrown. The random values are generated by Random class instance, that is created with a seed value equals seed
factory
Vector.zero(int length, {DType dtype = DType.float32})
Creates a vector filled with zeroes with length equal to length.
factory

Properties

dtype DType
Denotes a data type, used for representation of the vector's elements
no setter
first double
The first element.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<double>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last double
The last element.
no setterinherited
length int
The number of elements in this.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single double
Checks that this iterable has only one element, and returns that element.
no setterinherited

Methods

abs({bool skipCaching = false}) Vector
Returns a new vector where the elements are absolute values of the original vector's elements
any(bool test(double element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
distanceTo(Vector vector, {Distance distance = Distance.euclidean}) double
Returns a distance between this and vector
dot(Vector vector) double
Returns a dot (inner) product of this and vector
elementAt(int index) double
Returns the indexth element.
inherited
every(bool test(double element)) bool
Checks whether every element of this iterable satisfies test.
inherited
exp({bool skipCaching = false}) Vector
Creates a new Vector composed of Euler's numbers raised to powers which are the elements of this Vector
expand<T>(Iterable<T> toElements(double element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
fastMap<T>(T mapper(T element)) Vector
Returns a new vector from mapped elements of the original vector. Mapping function mapper should accept argument only of Float32x4 or Float64x2 data type (depends on dtype value, e.g. if dtype equals DType.float32 - the argument should be of Float32x4 type). The data types mentioned above allow to perform mapping much faster than the regular map method
filterElements(bool predicate(double element, int idx)) Vector
Returns a new vector consisting of filtered elements of the original vector
firstWhere(bool test(double element), {double orElse()?}) double
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, double element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<double> other) Iterable<double>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(double element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getCosine(Vector other) double
Returns cosine of the angle between this and other vector
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(double element), {double orElse()?}) double
The last element that satisfies the given predicate test.
inherited
log({bool skipCaching = false}) Vector
Creates a new Vector by taking natural log of each element of the source vector
map<T>(T toElement(double e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
mapToVector(double mapper(double value)) Vector
Creates a new vector applying mapper to each element of this Vector
max({bool skipCaching = false}) double
Returns maximum element among all vector elements
mean({bool skipCaching = false}) double
Returns the mean value of this vector
median({bool skipCaching = false}) double
Returns the median value of this vector
min({bool skipCaching = false}) double
Returns minimum element among all vector elements
norm([Norm norm = Norm.euclidean, bool skipCaching = false]) double
Calculates vector norm (magnitude)
normalize([Norm norm = Norm.euclidean, bool skipCaching = false]) Vector
Returns a new vector with normalized values of this vector
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(num exponent) Vector
Creates a new Vector composed of elements of this Vector raised to the exponent. Avoid raising a vector to a float power, since it is a slow operation
prod() double
Returns the product of all the vector's elements
reduce(double combine(double value, double element)) double
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
rescale({bool skipCaching = false}) Vector
Returns rescaled (min-max normed) version of this vector
sample(Iterable<int> indices) Vector
Returns a new vector composed of elements which are located on the passed indexes
scalarDiv(num scalar) Vector
Returns a new Vector where elements are the elements from this Vector divided by scalar
set(int index, num value) Vector
Copies the vector, sets the value by the index and returns the vector
singleWhere(bool test(double element), {double orElse()?}) double
The single element that satisfies test.
inherited
skip(int count) Iterable<double>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(double value)) Iterable<double>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
sqrt({bool skipCaching = false}) Vector
Returns a new Vector consisting of square roots of elements of this Vector
subvector(int start, [int? end]) Vector
Returns a new vector composed of values whose indices are within the range start (inclusive) - end (exclusive)
sum({bool skipCaching = false}) double
Returns the sum of all vector elements
take(int count) Iterable<double>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(double value)) Iterable<double>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toJson() Map<String, dynamic>
Returns a json-serializable map
toList({bool growable = true}) List<double>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<double>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
A string representation of this object.
inherited
unique({bool skipCaching = false}) Vector
Returns a new vector composed of the vector's unique elements
where(bool test(double element)) Iterable<double>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator *(Object value) Vector
Element-wise multiplication
operator +(Object value) Vector
Element-wise addition
operator -(Object value) Vector
Element-wise subtraction
operator /(Object value) Vector
Element-wise division
operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) double
Returns an element by its index in the vector