Search in sources :

Example 1 with BinaryAccessType

use of org.apache.sysml.runtime.matrix.data.LibMatrixBincell.BinaryAccessType in project incubator-systemml by apache.

the class MatrixBlock method estimateSparsityOnBinary.

private static SparsityEstimate estimateSparsityOnBinary(MatrixBlock m1, MatrixBlock m2, BinaryOperator op) {
    SparsityEstimate est = new SparsityEstimate();
    //see also, special sparse-safe case for DIV in LibMatrixBincell 
    if (!op.sparseSafe && !(op.fn instanceof Divide)) {
        est.sparse = false;
        return est;
    }
    BinaryAccessType atype = LibMatrixBincell.getBinaryAccessType(m1, m2);
    boolean outer = (atype == BinaryAccessType.OUTER_VECTOR_VECTOR);
    long m = m1.getNumRows();
    long n = outer ? m2.getNumColumns() : m1.getNumColumns();
    long nz1 = m1.getNonZeros();
    long nz2 = m2.getNonZeros();
    //account for matrix vector and vector/vector
    long estnnz = 0;
    if (atype == BinaryAccessType.OUTER_VECTOR_VECTOR) {
        //for outer vector operations the sparsity estimate is exactly known
        estnnz = nz1 * nz2;
    } else //DEFAULT CASE
    {
        if (atype == BinaryAccessType.MATRIX_COL_VECTOR)
            nz2 = nz2 * n;
        else if (atype == BinaryAccessType.MATRIX_ROW_VECTOR)
            nz2 = nz2 * m;
        //compute output sparsity consistent w/ the hop compiler
        OpOp2 bop = op.getBinaryOperatorOpOp2();
        double sp1 = OptimizerUtils.getSparsity(m, n, nz1);
        double sp2 = OptimizerUtils.getSparsity(m, n, nz2);
        double spout = OptimizerUtils.getBinaryOpSparsity(sp1, sp2, bop, true);
        estnnz = UtilFunctions.toLong(spout * m * n);
    }
    est.sparse = evalSparseFormatInMemory(m, n, estnnz);
    est.estimatedNonZeros = estnnz;
    return est;
}
Also used : Divide(org.apache.sysml.runtime.functionobjects.Divide) OpOp2(org.apache.sysml.hops.Hop.OpOp2) BinaryAccessType(org.apache.sysml.runtime.matrix.data.LibMatrixBincell.BinaryAccessType)

Aggregations

OpOp2 (org.apache.sysml.hops.Hop.OpOp2)1 Divide (org.apache.sysml.runtime.functionobjects.Divide)1 BinaryAccessType (org.apache.sysml.runtime.matrix.data.LibMatrixBincell.BinaryAccessType)1