}
/**
- * Creates a new Matrix object. For example
+ * Creates a new Matrix object containing a copy of the supplied array values.
+ * For example
*
* <pre>
* new Matrix(new double[][] {{2, 3, 4}, {5, 6, 7})
{
this.rows = values.length;
this.cols = this.rows == 0 ? 0 : values[0].length;
- this.value = values;
+
+ /*
+ * make a copy of the values array, for immutability
+ */
+ this.value = new double[rows][];
+ int i = 0;
+ for (double[] row : values)
+ {
+ if (row != null)
+ {
+ value[i] = new double[row.length];
+ System.arraycopy(row, 0, value[i], 0, row.length);
+ }
+ i++;
+ }
}
/**
* Returns a new matrix which is the transpose of this one
*
- * @return DOCUMENT ME!
+ * @return
*/
@Override
public MatrixI transpose()
}
/**
- * Multiply every entry in the matrix by the given value. This method is not
- * thread-safe.
+ * Multiplies every entry in the matrix by the given value.
+ *
+ * @param
*/
@Override
- public void multiply(double d)
+ public void multiply(double by)
{
for (double[] row : value)
{
{
for (int i = 0; i < row.length; i++)
{
- row[i] *= d;
+ row[i] *= by;
}
}
}