Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2014 15:35
Show Gist options
  • Save anonymous/9569105 to your computer and use it in GitHub Desktop.
Save anonymous/9569105 to your computer and use it in GitHub Desktop.
import java.util.Random;
import org.ejml.simple.SimpleMatrix;
public class EJMLTest {
private static SimpleMatrix getRandomMatrix(int rowCount, int columnCount) {
Random random = new Random();
int cellValueLimit = 9;
SimpleMatrix matrix = new SimpleMatrix(rowCount, rowCount);
for (int r = 0; r < rowCount; r++) {
for (int c = 0; c < columnCount; c++) {
matrix.set(r, c, random.nextInt(cellValueLimit));
}
}
return matrix;
}
public static void main(String[] args) {
int rows = 300;
int cols = rows;
SimpleMatrix matrix1 = getRandomMatrix(rows, cols);
SimpleMatrix matrix2 = getRandomMatrix(rows, cols);
long computationStartTime = System.currentTimeMillis();
SimpleMatrix multipliedMatrix = matrix1.mult(matrix2);
long computationEndTime = System.currentTimeMillis();
System.out.println(new StringBuilder("Multiplication took ").append(computationEndTime - computationStartTime).append(" ms"));
System.out.println(multipliedMatrix.determinant());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment