Search in sources :

Example 66 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project systemml by apache.

the class SGDNesterovUpdate method copy.

// Assumption dest is zero-ed out.
private static void copy(MatrixBlock src, double[] dest) {
    if (src.isInSparseFormat()) {
        Iterator<IJV> iter = src.getSparseBlockIterator();
        while (iter.hasNext()) {
            IJV ijv = iter.next();
            dest[ijv.getI() * ijv.getJ()] = ijv.getV();
        }
    } else {
        double[] denseBlock = src.getDenseBlockValues();
        if (denseBlock != null) {
            // If not empty block
            System.arraycopy(denseBlock, 0, dest, 0, dest.length);
        }
    }
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 67 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project systemml by apache.

the class CumSumProd method execute.

@Override
public void execute() {
    X = ((Matrix) getFunctionInput(0)).getMatrixObject().acquireRead();
    C = ((Matrix) getFunctionInput(1)).getMatrixObject().acquireRead();
    if (X.getNumRows() != C.getNumRows())
        throw new RuntimeException("Number of rows of X and C should match");
    if (X.getNumColumns() != C.getNumColumns() && C.getNumColumns() != 1)
        throw new RuntimeException("Incorrect Number of columns of X and C (Expected C to be of same dimension or a vector)");
    start = Double.parseDouble(((Scalar) getFunctionInput(2)).getValue());
    isReverse = Boolean.parseBoolean(((Scalar) getFunctionInput(3)).getValue());
    numRetRows = X.getNumRows();
    numRetCols = X.getNumColumns();
    allocateOutput();
    // Copy X to Y
    denseBlock = retMB.getDenseBlockValues();
    if (X.isInSparseFormat()) {
        Iterator<IJV> iter = X.getSparseBlockIterator();
        while (iter.hasNext()) {
            IJV ijv = iter.next();
            denseBlock[ijv.getI() * numRetCols + ijv.getJ()] = ijv.getV();
        }
    } else {
        if (X.getDenseBlock() != null)
            System.arraycopy(X.getDenseBlockValues(), 0, denseBlock, 0, denseBlock.length);
    }
    if (!isReverse) {
        // Y [1, ] = X [1, ] + C [1, ] * start;
        // Y [i+1, ] = X [i+1, ] + C [i+1, ] * Y [i, ]
        addCNConstant(0, start);
        for (int i = 1; i < numRetRows; i++) {
            addC(i, true);
        }
    } else {
        // Y [m, ] = X [m, ] + C [m, ] * start;
        // Y [i-1, ] = X [i-1, ] + C [i-1, ] * Y [i, ]
        addCNConstant(numRetRows - 1, start);
        for (int i = numRetRows - 2; i >= 0; i--) {
            addC(i, false);
        }
    }
    ((Matrix) getFunctionInput(1)).getMatrixObject().release();
    ((Matrix) getFunctionInput(0)).getMatrixObject().release();
    retMB.recomputeNonZeros();
    try {
        retMB.examSparsity();
        ret.setMatrixDoubleArray(retMB, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
    } catch (DMLRuntimeException e) {
        throw new RuntimeException("Error while executing CumSumProd", e);
    } catch (IOException e) {
        throw new RuntimeException("Error while executing CumSumProd", e);
    }
}
Also used : Matrix(org.apache.sysml.udf.Matrix) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IJV(org.apache.sysml.runtime.matrix.data.IJV) IOException(java.io.IOException) Scalar(org.apache.sysml.udf.Scalar) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 68 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project systemml by apache.

the class CumSumProd method addC.

private void addC(int i, boolean addPrevRow) {
    boolean isCVector = C.getNumColumns() != ret.getNumCols();
    if (C.isInSparseFormat()) {
        Iterator<IJV> iter = C.getSparseBlockIterator(i, i + 1);
        while (iter.hasNext()) {
            IJV ijv = iter.next();
            if (!isCVector) {
                if (addPrevRow)
                    denseBlock[ijv.getI() * numRetCols + ijv.getJ()] += ijv.getV() * denseBlock[(ijv.getI() - 1) * numRetCols + ijv.getJ()];
                else
                    denseBlock[ijv.getI() * numRetCols + ijv.getJ()] += ijv.getV() * denseBlock[(ijv.getI() + 1) * numRetCols + ijv.getJ()];
            } else {
                double val = ijv.getV();
                for (int j = ijv.getI() * numRetCols; j < (ijv.getI() + 1) * numRetCols; j++) {
                    double val1 = addPrevRow ? denseBlock[(ijv.getI() - 1) * numRetCols + ijv.getJ()] : denseBlock[(ijv.getI() + 1) * numRetCols + ijv.getJ()];
                    denseBlock[j] += val * val1;
                }
            }
        }
    } else {
        double[] CBlk = C.getDenseBlockValues();
        if (CBlk != null) {
            if (!isCVector) {
                for (int j = i * numRetCols; j < (i + 1) * numRetCols; j++) {
                    double val1 = addPrevRow ? denseBlock[j - numRetCols] : denseBlock[j + numRetCols];
                    denseBlock[j] += CBlk[j] * val1;
                }
            } else {
                for (int j = i * numRetCols; j < (i + 1) * numRetCols; j++) {
                    double val1 = addPrevRow ? denseBlock[j - numRetCols] : denseBlock[j + numRetCols];
                    denseBlock[j] += CBlk[i] * val1;
                }
            }
        }
    }
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 69 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project systemml by apache.

the class SpoofCellwise method executeCompressedAggSum.

private double executeCompressedAggSum(CompressedMatrixBlock a, SideInput[] b, double[] scalars, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    KahanObject kbuff2 = new KahanObject(0, 0);
    // special case: computation over value-tuples only
    if (sparseSafe && b.length == 0 && !a.hasUncompressedColGroup()) {
        // note: all remaining groups are guaranteed ColGroupValue
        boolean entireGrp = (rl == 0 && ru == a.getNumRows());
        int maxNumVals = a.getColGroups().stream().mapToInt(g -> ((ColGroupValue) g).getNumValues()).max().orElse(0);
        int[] counts = new int[maxNumVals];
        for (ColGroup grp : a.getColGroups()) {
            ColGroupValue grpv = (ColGroupValue) grp;
            counts = entireGrp ? grpv.getCounts(counts) : grpv.getCounts(rl, ru, counts);
            for (int k = 0; k < grpv.getNumValues(); k++) {
                kbuff2.set(0, 0);
                double in = grpv.sumValues(k, kplus, kbuff2);
                double out = genexec(in, b, scalars, m, n, -1, -1);
                kplus.execute3(kbuff, out, counts[k]);
            }
        }
    } else // general case of arbitrary side inputs
    {
        Iterator<IJV> iter = a.getIterator(rl, ru, !sparseSafe);
        while (iter.hasNext()) {
            IJV cell = iter.next();
            double val = genexec(cell.getV(), b, scalars, m, n, cell.getI(), cell.getJ());
            kplus.execute2(kbuff, val);
        }
    }
    return kbuff._sum;
}
Also used : ColGroup(org.apache.sysml.runtime.compress.ColGroup) IJV(org.apache.sysml.runtime.matrix.data.IJV) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) ColGroupValue(org.apache.sysml.runtime.compress.ColGroupValue)

Example 70 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project systemml by apache.

the class SpoofCellwise method executeCompressedRowAggMxx.

private long executeCompressedRowAggMxx(CompressedMatrixBlock a, SideInput[] b, double[] scalars, double[] c, int m, int n, boolean sparseSafe, int rl, int ru) {
    Arrays.fill(c, rl, ru, (_aggOp == AggOp.MIN) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY);
    ValueFunction vfun = getAggFunction();
    long lnnz = 0;
    Iterator<IJV> iter = a.getIterator(rl, ru, !sparseSafe);
    while (iter.hasNext()) {
        IJV cell = iter.next();
        double val = genexec(cell.getV(), b, scalars, m, n, cell.getI(), cell.getJ());
        c[cell.getI()] = vfun.execute(c[cell.getI()], val);
    }
    for (int i = rl; i < ru; i++) lnnz += (c[i] != 0) ? 1 : 0;
    return lnnz;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) IJV(org.apache.sysml.runtime.matrix.data.IJV)

Aggregations

IJV (org.apache.sysml.runtime.matrix.data.IJV)80 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)22 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)12 SparseBlock (org.apache.sysml.runtime.matrix.data.SparseBlock)11 BufferedWriter (java.io.BufferedWriter)10 OutputStreamWriter (java.io.OutputStreamWriter)10 FileSystem (org.apache.hadoop.fs.FileSystem)10 SequenceFile (org.apache.hadoop.io.SequenceFile)10 File (java.io.File)8 IOException (java.io.IOException)8 Path (org.apache.hadoop.fs.Path)8 JobConf (org.apache.hadoop.mapred.JobConf)8 MatrixCell (org.apache.sysml.runtime.matrix.data.MatrixCell)7 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)7 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)6 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)6 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)6 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)6