Almost everything in ojAlgo makes use of or interacts with some array based data structure. To always code directly against raw arrays like double[], float[] or Number[] would be awkward. Therefore there are classes that encapsulate these raw arrays and, using generics and inheritance, defines a set of standard methods to interact with them. This is done in the org.ojalgo.array package.

In the org.ojalgo.array package there are classes supporting 1, 2 or “any” dimensional “arrays” of double, floatBigDecimalComplexNumberQuaternion and RationalNumber. The arrays can be sparse or dense and arbitrarily large (using long indices). Further more the actual data do NOT have to be in plain Java arrays (like double[] or float[]) but may reside in byte buffers, memory mapped files, native off heap memory or whatever else you can think of.

The linear algebra stuff builds on this, and that in turn enable stuff like the optimisation solvers, neural network and more. But the array classes can also be used directly.

Example Code

Console Output


class WorkingWithArrays
ojAlgo
2022-09-27

Element types supported ny ojAlgo
=================================
C128 := Math number set C implemented as 2 x DOUBLE
H256 := Math number set H implemented as 4 x DOUBLE
Q128 := Math number set Q implemented as 2 x LONG
R032 := Math number set R implemented as 1 x FLOAT
R064 := Math number set R implemented as 1 x DOUBLE
R128 := Math number set R implemented as 1 x REFERENCE
Z008 := Math number set Z implemented as 1 x BYTE
Z016 := Math number set Z implemented as 1 x SHORT
Z032 := Math number set Z implemented as 1 x INT
Z064 := Math number set Z implemented as 1 x LONG

shape.lengtgh 4 = rank() 4
Original shape: [2, 3, 1, 4]
Squeezed shape: [2, 3, 4]
Reshaped shape: [3, 2, 4]
3 different shapes: [2, 3, 1, 4], [2, 3, 4] and [3, 2, 4]

Element-wise iteration
ElementView 0: 0 = 1.0
ElementView 1: 1 = 1.0
ElementView 2: 2 = 1.0
ElementView 3: 3 = 1.0
ElementView 4: 4 = 1.0
ElementView 5: 5 = 1.0
ElementView 6: 6 = 2.0
ElementView 7: 7 = 2.0
ElementView 8: 8 = 2.0
ElementView 9: 9 = 2.0
ElementView 10: 10 = 2.0
ElementView 11: 11 = 2.0
ElementView 12: 12 = 3.0
ElementView 13: 13 = 3.0
ElementView 14: 14 = 3.0
ElementView 15: 15 = 3.0
ElementView 16: 16 = 3.0
ElementView 17: 17 = 3.0
ElementView 18: 18 = 4.0
ElementView 19: 19 = 4.0
ElementView 20: 20 = 4.0
ElementView 21: 21 = 4.0
ElementView 22: 22 = 4.0
ElementView 23: 23 = 4.0

Vector-wise iteration
VectorView 0: { 1.0, 1.0, 1.0 }
VectorView 1: { 1.0, 1.0, 1.0 }
VectorView 2: { 2.0, 2.0, 2.0 }
VectorView 3: { 2.0, 2.0, 2.0 }
VectorView 4: { 3.0, 3.0, 3.0 }
VectorView 5: { 3.0, 3.0, 3.0 }
VectorView 6: { 4.0, 4.0, 4.0 }
VectorView 7: { 4.0, 4.0, 4.0 }

Matrix-wise iteration
MatrixView 0: { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }
MatrixView 1: { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 }
MatrixView 2: { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 }
MatrixView 3: { 4.0, 4.0, 4.0, 4.0, 4.0, 4.0 }