use of org.apache.sysml.runtime.matrix.data.MatrixValue in project systemml by apache.
the class ParameterizedBuiltinMRInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
if (blkList != null)
for (IndexedMatrixValue imv : blkList) {
if (imv == null)
continue;
if (_opcode.equalsIgnoreCase("replace")) {
MatrixValue in = imv.getValue();
MatrixIndexes inIX = imv.getIndexes();
// allocate space for the output value
IndexedMatrixValue iout = null;
if (output == input)
iout = tempValue;
else
iout = cachedValues.holdPlace(output, valueClass);
iout.getIndexes().setIndexes(inIX);
MatrixValue out = iout.getValue();
// process instruction
in.replaceOperations(out, _pattern, _replace);
// put the output value in the cache
if (iout == tempValue)
cachedValues.add(output, iout);
} else if (_opcode.equalsIgnoreCase("rexpand")) {
// process instruction
ArrayList<IndexedMatrixValue> out = new ArrayList<>();
LibMatrixReorg.rexpand(imv, _max, _dirRows, _cast, _ignore, blockRowFactor, blockColFactor, out);
// put the output values in the cache
for (IndexedMatrixValue lout : out) cachedValues.add(output, lout);
}
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project systemml by apache.
the class RemoveEmptyMRInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
// get input and offsets
IndexedMatrixValue inData = cachedValues.getFirst(input1);
IndexedMatrixValue inOffset = cachedValues.getFirst(input2);
MatrixIndexes ix = inData.getIndexes();
MatrixValue mb = inData.getValue();
if (_len > 0) {
// execute remove empty operations
ArrayList<IndexedMatrixValue> out = new ArrayList<>();
LibMatrixReorg.rmempty(inData, inOffset, _rmRows, _len, blockRowFactor, blockColFactor, out);
// put results into cache map
for (IndexedMatrixValue imv : out) cachedValues.add(output, imv);
} else {
int n = _emptyRet ? 1 : 0;
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(_rmRows ? 1 : ix.getRowIndex(), _rmRows ? ix.getColumnIndex() : 1), new MatrixBlock(_rmRows ? n : mb.getNumRows(), _rmRows ? mb.getNumColumns() : n, false)));
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project systemml by apache.
the class ReplicateInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
if (blkList != null) {
for (IndexedMatrixValue in : blkList) {
if (in == null)
continue;
// allocate space for the output value
IndexedMatrixValue out;
if (input == output)
out = tempValue;
else
out = cachedValues.holdPlace(output, valueClass);
// process instruction
MatrixIndexes inIx = in.getIndexes();
MatrixValue inVal = in.getValue();
if (// replicate columns
_repCols) {
// (e.g., M is Nx2700, blocksize=1000 -> numRep 2 because original block passed to index 1)
if (// blocksize should be 1000 or similar
blockColFactor <= 1)
LOG.warn("Block size of input matrix is: brlen=" + blockRowFactor + ", bclen=" + blockColFactor + ".");
long numRep = (long) Math.ceil((double) _lenM / blockColFactor) - 1;
// hence the memory overhead is very small)
for (long i = 0; i < numRep; i++) {
IndexedMatrixValue repV = cachedValues.holdPlace(output, valueClass);
MatrixIndexes repIX = repV.getIndexes();
repIX.setIndexes(inIx.getRowIndex(), 2 + i);
repV.set(repIX, inVal);
}
// output original block
out.set(inIx, inVal);
} else // replicate rows
{
// (e.g., M is Nx2700, blocksize=1000 -> numRep 2 because original block passed to index 1)
if (// blocksize should be 1000 or similar
blockRowFactor <= 1)
LOG.warn("Block size of input matrix is: brlen=" + blockRowFactor + ", bclen=" + blockColFactor + ".");
long numRep = (long) Math.ceil((double) _lenM / blockRowFactor) - 1;
// hence the memory overhead is very small)
for (long i = 0; i < numRep; i++) {
IndexedMatrixValue repV = cachedValues.holdPlace(output, valueClass);
MatrixIndexes repIX = repV.getIndexes();
repIX.setIndexes(2 + i, inIx.getColumnIndex());
repV.set(repIX, inVal);
}
// output original block
out.set(inIx, inVal);
}
// put the output value in the cache
if (out == tempValue)
cachedValues.add(output, out);
}
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project systemml by apache.
the class AppendMInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input1);
if (blkList == null)
return;
// right now this only deals with appending matrix with number of column <= blockColFactor
for (IndexedMatrixValue in1 : blkList) {
if (in1 == null)
continue;
// check for boundary block w/ awareness of zero rows or columns
int blen = _cbind ? blockColFactor : blockRowFactor;
long lastBlockColIndex = Math.max((long) Math.ceil((double) _offset / blen), 1);
// case 1: pass through of non-boundary blocks
MatrixIndexes ix = in1.getIndexes();
if ((_cbind ? ix.getColumnIndex() : ix.getRowIndex()) != lastBlockColIndex) {
cachedValues.add(output, in1);
} else // case 2: pass through full input block and rhs block
if (_cbind && in1.getValue().getNumColumns() == blen || !_cbind && in1.getValue().getNumRows() == blen) {
// output lhs block
cachedValues.add(output, in1);
// output shallow copy of rhs block
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
if (_cbind) {
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1), dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue()));
} else {
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex() + 1, ix.getColumnIndex()), dcInput.getDataBlock(1, (int) ix.getColumnIndex()).getValue()));
}
} else // case 3: append operation on boundary block
{
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
// allocate space for the output value
ArrayList<IndexedMatrixValue> outlist = new ArrayList<>(2);
IndexedMatrixValue first = cachedValues.holdPlace(output, valueClass);
first.getIndexes().setIndexes(ix);
outlist.add(first);
MatrixValue value_in2 = null;
if (_cbind) {
value_in2 = dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue();
if (in1.getValue().getNumColumns() + value_in2.getNumColumns() > blen) {
IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
second.getIndexes().setIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1);
outlist.add(second);
}
} else {
// rbind
value_in2 = dcInput.getDataBlock(1, (int) ix.getColumnIndex()).getValue();
if (in1.getValue().getNumRows() + value_in2.getNumRows() > blen) {
IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
second.getIndexes().setIndexes(ix.getRowIndex() + 1, ix.getColumnIndex());
outlist.add(second);
}
}
OperationsOnMatrixValues.performAppend(in1.getValue(), value_in2, outlist, blockRowFactor, blockColFactor, _cbind, true, 0);
}
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project systemml by apache.
the class MapperBase method commonMap.
@SuppressWarnings("unchecked")
protected void commonMap(Writable rawKey, Writable rawValue, OutputCollector<Writable, Writable> out, Reporter reporter) throws IOException {
long start = System.currentTimeMillis();
// for each representative matrix, read the record and apply instructions
for (int i = 0; i < representativeMatrixes.size(); i++) {
byte thisMatrix = representativeMatrixes.get(i);
// convert the record into the right format for the representative matrix
inputConverter.setBlockSize(brlens[i], bclens[i]);
inputConverter.convert(rawKey, rawValue);
// apply unary instructions on the converted indexes and values
while (inputConverter.hasNext()) {
Pair<MatrixIndexes, MatrixValue> pair = inputConverter.next();
MatrixIndexes indexes = pair.getKey();
MatrixValue value = pair.getValue();
checkValidity(indexes, value, i);
// put the input in the cache
cachedValues.reset();
cachedValues.set(thisMatrix, indexes, value);
// special operations for individual mapp type
specialOperationsForActualMap(i, out, reporter);
}
}
reporter.incrCounter(Counters.MAP_TIME, System.currentTimeMillis() - start);
}
Aggregations