Documentation ¶
Index ¶
- Variables
- func Filter[T any](slice []T, pred func(T) bool) []T
- func NilIfEmpty[T any](slice []T) []T
- func VecDot(v1, v2 *Vector) float64
- type CSCEntriesSort
- type CSCMatrix
- type CSMatrix
- func (m *CSMatrix) Dim() (int, error)
- func (m *CSMatrix) Merge(m2 *CSMatrix)
- func (m *CSMatrix) Mmap(ctx context.Context) error
- func (m *CSMatrix) Munmap() error
- func (m *CSMatrix) NNZ() (nnz int)
- func (m *CSMatrix) Reset()
- func (m *CSMatrix) SetMajorDim(dim int)
- func (m *CSMatrix) SetMinorDim(dim int)
- func (m *CSMatrix) Transpose(ctx context.Context) (*CSMatrix, error)
- type CSREntriesSort
- type CSRMatrix
- func (m *CSRMatrix) Dims() (rows, cols int)
- func (m *CSRMatrix) RowVector(index int) *Vector
- func (m *CSRMatrix) SetDim(rows, cols int)
- func (m *CSRMatrix) SetRowVector(index int, vector *Vector)
- func (m *CSRMatrix) Transpose(ctx context.Context) (*CSRMatrix, error)
- func (m *CSRMatrix) TransposeToCSC() *CSCMatrix
- type CooEntry
- type EntriesByIndex
- type EntriesByValue
- type Entry
- type KBNSummer
- type Matrix
- type Vector
- func (v *Vector) AddVec(v1, v2 *Vector) error
- func (v *Vector) Assign(v1 *Vector)
- func (v *Vector) Clone() *Vector
- func (v *Vector) Merge(v2 *Vector)
- func (v *Vector) MulVec(ctx context.Context, m *Matrix, v1 *Vector) error
- func (v *Vector) NNZ() int
- func (v *Vector) Norm2() float64
- func (v *Vector) Reset()
- func (v *Vector) ScaleVec(a float64, v1 *Vector)
- func (v *Vector) SetDim(dim int)
- func (v *Vector) SubVec(v1, v2 *Vector) error
- func (v *Vector) Sum() float64
Constants ¶
This section is empty.
Variables ¶
var ErrDimensionMismatch = errors.New("dimension mismatch")
ErrDimensionMismatch signals a dimension mismatch between related data structures, ex: a local trust matrix and a pre-trust vector.
var ErrZeroSum = errors.New("zero sum")
ErrZeroSum signals that an input vector's components sum to zero.
Functions ¶
func NilIfEmpty ¶
func NilIfEmpty[T any](slice []T) []T
NilIfEmpty returns the given slice, except if empty, it returns nil.
Types ¶
type CSCEntriesSort ¶
type CSCEntriesSort []CooEntry
CSCEntriesSort sorts CooEntry objects by (column, row) key.
func (CSCEntriesSort) Len ¶
func (a CSCEntriesSort) Len() int
func (CSCEntriesSort) Less ¶
func (a CSCEntriesSort) Less(i, j int) bool
func (CSCEntriesSort) Swap ¶
func (a CSCEntriesSort) Swap(i, j int)
type CSCMatrix ¶
type CSCMatrix struct {
CSMatrix
}
CSCMatrix is a compressed sparse column matrix.
func (*CSCMatrix) ColumnVector ¶
ColumnVector returns the given row as a sparse vector. The returned vector shares the same entry objects.
func (*CSCMatrix) SetDim ¶
SetDim grows/shrinks the receiver in-place, so it contains the specified number of rows/columns.
func (*CSCMatrix) TransposeToCSR ¶
TransposeToCSR transposes the matrix. The returned matrix shares the same entry objects.
type CSMatrix ¶
type CSMatrix struct {
MajorDim, MinorDim int
Entries [][]Entry
// contains filtered or unexported fields
}
CSMatrix is a compressed sparse matrix. Used as the base of CSRMatrix and CSCMatrix.
(Shallow-)copying CSMatrix is lightweight.
func (*CSMatrix) Merge ¶
Merge merges the given matrix (m2) into the receiver.
If both m and m2 contain an entry at the same location, m2's entry wins.
m2 is reset after merge.
func (*CSMatrix) Mmap ¶
Mmap swaps out contents onto a temp file and mmap-s it, freeing core memory.
If the receiver (m) is Mmap()-ed, future operations on it that replaces its major spans will not automatically map the replaced major spans. If needed, Mmap() can be called again on the same receiver in order to refresh the mapping and ensure that the entirety of the receiver's contents is swapped out. (In this case, Munmap() need not be called first.)
func (*CSMatrix) SetMajorDim ¶
SetMajorDim grows/shrinks the receiver in-place, so it matches the given major dimension.
func (*CSMatrix) SetMinorDim ¶
SetMinorDim grows/shrinks the receiver in-place, so it matches the given minor dimension.
type CSREntriesSort ¶
type CSREntriesSort []CooEntry
CSREntriesSort sorts CooEntry objects by (row, column) key.
func (CSREntriesSort) Len ¶
func (a CSREntriesSort) Len() int
func (CSREntriesSort) Less ¶
func (a CSREntriesSort) Less(i, j int) bool
func (CSREntriesSort) Swap ¶
func (a CSREntriesSort) Swap(i, j int)
type CSRMatrix ¶
type CSRMatrix struct {
CSMatrix
}
CSRMatrix is a compressed sparse row matrix.
func NewCSRMatrix ¶
NewCSRMatrix creates a new compressed sparse row matrix with the given dimension and entries.
The given entries are sorted in row-column order.
func (*CSRMatrix) RowVector ¶
RowVector returns the given row as a sparse vector. The returned vector shares the same slice of entry objects.
func (*CSRMatrix) SetDim ¶
SetDim grows/shrinks the receiver in-place, so it contains the specified number of rows/columns.
func (*CSRMatrix) SetRowVector ¶
SetRowVector replaces the given row. The receiver shares the same slice of entry objects.
func (*CSRMatrix) TransposeToCSC ¶
TransposeToCSC transposes the matrix. The returned matrix shares the same entry objects.
type CooEntry ¶
CooEntry is a sparse matrix coordinate-format ("Coo") entry. Used as an input to a sparse matrix builder.
type EntriesByIndex ¶
type EntriesByIndex []Entry
func (EntriesByIndex) Len ¶
func (a EntriesByIndex) Len() int
func (EntriesByIndex) Less ¶
func (a EntriesByIndex) Less(i, j int) bool
func (EntriesByIndex) Swap ¶
func (a EntriesByIndex) Swap(i, j int)
type EntriesByValue ¶
type EntriesByValue []Entry
func (EntriesByValue) Len ¶
func (a EntriesByValue) Len() int
func (EntriesByValue) Less ¶
func (a EntriesByValue) Less(i, j int) bool
func (EntriesByValue) Swap ¶
func (a EntriesByValue) Swap(i, j int)
type Entry ¶
type Entry struct { // Index is the index of the entry. // Context decides the meaning: For example, it is a column index when used // as a compressed sparse row (CSR) matrix. Index int // Value is the entry value. For sparse use, it should be nonzero. Value float64 }
Entry is an entry in a sparse vector or matrix.
func SortEntriesByIndex ¶
func SortEntriesByValue ¶
type KBNSummer ¶
type KBNSummer struct {
// contains filtered or unexported fields
}
KBNSummer is the Kahan-Babushka-Neumaier compensated summation algorithm.
type Matrix ¶
type Matrix = CSRMatrix
Matrix is just an alias of CSRMatrix, which is the more popular of the two compressed sparse variants.
type Vector ¶
type Vector struct { // Dim is the dimension of the vector. Dim int // Entries contain sparse entries, sorted by their Entry.Index. // For each Entry in Entries, 0 <= Entry.Index < Dim holds. Entries []Entry }
Vector is a sparse vector.
func (*Vector) Merge ¶
Merge merges the given vector (v2) into the receiver.
If both v and v2 contain an entry at the same location, v2's entry wins.
v2 is reset after merge.