Class DenseSemiringConversions
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Semiring<T>>
SparseMatrixData<T> Converts a dense matrix to an equivalent sparse COO matrix.static <T extends Semiring<T>>
SparseMatrixData<T> Converts a dense matrix to an equivalent sparse COO matrix.static <T extends Semiring<T>>
SparseTensorData<T> toCooTensor
(Shape shape, T[] entries) Converts a dense tensor to an equivalent sparse COO tensor.static <T extends Semiring<T>>
SparseTensorData<T> toCooTensor
(Shape shape, T[] entries, double estimatedSparsity) Converts a dense tensor to an equivalent sparse COO tensor.
-
Method Details
-
toCoo
public static <T extends Semiring<T>> SparseMatrixData<T> toCoo(Shape shape, T[] entries, double estimatedSparsity) Converts a dense matrix to an equivalent sparse COO matrix.
This should only be done for matrices which are known to be sparse.
If no estimate is known, then using
toCoo(Shape, Semiring[])
will estimate the sparsity as 0.9.- Parameters:
shape
- Shape of the matrix.entries
- Entries of the matrix.estimatedSparsity
- Estimated sparsity of the matrix. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse COO matrix containing the non-zero values of the specified dense matrix.
-
toCoo
Converts a dense matrix to an equivalent sparse COO matrix.
This should only be done for matrices which are known to be sparse.
This method will estimate the sparsity of the matrix at 99%. If a more accurate estimation is known, providing it to
toCoo(Shape, Semiring[], double)
may provide a slight speedup or reduce excess memory consumption. If the sparsity is not known, it is recommended to simply use this method.- Parameters:
shape
- Shape of the matrix.entries
- Entries of the matrix.- Returns:
- A sparse COO matrix containing the non-zero values of the specified dense matrix.
- See Also:
-
toCooTensor
public static <T extends Semiring<T>> SparseTensorData<T> toCooTensor(Shape shape, T[] entries, double estimatedSparsity) Converts a dense tensor to an equivalent sparse COO tensor.
This should only be done for tensors which are known to be sparse.
If no estimate is known, then using
toCooTensor(Shape, Semiring[])
will estimate the sparsity as 0.9.- Parameters:
shape
- Shape of the tensor.entries
- Entries of the tensor.estimatedSparsity
- Estimated sparsity of the tensor. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse COO tensor containing the non-zero values of the specified dense tensor.
-
toCooTensor
Converts a dense tensor to an equivalent sparse COO tensor.
This should only be done for matrices which are known to be sparse.
This method will estimate the sparsity of the tensor at 99%. If a more accurate estimation is known, providing it to
toCoo(Shape, Semiring[], double)
may provide a slight speedup or reduce excess memory consumption. If the sparsity is not known, it is recommended to simply use this method.- Parameters:
shape
- Shape of the tensor.entries
- Entries of the tensor.- Returns:
- A sparse COO tensor containing the non-zero values of the specified dense tensor.
- See Also:
-