Skip to content

Latest commit

 

History

History
281 lines (124 loc) · 3.8 KB

File metadata and controls

281 lines (124 loc) · 3.8 KB

Home > @josh-brown/vector > SparseVector

SparseVector class

Implements Vector as a map of indices to nonzero values.

Signature:

export declare abstract class SparseVector<S = number> implements Vector<S> 

Implements: Vector<S>

Remarks

For large vectors with many entries equal to 0, some operations are more efficient with a Vector implementation that only stores the non-zero values.

Subclasses must specify the usual scalar operations on their contents.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the SparseVector class.

Methods

Method

Modifiers

Description

add(other)

Implements vector addition

builder()

abstract

combine(other, combineEntries)

Returns the dimension of the vector

equals(other)

Tests if two vectors are equal

forEach(callback)

Returns the dimension of the vector

getDimension()

Returns the dimension of the vector

getEntry(index)

Returns the entry of the matrix located at the provided index (index)

getSparseData()

Returns the contents of the vector as a map of indices to nonzero values

innerProduct(other)

Implements the inner product (scalar product or dot product) of two vectors

map(valueFromEntry)

Returns the dimension of the vector

matrixBuilder()

abstract

ops()

abstract

outerProduct(other)

Implements the outer product (matrix product) of two vectors

projectOnto(u)

Returns a new vector in the direction of u but with magnitude equal to the amount of the original vector that lies in that direction

scalarMultiply(scalar)

Implements vector multiplication by a scalar

set(index, value)

Returns a new vector equal to the old one, except with the entry at index replaced with value

toArray()

Returns the contents of the vector as an array