Search in sources :

Example 1 with SwapIndex

use of org.apache.sysml.runtime.functionobjects.SwapIndex in project incubator-systemml by apache.

the class MatrixBlock method reorgOperations.

@Override
public MatrixValue reorgOperations(ReorgOperator op, MatrixValue ret, int startRow, int startColumn, int length) throws DMLRuntimeException {
    if (!(op.fn instanceof SwapIndex || op.fn instanceof DiagIndex || op.fn instanceof SortIndex || op.fn instanceof RevIndex))
        throw new DMLRuntimeException("the current reorgOperations cannot support: " + op.fn.getClass() + ".");
    MatrixBlock result = checkType(ret);
    //compute output dimensions and sparsity flag
    CellIndex tempCellIndex = new CellIndex(-1, -1);
    op.fn.computeDimension(rlen, clen, tempCellIndex);
    boolean sps = evalSparseFormatInMemory(tempCellIndex.row, tempCellIndex.column, nonZeros);
    //prepare output matrix block w/ right meta data
    if (result == null)
        result = new MatrixBlock(tempCellIndex.row, tempCellIndex.column, sps, nonZeros);
    else
        result.reset(tempCellIndex.row, tempCellIndex.column, sps, nonZeros);
    if (LibMatrixReorg.isSupportedReorgOperator(op)) {
        //SPECIAL case (operators with special performance requirements, 
        //or size-dependent special behavior)
        //currently supported opcodes: r', rdiag, rsort
        LibMatrixReorg.reorg(this, result, op);
    } else {
        //GENERIC case (any reorg operator)
        CellIndex temp = new CellIndex(0, 0);
        if (sparse) {
            if (sparseBlock != null) {
                for (int r = 0; r < Math.min(rlen, sparseBlock.numRows()); r++) {
                    if (sparseBlock.isEmpty(r))
                        continue;
                    int apos = sparseBlock.pos(r);
                    int alen = sparseBlock.size(r);
                    int[] aix = sparseBlock.indexes(r);
                    double[] avals = sparseBlock.values(r);
                    for (int i = apos; i < apos + alen; i++) {
                        tempCellIndex.set(r, aix[i]);
                        op.fn.execute(tempCellIndex, temp);
                        result.appendValue(temp.row, temp.column, avals[i]);
                    }
                }
            }
        } else {
            if (denseBlock != null) {
                if (//SPARSE<-DENSE
                result.isInSparseFormat()) {
                    double[] a = denseBlock;
                    for (int i = 0, aix = 0; i < rlen; i++) for (int j = 0; j < clen; j++, aix++) {
                        temp.set(i, j);
                        op.fn.execute(temp, temp);
                        result.appendValue(temp.row, temp.column, a[aix]);
                    }
                } else //DENSE<-DENSE
                {
                    result.allocateDenseBlock();
                    Arrays.fill(result.denseBlock, 0);
                    double[] a = denseBlock;
                    double[] c = result.denseBlock;
                    int n = result.clen;
                    for (int i = 0, aix = 0; i < rlen; i++) for (int j = 0; j < clen; j++, aix++) {
                        temp.set(i, j);
                        op.fn.execute(temp, temp);
                        c[temp.row * n + temp.column] = a[aix];
                    }
                    result.nonZeros = nonZeros;
                }
            }
        }
    }
    return result;
}
Also used : SwapIndex(org.apache.sysml.runtime.functionobjects.SwapIndex) RevIndex(org.apache.sysml.runtime.functionobjects.RevIndex) DiagIndex(org.apache.sysml.runtime.functionobjects.DiagIndex) SortIndex(org.apache.sysml.runtime.functionobjects.SortIndex) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 DiagIndex (org.apache.sysml.runtime.functionobjects.DiagIndex)1 RevIndex (org.apache.sysml.runtime.functionobjects.RevIndex)1 SortIndex (org.apache.sysml.runtime.functionobjects.SortIndex)1 SwapIndex (org.apache.sysml.runtime.functionobjects.SwapIndex)1