Multiply this matrix by a column vector: this*cv
@param cv the column vector
@return the product column vector
@throws numbercruncher.MatrixException for invalid size
182717
public ColumnVector multiply(ColumnVector cv)
        throws MatrixException
    {
        // Validate cv's size.
        if (nRows != cv.nRows) {
            throw new MatrixException(
                                MatrixException.INVALID_DIMENSIONS);
        }

        double pv[] = new double[nRows];   // product values

        // Compute the values of the product.
        for (int r = 0; r < nRows; ++r) {
            double dot = 0;
            for (int c = 0; c < nCols; ++c) {
                dot += values[r][c] * cv.values[c][0];
            }
            pv[r] = dot;
        }

        return new ColumnVector(pv);
    }
590146
public static Basic2DMatrix fromCSV(String csv) {
        return Matrix.fromCSV(csv).to(Matrices.BASIC_2D);
    }
28197
public Matrix4d set3x3(Matrix3dc mat) {
        m00 = mat.m00();
        m01 = mat.m01();
        m02 = mat.m02();
        m10 = mat.m10();
        m11 = mat.m11();
        m12 = mat.m12();
        m20 = mat.m20();
        m21 = mat.m21();
        m22 = mat.m22();
        properties &= ~(PROPERTY_PERSPECTIVE | PROPERTY_IDENTITY | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL);
        return this;
    }
667739
public Matrix4f set4x3(Matrix4x3fc mat) {
        if (mat instanceof Matrix4x3f) {
            MemUtil.INSTANCE.copy4x3((Matrix4x3f) mat, this);
        } else {
            set4x3Matrix4x3fc(mat);
        }
        properties &= mat.properties() & ~(PROPERTY_PERSPECTIVE);
        return this;
    }
100271
public Matrix multiply(double c, ExecutorService threadPool)
    {
        Matrix toReturn = getThisSideMatrix(null);
        toReturn.mutableMultiply(c, threadPool);
        return toReturn;
    }
283822
public Matrix3d set(int column, int row, double value) {
        switch (column) {
        case 0:
            switch (row) {
            case 0:
                this.m00 = value;
                return this;
            case 1:
                this.m01 = value;
                return this;
            case 2:
                this.m02 = value;
                return this;
            default:
                break;
            }
            break;
        case 1:
            switch (row) {
            case 0:
                this.m10 = value;
                return this;
            case 1:
                this.m11 = value;
                return this;
            case 2:
                this.m12 = value;
                return this;
            default:
                break;
            }
            break;
        case 2:
            switch (row) {
            case 0:
                this.m20 = value;
                return this;
            case 1:
                this.m21 = value;
                return this;
            case 2:
                this.m22 = value;
                return this;
            default:
                break;
            }
            break;
        default:
            break;
        }
        throw new IllegalArgumentException();
    }
203796
public Matrix4f set3x3(Matrix3fc mat) {
        if (mat instanceof Matrix3f) {
            MemUtil.INSTANCE.copy3x3((Matrix3f) mat, this);
        } else {
            set3x3Matrix3fc(mat);
        }
        properties &= ~(PROPERTY_PERSPECTIVE | PROPERTY_IDENTITY | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL);
        return this;
    }
462156
public static DenseMatrix matrix(int nrows, int ncols, double value) {
        if (nlmatrixOnes != null) {
            try {
                return (DenseMatrix) nlmatrixOnes.newInstance(nrows, ncols, value);
            } catch (Exception e) {
                logger.error("Failed to call NLMatrix(int, int, double): {}", e);
            }
        }

        return new JMatrix(nrows, ncols, value);
    }
554056
public Matrix4x3d set(Matrix4x3dc m) {
        m00 = m.m00();
        m01 = m.m01();
        m02 = m.m02();
        m10 = m.m10();
        m11 = m.m11();
        m12 = m.m12();
        m20 = m.m20();
        m21 = m.m21();
        m22 = m.m22();
        m30 = m.m30();
        m31 = m.m31();
        m32 = m.m32();
        properties = m.properties();
        return this;
    }
1117589
public static double[] colMeans (RealMatrix matrix) {
        // Get the col sums:
        double[] retval = EMatrixUtils.colSums(matrix);

        // Iterate over return value and divide by the length:
        for (int i = 0; i < retval.length; i++) {
            retval[i] = retval[i] / matrix.getRowDimension();
        }

        // Done, return col means:
        return retval;
    }
441087
public Matrix4x3f set3x3(Matrix3fc mat) {
        if (mat instanceof Matrix3f) {
            MemUtil.INSTANCE.copy3x3((Matrix3f) mat, this);
        } else {
            set3x3Matrix3fc(mat);
        }
        properties = 0;
        return this;
    }
611250
@Override
	public double innerVectorHessian( DMatrixRMaj v ) {
		int M = A.getNumRows();

		double sum = 0;
		sum += innerProduct(v.data, 0, A, v.data, 0);
		sum += 2*innerProduct(v.data, 0, B, v.data, M);
		sum += innerProduct(v.data, M, D, v.data, M);

		return sum;
	}
619891
public Matrix4x3d set(Matrix4dc m) {
        m00 = m.m00();
        m01 = m.m01();
        m02 = m.m02();
        m10 = m.m10();
        m11 = m.m11();
        m12 = m.m12();
        m20 = m.m20();
        m21 = m.m21();
        m22 = m.m22();
        m30 = m.m30();
        m31 = m.m31();
        m32 = m.m32();
        properties = m.properties() & (PROPERTY_IDENTITY | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL);
        return this;
    }
832562
public Num calculate() {
        unbind();
        prepareForNewCalculation();
        
        PostfixCalculator pc = convertToPostfix();
        Num cv = pc.calculate(this, postfix, trackSteps);

        lastCalculatedValue = cv.clone();

        return cv;
    }
1243667
public Matrix4x3f set(Matrix4fc m) {
        if (m instanceof Matrix4f) {
            MemUtil.INSTANCE.copy((Matrix4f) m, this);
        } else {
            setMatrix4fc(m);
        }
        properties = m.properties() & (PROPERTY_IDENTITY | PROPERTY_TRANSLATION | PROPERTY_ORTHONORMAL);
        return this;
    }
553990
public DoubleVector getRowVector(int row) {
        DoubleVector v = getRow(row, -1, false);
        // If no row was currently assigned in the matrix, then return an empty
        // vector in its place.  Otherwise, return a view on top of the vector
        // with its current length
        return (v == null) 
            ? new CompactSparseVector(cols.get())
            : Vectors.subview(v, 0, cols.get());
    }
276256
public static Matrix copy(Matrix m) {
		if (m==null) throw new NullPointerException();
		Matrix copy=createMatrix(m.getRowCount(), m.getColumnCount());
		for (int row=0; row<m.getRowCount(); row++) for (int col=0; col<m.getColumnCount(); col++)
			copy.set(row, col, m.getQuick(row, col));
		return copy;
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Matrix2 copy(Matrix2 m) {
		return (Matrix2) copy((Matrix)m);
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Matrix3 copy(Matrix3 m) {
		return (Matrix3) copy((Matrix)m);
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector copy(Vector m) {
		return (Vector) copy((Matrix)m);
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector2 copy(Vector2 m) {
		return (Vector2) copy((Matrix)m);
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector3 copy(Vector3 m) {
		return (Vector3) copy((Matrix)m);
	}

	/**
	 * Creates a copy of a matrix.
	 * @param m the matrix to copy
	 * @return a new matrix with the same dimensions and contents as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector4 copy(Vector4 m) {
		return (Vector4) copy((Matrix)m);
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Matrix createLike(Matrix matrix) {
		return createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Matrix2 createLike(Matrix2 matrix) {
		return (Matrix2) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Matrix3 createLike(Matrix3 matrix) {
		return (Matrix3) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector createLike(Vector matrix) {
		return (Vector) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector2 createLike(Vector2 matrix) {
		return (Vector2) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector3 createLike(Vector3 matrix) {
		return (Vector3) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates a matrix with the same dimensions as the argument.
	 * @param matrix the template matrix
	 * @return a new zero matrix with the same dimensions as the argument
	 * @throws NullPointerException if {@code matrix} is {@code null}
	 */
	public static Vector4 createLike(Vector4 matrix) {
		return (Vector4) createMatrix(matrix.getRowCount(), matrix.getColumnCount());
	}
	
	/**
	 * Creates an identity matrix of the specified dimension.
	 * @param size the dimension of the matrix
	 * @return a <code>size</code>×<code>size</code> identity matrix
	 * @throws IllegalArgumentException if the size is not positive
	 */
	public static Matrix identity(int size) {
		Matrix m = MatrixFactory.createMatrix(size, size);
		for (int i = 0; i < size; i++)
			m.set(i, i, 1);
		return m;
	}

	/**
	 * Creates a matrix of the specified size whose elements are all 1.
	 * @param rows the number of rows
	 * @param columns the number of columns
	 * @return a <code>rows</code>×<code>columns</code> matrix whose elements are all 1
	 * @throws IllegalArgumentException if either argument is non-positive
	 */
	public static Matrix ones(int rows, int columns) {
		Matrix m = MatrixFactory.createMatrix(rows, columns);
		for (int i = 0; i < m.getRowCount(); i++)
			for (int j = 0; j < m.getColumnCount(); j++)
				m.set(i, j, 1);
		return m;
	}

	/**
	 * Creates a matrix of the specified size whose elements are pseudorandom, uniformly distributed
	 * values between 0 (inclusive) and 1 (exclusive).
	 * @param rows the number of rows
	 * @param columns the number of columns
	 * @return a <code>rows</code>×<code>columns</code> matrix of random elements
	 * @throws IllegalArgumentException if either argument is non-positive
	 */
	public static Matrix random(int rows, int columns) {
		Matrix m = MatrixFactory.createMatrix(rows, columns);
		for (int i = 0; i < m.getRowCount(); i++)
			for (int j = 0; j < m.getColumnCount(); j++)
				m.set(i, j, Math.random());
		return m;
	}
	
	//
	// Matrix creation from arrays
	//
	
	/**
	 * Creates a matrix and initializes its elements from an array. The parameter should be a {@code double[r][c]}
	 * array with {@code r>0} and {@code c>0}. The matrix element at row {@code row} and column {@code col} will be
	 * {@code elements[row][col]}.
	 * @param elements the array containing the elements of the matrix
	 * @return the new matrix initialized from the array
	 * @throws NullPointerException if the array is {@code null}
	 * @throws IllegalArgumentException if the dimensions of the array are not valid
	 */
	public static Matrix createMatrix(double[][] elements) {
		Matrix m=createMatrix(elements.length, elements[0].length);
		for (int row=0; row<m.getRowCount(); row++) {
			double[] rowData=elements[row];
			if (rowData.length!=m.getColumnCount()) throw new IllegalArgumentException("Invalid array");
			for (int col=0; col<m.getColumnCount(); col++) {
				m.set(row, col, rowData[col]);
			}
		}
		return m;
	}
	
	/**
	 * Creates a matrix and initializes its elements from an array. The parameter should be a {@code double[2][2]}
	 * array. The matrix element at row {@code row} and column {@code col} will be
	 * {@code elements[row][col]}.
	 * @param elements the array containing the elements of the matrix
	 * @return the new matrix initialized from the array
	 * @throws NullPointerException if the array is {@code null}
	 * @throws IllegalArgumentException if the dimensions of the array are not correct
	 */
	public static Matrix2 createMatrix2(double[][] elements) {
		Matrix m=createMatrix(elements);
		if (m.getRowCount()!=2 || m.getColumnCount()!=2)
			throw new IllegalArgumentException("Array describes a matrix of size "+m.getRowCount()+"x"+m.getColumnCount()+" instead of 2x2");
		return (Matrix2)m;
	}
	
	/**
	 * Creates a matrix and initializes its elements from an array. The parameter should be a {@code double[3][3]}
	 * array. The matrix element at row {@code row} and column {@code col} will be
	 * {@code elements[row][col]}.
	 * @param elements the array containing the elements of the matrix
	 * @return the new matrix initialized from the array
	 * @throws NullPointerException if the array is {@code null}
	 * @throws IllegalArgumentException if the dimensions of the array are not correct
	 */
	public static Matrix3 createMatrix3(double[][] elements) {
		Matrix m=createMatrix(elements);
		if (m.getRowCount()!=3 || m.getColumnCount()!=3)
			throw new IllegalArgumentException("Array describes a matrix of size "+m.getRowCount()+"x"+m.getColumnCount()+" instead of 3x3");
		return (Matrix3)m;
	}
	
	/**
	 * Creates a vector and initializes its elements from an array.
	 * @param elements the array containing the elements of the vector
	 * @return the new vector initialized from the array
	 * @throws NullPointerException if the array is {@code null}
	 * @throws IllegalArgumentException if the length of the array is zero
	 */
	public static Vector createVector(double[] elements) {
		Vector v=createVector(elements.length);
		for (int i=0; i<elements.length; i++)
			v.setCoordQuick(i, elements[i]);
		return v;
	}
	
	/**
	 * Creates a matrix backed by the specified data structure.
	 * @param core the data structure for the new matrix
	 * @return a matrix of proper type using the specified matrix core for its implementation
	 * @throws NullPointerException if {@code core} is {@code null}
	 */
	public static Matrix create(MatrixCore core) {
		if (core.getColumnCount()==1) {
			switch (core.getRowCount()) {
				case 2: return new CoredVector2Impl(core);
				case 3: return new CoredVector3Impl(core);
				case 4: return new CoredVector4Impl(core);
				default: return new CoredVectorImpl(core);
			}
		} else {
			if (core.getRowCount()==2 && core.getColumnCount()==2)
				return new CoredMatrix2Impl(core);
			if (core.getRowCount()==3 && core.getColumnCount()==3)
				return new CoredMatrix3Impl(core);
			return new CoredMatrixImpl(core);
		}
	}
}