"""
<h1>Lightweight Java sparse/dense matrix library</h1>
      The <a href="http://la4j.org/">La4j</a>  is open source and 100% Java library that provides <a href="http://mathworld.wolfram.com/LinearAlgebra.html">Linear Algebra</a> primitives (matrices and vectors) and algorithms. The la4j was initially designed to be lightweight and simple tool for passionate Java developers. It has been started as student project and turned into one of the most popular Java packages for matrices and vectors.
"""


from org.la4j.matrix.dense import *
from org.la4j.matrix.sparse import *
from org.la4j.matrix import *
from org.la4j.matrix.functor import *
from org.la4j.vector.sparse  import *
from org.la4j.vector.dense  import *
from org.la4j import *

print "Create Dense matrix"
a=Basic2DMatrix.from2DArray([[1.0, 2.0, 3.0 ],
               [4.0, 5.0, 6.0],
               [7.0, 8.0, 9.0]])

print "Create Sparse matrix"
b=CRSMatrix.from2DArray( [[1.0, 2.0, 3.0 ],
                [4.0, 5.0, 6.0],
                [7.0, 8.0, 9.0]])

# define a function for this matrix
class myFunction(MatrixFunction):
    def evaluate(self, i,j,value):
               if (i==j): return value
               else: return 0

print "Matrix before transform=\n", a.toString()
print "We keep only diagonal elements of matrix 'a'"
c= a.transform(myFunction())
print c.toString()

