vkostyukov / la4j

Linear Algebra for Java
http://la4j.org
Apache License 2.0
373 stars 109 forks source link

Replace builders with factory methods #241

Closed vkostyukov closed 9 years ago

vkostyukov commented 9 years ago

I would like to follow Scala style of factory methods in the companion objects. Here is how I see the overall picture.

For vectors:

Vector a = CompressedVector.empty();
Vector b = CompressedVector.ofLength(4);
Vector c = CompressedVector.of(1, 2, 3, 4);
Vector d = CompressedVector.fromArray(array);
Vector f = CompressedVector.constant(2, 3);
Vector g = CompressedVector.random(4, new Random());

For matrices:

Matrix a = CRSMatrix.empty();
Matrix b = CRSMatrix.ofShape(2, 4);
Matrix c = CRSMatrix.from1DArray(array1D);
Matrix d = CRSMatrix.from2DArray(array2D);
Matrix g = CRSMatrix.constant(4, 4);
Matrix h = CRSMatrix.random(4, new Random());
Matrix i = CRSMatrix.randomSymmetric();
Matrix j = CRSMatrix.square(4);
Matrix k = CRSMatrix.identity(4);
Matrix l = CRSMatrix.diagonal();
Matrix m = CRSMatrix.block();