Sparse matrix functionality in VectorZ
Code: "SparseMatrix.java". Programming language: Java
DMelt Version 2.3. Last modified: 11/26/1972. License: Pro
https://datamelt.org/code/cache/SparseMatrix_4584.java
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
import mikera.indexz.Index;
import mikera.indexz.Indexz;
import mikera.matrixx.AMatrix;
import mikera.matrixx.Matrixx;
import mikera.matrixx.Matrix;
import mikera.matrixx.impl.SparseRowMatrix;
import mikera.util.Rand;
import mikera.vectorz.AVector;
import mikera.vectorz.impl.RepeatedElementVector;
import mikera.vectorz.impl.SparseIndexedVector;
/**
* Demonstration class showing usage of sparse matrix functionality.
*
* @author Mike
*
*/
public class SparseMatrix {
private static int SIZE=32000; // size of large NxN matrix
private static int DSIZE=100; // dense elements per row in large matrix
private static int CSIZE=200; // dense elements per row for target matrix
private static int SSIZE=2000; // size of smaller NxN matrix
private static long start=0;
private static void printTime(String msg) {
long now=System.currentTimeMillis();
System.out.println(msg+(now-start)+"ms");
startTimer();
}
private static void startTimer() {
start=System.currentTimeMillis();
}
public static void main(String[] args) {
// We want a SparseRowMatrix, because we are going to multiply it with a second dense matrix
// This means that a row-oriented sparse format is better for the first matrix
SparseRowMatrix m=SparseRowMatrix.create(SIZE,SIZE);
// First task is to construct the large sparse matrix
startTimer();
for (int i=0; i
You see the box below because you did not login.