My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

Latest available release: la4j-0.2.0.zip (api + src) (Nov 2011);

News

14 Nov 2011

I've just published awesome article about la4j at CodeProject.com. Enjoy reading!

13 Nov 2011

Hey! la4j-0.2.0 just released. Here is changelog:

  • ~55 classes, ~6700 loc, ~90 tests, ~50 kb (bin);
  • new package la4j.io for reading/writing matrices in MatrixMarket format;
  • matrices decomposition (LU, QR, Cholesky, SVD, Eigenvalues) support;
  • matrix inversion support;
  • sparse (CSR) and dense matrices and vectors support;
  • matrices and vectors can be serialized;
  • la4j uses Maven and jUnit now;
Full changelog

9 Sep 2011

I've just started new blog of project - la4j development. I am planing write there some technical staff about implementation details.

26 Jan 2011

I am working on integration la4j into jmatbench project.


Linear Algebra for Java (la4j)

la4j (Linear Algebra for Java) - is a elegant and pure Java library for solving problems of linear algebra. It is support sparse and dense matrices and vectors. la4j - is a try to design nice object oriented implementation of linear math library.

Features

  • single-threaded;
  • uniform interpretation of vectors and matrices;
  • sparse (CSR) and dense (2d array) matrices and vectors support;
  • linear systems solving (Gaussian, Jacobi, Zeidel, Square Root, Sweep and other);
  • matrices decomposition (Eigenvalues, SVD, QR, LU, Cholesky and other);
  • inverted matrices foundation;
  • MatrixMarket output format support;

List of projects uses la4j

Here could be Your project :) Use issue 12 for submitting.

Downloads

You can download latest version of la4j from here:

Contribution

You can contribute to la4j by following:

  • submit a bug/feature request here;
  • send patch/feedback to author through email (vladimir dot kostukov at Gmail);
  • send reference to your project where you use la4j;
  • donate here;


Code samples

See jUnit tests package for more examples.

Factories

Factory denseFactory = new DenseFactory();
Factory sparseFactory = new SparseFactory();

double array[][] = new double[][] { 
    {1.0, 0.0, 0.0}, 
    {0.0, 5.0, 0.0}, 
    {0.0, 0.0, 9.0} 
};
		
Matrix a = sparseFactory.createMatrix(array);
Matrix b = denseFactory.createMatrix(array);

Matrix c = a.copy(denseFactory); // convert sparse to dense
Matrix d = b.copy(sparseFactory); // convert dense to sparse

Basic operations

Matrix a = sparseFactory.createMatrix(array);
Matrix b = denseFactory.createMatrix(array);
		
Matrix c = a.multiply(b); // c - is sparse matrix
Matrix d = a.multiply(b, denseFactory); // d - is dense matrix

Matrix e = c.add(d).subtract(a).multiply(100); // c + d - a * 100

Transposing and trace

Matrix a = sparseFactory.createMatrix(array);
Matrix b = denseFactory.createMatrix(array);

double trace = a.trace();

Matrix c = a.transpose(); // c - is sparse matrix
Matrix d = a.transpose(denseFactory); // d - is dense matrix

Rows and columns

Matrix a = sparseFactory.createMatrix(array);

int rows = a.rows();
int columns = a.columns();

a.setColumns(columns + 1); // set number of columns
a.setRows(rows + 1); // set number of rows

b.resize(rows + 1, columns + 1); // resize matrix

a.swapColumns(0, columns - 1); // swap columns
a.swapRows(0, rows - 1); // swap rows

Vector row = a.getRow(0); // row - is sparse vector
Vector column = a.getColumn(0); // column is sparse vector

Triangles matrices

Matrix a = denseFactory.createMatrix(array);

boolean check = a.isTrianle(); // true if a - is triangle matrix

Matrix b = a.triangularize(); // b - is triangle dense matrix
Matrix c = a.triangularize(sparseFactory); // c - is triangle sparse matrix

Solving linear systems

Matrix a = denseFactory.createMatrix(array);
Vector b = sparseFactory.createVector(array[0]);

LinearSystem system = new LinearSystem(a, b);

Vector x = system.solve(new GaussianSolver()); // x - is dense vector

Vector y = system.solve(new SquareRootSolver(), sparseFactory); // y - is sparse vector

Matrix inversion

Matrix a = denseFactory.createMatrix(array);

Matrix b = a.inverse(new GaussianInvertor()); // b - is dense matrix
Matrix c = a.inverse(new GaussianInvertor(), sparseFactory); // c - is sparse matrix

Matrix decomposition

Matrix a = denseFactory.createMatrix(array);

Matrix[] qr = a.decompose(new QRDecompositor()); // qr[0] = Q, qr[1] = R; Q,R - dense matrices

Matrix[] lu = a.decompose(new LUDecompositor(), sparseFactory); // lu[0] = L, lu[1] = U; L,U - sparse matrices

Input/Output

Matrix a = denseFactory.createMatrix(array);

ObjectOutput mmos = new MMOutputStream(new FileOutputStream("file.mm"));
mmos.writeObject(a);
mmos.close();
		
ObjectInput mmis = new MMInputStream(new FileInputStream("file.mm"));
Matrix b = (Matrix) mmis.readObject();
mis.close();
Powered by Google Project Hosting