Package org.flag4j.operations.sparse.coo
Class SparseDataWrapper<T>
java.lang.Object
org.flag4j.operations.sparse.coo.SparseDataWrapper<T>
- Type Parameters:
T
- Type of the individual entry within the sparse tensor.
A wrapper to wrap the entries and indices from a sparse tensor, vector, or matrix. This wrapper can then be used to sort the indices, along with data values, in lexicographical order.
Specifically, if a sparse tensor has shape (10, 15, 5, 2) and the following indices and non-zero values,
- Indices: {{4, 1, 2, 0}, {4, 0, 1, 2}, {1, 2, 3, 0}, {2, 3, 5, 1}, {9, 10, 4, 1}, {1, 2, 1, 1}} - Values: {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}then the sorted indices and non-zero values will be,
- Indices: {{1, 2, 1, 1}, {1, 2, 3, 0}, {2, 3, 5, 1}, {4, 0, 1, 2}, {4, 1, 2, 0}, {9, 10, 4, 1}} - Values: {6.6, 3.3, 4.4, 2.2, 1.1, 5.5}
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprivate
SparseDataWrapper
(T[] values, int[][] indices, boolean transpose) Wraps the data, and it's associated indices, of a sparse tensor. -
Method Summary
Modifier and TypeMethodDescriptionSorts the wrapped indices in lexicographical order while maintaining the order of the non-zero values so that their order matches the order of the indices.private void
sparseSortHelper
(int keyIdx, int start, int stop) Sorts the specified key list over a specified range.void
unwrap
(double[] values, int[] indices) Unwraps sparse data values and indices.void
unwrap
(double[] values, int[][] indices) Unwraps sparse data values and indices.void
unwrap
(double[] values, int[] rowIndices, int[] colIndices) Unwraps sparse data values and indices.void
Unwraps sparse data values and indices.void
Unwraps sparse data values and indices.void
Unwraps sparse data values and indices.static SparseDataWrapper
<Double> wrap
(double[] values, int[] indices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.static SparseDataWrapper
<Double> wrap
(double[] values, int[][] indices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.static SparseDataWrapper
<Double> wrap
(double[] values, int[] rowIndices, int[] colIndices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.static <T extends Number>
SparseDataWrapper<T> wrap
(T[] values, int[] indices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.static <T extends Number>
SparseDataWrapper<T> wrap
(T[] values, int[][] indices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.static <T extends Number>
SparseDataWrapper<T> wrap
(T[] values, int[] rowIndices, int[] colIndices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.
-
Field Details
-
values
-
keys
-
-
Constructor Details
-
SparseDataWrapper
Wraps the data, and it's associated indices, of a sparse tensor.- Parameters:
values
- Non-zero values of the sparse tensor.indices
- Indices of non-zero values in the sparse tensor.transpose
- Indicates if a transpose should be applied to the indices array.
-
-
Method Details
-
wrap
Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Type Parameters:
T
- Type of the individual entry withinvalues
.- Parameters:
values
- Non-zero values of the sparse tensor.indices
- Indices of non-zero values in the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Type Parameters:
T
- Type of the individual entry withinvalues
.- Parameters:
values
- Non-zero values of the sparse tensor.indices
- Indices of non-zero values in the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Parameters:
values
- Non-zero values of the sparse tensor.indices
- Indices of non-zero values in the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Parameters:
values
- Non-zero values of the sparse tensor.indices
- Indices of non-zero values in the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Parameters:
values
- Non-zero values of the sparse tensor.rowIndices
- Row indices of non-zero entries of the sparse tensor.colIndices
- Column indices of non-zero entries of the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
wrap
public static <T extends Number> SparseDataWrapper<T> wrap(T[] values, int[] rowIndices, int[] colIndices) Factory method which wraps data in an instance ofSparseDataWrapper
and returns that instance.- Parameters:
values
- Non-zero values of the sparse tensor.rowIndices
- Row indices of non-zero entries of the sparse tensor.colIndices
- Column indices of non-zero entries of the sparse tensor.- Returns:
- A new instance of
SparseDataWrapper
which wraps the specifiedvalues
andindices
.
-
sparseSort
Sorts the wrapped indices in lexicographical order while maintaining the order of the non-zero values so that their order matches the order of the indices.- Returns:
- A reference to this sparse data wrapper.
-
sparseSortHelper
private void sparseSortHelper(int keyIdx, int start, int stop) Sorts the specified key list over a specified range. During sorting, when swaps are made in the key list, the same indices are swapped in all other lists within the wrapper. This is done recursively top down.- Parameters:
keyIdx
- Index of key list withinkeys
.start
- Staring index of range to sort the key list over (inclusive).stop
- Stopping index of range to sort the key list over (exclusive).
-
unwrap
Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.indices
- Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
-
unwrap
Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.indices
- Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
-
unwrap
public void unwrap(double[] values, int[][] indices) Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.indices
- Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
-
unwrap
public void unwrap(double[] values, int[] rowIndices, int[] colIndices) Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.rowIndices
- Storage for unwrapped row indices. Must have the same shape as that passed to the constructor. Modified.colIndices
- Storage for unwrapped column indices. Must have the same shape as that passed to the constructor. Modified.
-
unwrap
Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.rowIndices
- Storage for unwrapped row indices. Must have the same shape as that passed to the constructor. Modified.colIndices
- Storage for unwrapped column indices. Must have the same shape as that passed to the constructor. Modified.
-
unwrap
public void unwrap(double[] values, int[] indices) Unwraps sparse data values and indices.- Parameters:
values
- Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.indices
- Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
-