java.lang.Object
org.flag4j.linalg.ops.sparse.coo.CooDataSorter<T>
A class which can be used to sort the indices, along with data values, in lexicographical order.
This class is not thread safe.
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
ModifierConstructorDescriptionCreates a sorter which can sort the indices and values of a COO matrix lexicographically.private
CooDataSorter
(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 CooDataSorter
wrap
(double[] values, int[] indices) Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.static CooDataSorter
wrap
(double[] values, int[][] indices) Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.static CooDataSorter
wrap
(double[] values, int[] rowIndices, int[] colIndices) Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.static CooDataSorter
Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.static CooDataSorter
Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.static CooDataSorter
Factory method which wraps data in an instance ofCooDataSorter
and returns that instance.
-
Field Details
-
values
-
keys
-
-
Constructor Details
-
CooDataSorter
Creates a sorter which can sort the indices and values of a COO matrix lexicographically.
When
sparseSort()
is called on an instance created with this constructor, the sorting will be done in place.- Parameters:
values
- Non-zero values of the sparse COO matrix.rowIndices
- Row indices of the sparse COO matrix.colIndices
- Row indices of the sparse COO matrix.
-
CooDataSorter
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 ofCooDataSorter
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
CooDataSorter
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofCooDataSorter
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
CooDataSorter
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofCooDataSorter
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
CooDataSorter
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofCooDataSorter
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
CooDataSorter
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofCooDataSorter
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
CooDataSorter
which wraps the specifiedvalues
andindices
.
-
wrap
Factory method which wraps data in an instance ofCooDataSorter
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
CooDataSorter
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.
-