smile.math
Class Array2D
- java.lang.Object
-
- smile.math.Array2D
-
public class Array2D extends java.lang.Object2-dimensional array of doubles. Java doesn't have real multidimensional arrays. They are just array of arrays, which are not friendly to modern CPU due to frequent cache miss. The extra (multiple times) array index checking also significantly reduces the performance. This class solves these pain points by storing data in a single 1D array of doubles in row major order. Note that this class is simple by design, as a replacement of double[][] in case of row by row access. For advanced matrix computation, please useMatrix.- See Also:
Matrix
-
-
Constructor Summary
Constructors Constructor and Description Array2D(double[][] A)Constructor.Array2D(int rows, int cols)Constructor of all-zero matrix.Array2D(int rows, int cols, double value)Constructor.Array2D(int rows, int cols, double[] value)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Array2Dadd(Array2D b)Array2Dadd(double x)doubleadd(int i, int j, double x)doubleapply(int i, int j)Returns A(i, j).Array2Ddiv(Array2D b)Array2Ddiv(double x)doublediv(int i, int j, double x)doubleget(int i, int j)Returns A(i, j).Array2Dmul(Array2D b)Array2Dmul(double x)doublemul(int i, int j, double x)intncols()intnrows()Array2DreplaceNaN(double x)doubleset(int i, int j, double x)Sets A(i, j).Array2Dsub(Array2D b)Array2Dsub(double x)doublesub(int i, int j, double x)doublesum()
-
-
-
Constructor Detail
-
Array2D
public Array2D(double[][] A)
Constructor.- Parameters:
A- the array of matrix.
-
Array2D
public Array2D(int rows, int cols)Constructor of all-zero matrix.
-
Array2D
public Array2D(int rows, int cols, double value)Constructor. Fill the matrix with given value.
-
Array2D
public Array2D(int rows, int cols, double[] value)Constructor.- Parameters:
value- the array of matrix values arranged in row major format
-
-
Method Detail
-
nrows
public int nrows()
-
ncols
public int ncols()
-
apply
public double apply(int i, int j)Returns A(i, j). Useful in Scala.
-
get
public double get(int i, int j)Returns A(i, j).
-
set
public double set(int i, int j, double x)Sets A(i, j).
-
add
public double add(int i, int j, double x)
-
sub
public double sub(int i, int j, double x)
-
mul
public double mul(int i, int j, double x)
-
div
public double div(int i, int j, double x)
-
add
public Array2D add(double x)
-
sub
public Array2D sub(double x)
-
mul
public Array2D mul(double x)
-
div
public Array2D div(double x)
-
replaceNaN
public Array2D replaceNaN(double x)
-
sum
public double sum()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG