Multiply a two element vector against this matrix.
If out is null or not length four, a new double array will be returned.
The values for vec and out can be the same (though that's less efficient).
351298
public double[] mult(double[] vec, double[] out) {
        if (out == null || out.length != 2) {
            out = new double[2];
        }

        if (vec == out) {
            double tx = m00*vec[0] + m01*vec[1] + m02;
            double ty = m10*vec[0] + m11*vec[1] + m12;

            out[0] = tx;
            out[1] = ty;
        } else {
            out[0] = m00*vec[0] + m01*vec[1] + m02;
            out[1] = m10*vec[0] + m11*vec[1] + m12;
        }

        return out;
    }
699991
@Override
    public double dot(Vec v)
    {
        if(v instanceof  ShiftedVec)
        {
            ShiftedVec other = (ShiftedVec) v;
            return this.base.dot(other.base) + other.base.sum()*this.shift + this.base.sum()*other.shift + this.length()*this.shift*other.shift;
        }
        return base.dot(v) + v.sum()*shift;
    }
954431
public Vector3f mul(Vector3fc v, Vector3f dest) {
        dest.x = x * v.x();
        dest.y = y * v.y();
        dest.z = z * v.z();
        return dest;
    }
107289
public static double[][] diag(double[] vector){

		// Note: According to the Java Language spec, an array is initialized with the default value, here 0.
		double[][] diagonalMatrix = new double[vector.length][vector.length];

		for(int index = 0; index < vector.length; index++) {
			diagonalMatrix[index][index] = vector[index];
		}

		return diagonalMatrix;
	}
1009144
static double inner_product(SparseVector vec1, SparseVector vec2)
    {
        Iterator<Map.Entry<Integer, Double>> it;
        SparseVector other;
        if (vec1.size() < vec2.size())
        {
            it = vec1.entrySet().iterator();
            other = vec2;
        }
        else
        {
            it = vec2.entrySet().iterator();
            other = vec1;
        }
        double prod = 0;
        while (it.hasNext())
        {
            Map.Entry<Integer, Double> entry = it.next();
            prod += entry.getValue() * other.get(entry.getKey());
        }
        return prod;
    }
119788
def multiply(self, a, b):
    
    if a is None or b is None: return None
    m, n, l = len(a), len(b[0]), len(b[0])
    if len(b) != n:
        raise Exception("A's column number must be equal to B's row number.")
    c = [[0 for _ in range(l)] for _ in range(m)]
    for i, row in enumerate(a):
        for k, eleA in enumerate(row):
            if eleA:
                for j, eleB in enumerate(b[k]):
                    if eleB: c[i][j] += eleA * eleB
    return c
421731
public static double[] xVals(double[] vector) {


        if (vector == null)
            return null;
        double[] x = new double[vector.length / 2];
        int count = 0;
        for (int i = 0; i < vector.length; i++) {
            if (i % 2 != 0)
                x[count++] = vector[i];
        }
        return x;
    }
294839
public Vector2d mul(double scalar, Vector2d dest) {
        dest.x = x * scalar;
        dest.y = y * scalar;
        return dest;
    }
57888
public Frame mult(Frame y) {
    int xrows = (int)_x.numRows();
    int xcols =      _x.numCols();
    int yrows = (int) y.numRows();
    int ycols =       y.numCols();
    if(xcols != yrows)
      throw new IllegalArgumentException("Matrices are not compatible for multiplication: ["+xrows+"x"+xcols+"] * ["+yrows+"x"+ycols+"]. Requires [n x m] * [m x p]");

    Vec[] x_vecs = _x.vecs();
    Vec[] y_vecs =  y.vecs();
    for(int k = 0; k < xcols; k++) {
      if(x_vecs[k].isEnum())
        throw new IllegalArgumentException("Multiplication not meaningful for factor column "+k);
    }
    for(int j = 0; j < ycols; j++) {
      if(y_vecs[j].isEnum())
        throw new IllegalArgumentException("Multiplication not meaningful for factor column "+j);
    }

    Vec[] output = new Vec[ycols];
    for(int j = 0; j < ycols; j++)
      output[j] = Vec.makeSeq(xrows);

    for(int i = 0; i < xrows; i++) {
      for(int j = 0; j < ycols; j++) {
        Vec yvec = y_vecs[j];
        double d = 0;
        for(int k = 0; k < xcols; k++)
          d += x_vecs[k].at(i) * yvec.at(k);
        output[j].set(i, d);
      }
    }
    return new Frame(y._names,output);
  }
1005258
public static DMatrixRMaj convert(DMatrix2 input , DMatrixRMaj output ) {
        if( output == null)
            output = new DMatrixRMaj(2,1);

        if( output.getNumRows() != 1 && output.getNumCols() != 1 )
            throw new IllegalArgumentException("One row or column must have a length of 1 for it to be a vector");
        int length = Math.max(output.getNumRows(),output.getNumCols());
        if( length != 2 )
            throw new IllegalArgumentException("Length of input vector is not 2.  It is "+length);

        output.data[0] = input.a1;
        output.data[1] = input.a2;

        return output;
    }
616761
def vector_to_arr(vec, dim):
    
    if len(dim) <= 1:
        return vec
    array = vec
    while len(dim) > 1:
        i = 0
        outer_array = []
        for m in range(reduce(mul, dim[0:-1])):
            inner_array = []
            for n in range(dim[-1]):
                inner_array.append(array[i])
                i += 1
            outer_array.append(inner_array)
        array = outer_array
        dim = dim[0:-1]

        return array
4209
public Vector4d mul(double scalar, Vector4d dest) {
        dest.x = x * scalar;
        dest.y = y * scalar;
        dest.z = z * scalar;
        dest.w = w * scalar;
        return dest;
    }
1137907
private static void quadMult(final double a[], final double b[], final double result[]) {
        final double xs[] = new double[2];
        final double ys[] = new double[2];
        final double zs[] = new double[2];

        /* a[0] * b[0] */
        split(a[0], xs);
        split(b[0], ys);
        splitMult(xs, ys, zs);

        result[0] = zs[0];
        result[1] = zs[1];

        /* a[0] * b[1] */
        split(b[1], ys);
        splitMult(xs, ys, zs);

        double tmp = result[0] + zs[0];
        result[1] = result[1] - (tmp - result[0] - zs[0]);
        result[0] = tmp;
        tmp = result[0] + zs[1];
        result[1] = result[1] - (tmp - result[0] - zs[1]);
        result[0] = tmp;

        /* a[1] * b[0] */
        split(a[1], xs);
        split(b[0], ys);
        splitMult(xs, ys, zs);

        tmp = result[0] + zs[0];
        result[1] = result[1] - (tmp - result[0] - zs[0]);
        result[0] = tmp;
        tmp = result[0] + zs[1];
        result[1] = result[1] - (tmp - result[0] - zs[1]);
        result[0] = tmp;

        /* a[1] * b[0] */
        split(a[1], xs);
        split(b[1], ys);
        splitMult(xs, ys, zs);

        tmp = result[0] + zs[0];
        result[1] = result[1] - (tmp - result[0] - zs[0]);
        result[0] = tmp;
        tmp = result[0] + zs[1];
        result[1] = result[1] - (tmp - result[0] - zs[1]);
        result[0] = tmp;
    }
320991
public Matrix multiply(Matrix m) throws MatrixException
    {
        // Validate m's dimensions.
        if (nCols != m.nRows) {
            throw new MatrixException(
                                MatrixException.INVALID_DIMENSIONS);
        }

        double pv[][] = new double[nRows][m.nCols];  // product values

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

        return new Matrix(pv);
    }
1336789
public static Vector add(Vector vector1, Vector vector2) {
        if (vector2.length() != vector1.length())
            throw new IllegalArgumentException(
                    "Vectors of different sizes cannot be added");
        if (vector2 instanceof IntegerVector &&
            vector1 instanceof DoubleVector)
            return add(vector1, Vectors.asDouble(vector2));
        if (vector2 instanceof SparseVector)
            addSparseValues(vector1, vector2);
        else {
            int length = vector2.length();
            for (int i = 0; i < length; ++i) {
                double value = vector2.getValue(i).doubleValue() +
                               vector1.getValue(i).doubleValue();
                vector1.set(i, value);
            }
        }

        return vector1;
    }
417270
public void mul(double b, IVector result) {
        if (result.size != size) result.reshape(size);

        int i;
        for (i = 0; i < size; i++) {
            result.realvector[i] = realvector[i] * b;
            result.imagvector[i] = imagvector[i] * b;
        }
    }
44515
private final void MultiplyAv(int n, double[] v, double[] Av){
        for (int i=0; i<n; i++){
            Av[i] = 0;
            for (int j=0; j<n; j++) Av[i] += A(i,j)*v[j];
        }
    }

     transposed */
    private final void MultiplyAtv(int n, double[] v, double[] Atv){
        for (int i=0;i<n;i++){
            Atv[i] = 0;
            for (int j=0; j<n; j++) Atv[i] += A(j,i)*v[j];
        }
    }

     and then by matrix A transposed */
    private final void MultiplyAtAv(int n, double[] v, double[] AtAv){
        double[] u = new double[n];
        MultiplyAv(n,v,u);
        MultiplyAtv(n,u,AtAv);
    }
}