use of org.apache.sysml.runtime.functionobjects.Equals in project incubator-systemml by apache.
the class LibMatrixOuterAgg method prepareRowIndicesMax.
/**
* This function will return max indices, based on column vector data.
* This indices will be computed based on operator.
* These indices can be used to compute max index for a given input value in subsequent operation.
*
* e.g. Right Vector has data (V1) : 6 3 9 7 2 4 4 3
* Original indices for this data will be (I1): 1 2 3 4 5 6 7 8
*
* Sorting this data based on value will be (V2): 2 3 3 4 4 6 7 9
* Then indices will be ordered as (I2): 5 2 8 6 7 1 4 3
*
* CumMax of I2 will be A: (CumMin(I2)) 5 5 8 8 8 8 8 8
* CumMax of I2 in reverse order be B: 8 8 8 7 7 4 4 3
*
* Values from vector A is used to compute RowIndexMax for > & >= operators
* Values from vector B is used to compute RowIndexMax for < & <= operators
* Values from I2 is used to compute RowIndexMax for == operator.
* Original values are directly used to compute RowIndexMax for != operator
*
* Shifting values from vector A or B is required to compute final indices.
* Once indices are shifted from vector A or B, their cell value corresponding to input data will be used.
*
* @param iCols ?
* @param vmb ?
* @param bOp binary operator
* @return array of maximum row indices
* @throws DMLRuntimeException if DMLRuntimeException occurs
*/
public static int[] prepareRowIndicesMax(int iCols, double[] vmb, BinaryOperator bOp) throws DMLRuntimeException {
int[] vixCumSum = null;
int[] vix = new int[iCols];
//sort index vector on extracted data (unstable)
if (!(bOp.fn instanceof NotEquals)) {
for (int i = 0; i < iCols; i++) vix[i] = i;
SortUtils.sortByValueStable(0, iCols, vmb, vix);
}
if (bOp.fn instanceof LessThan || bOp.fn instanceof LessThanEquals || bOp.fn instanceof GreaterThan || bOp.fn instanceof GreaterThanEquals) {
boolean bPrimeCumSum = false;
if (bOp.fn instanceof LessThan || bOp.fn instanceof LessThanEquals)
bPrimeCumSum = true;
double[] dvix = new double[vix.length];
if (bPrimeCumSum)
for (int i = 0; i < vix.length; i++) dvix[vix.length - 1 - i] = vix[i];
else
for (int i = 0; i < vix.length; i++) dvix[i] = vix[i];
MatrixBlock mbix = DataConverter.convertToMatrixBlock(dvix, true);
UnaryOperator u_op = new UnaryOperator(Builtin.getBuiltinFnObject(Builtin.BuiltinCode.CUMMAX));
MatrixBlock mbResult = (MatrixBlock) mbix.unaryOperations(u_op, new MatrixBlock());
vixCumSum = DataConverter.convertToIntVector(mbResult);
if (bPrimeCumSum)
for (int i = 0; i < (vixCumSum.length + 1) / 2; i++) {
int iTemp = vixCumSum[vixCumSum.length - 1 - i];
vixCumSum[vixCumSum.length - 1 - i] = vixCumSum[i];
vixCumSum[i] = iTemp;
}
adjustRowIndicesMax(vixCumSum, vmb, bOp);
} else if (bOp.fn instanceof Equals || bOp.fn instanceof NotEquals) {
adjustRowIndicesMax(vix, vmb, bOp);
vixCumSum = vix;
}
return vixCumSum;
}
use of org.apache.sysml.runtime.functionobjects.Equals in project incubator-systemml by apache.
the class LibMatrixOuterAgg method prepareRowIndicesMin.
/**
* This function will return min indices, based on column vector data.
* This indices will be computed based on operator.
* These indices can be used to compute min index for a given input value in subsequent operation.
*
* e.g. Right Vector has data (V1) : 6 3 9 7 2 4 4 3
* Original indices for this data will be (I1): 1 2 3 4 5 6 7 8
*
* Sorting this data based on value will be (V2): 2 3 3 4 4 6 7 9
* Then indices will be ordered as (I2): 5 2 8 6 7 1 4 3
*
* CumMin of I2 will be A: (CumMin(I2)) 5 2 2 2 2 1 1 1
* CumMin of I2 in reverse order be B: 1 1 1 1 1 1 3 3
*
* Values from vector A is used to compute RowIndexMin for > operator
* Values from vector B is used to compute RowIndexMin for <, <= and >= operators
* Values from I2 is used to compute RowIndexMax for == operator.
* Original values are directly used to compute RowIndexMax for != operator
*
* Shifting values from vector A or B is required to compute final indices.
* Once indices are shifted from vector A or B, their cell value corresponding to input data will be used.
*
* @param iCols ?
* @param vmb ?
* @param bOp binary operator
* @return array of minimum row indices
* @throws DMLRuntimeException if DMLRuntimeException occurs
*/
public static int[] prepareRowIndicesMin(int iCols, double[] vmb, BinaryOperator bOp) throws DMLRuntimeException {
int[] vixCumSum = null;
int[] vix = new int[iCols];
//sort index vector on extracted data (unstable)
if (!(bOp.fn instanceof NotEquals || bOp.fn instanceof Equals)) {
for (int i = 0; i < iCols; i++) vix[i] = i;
SortUtils.sortByValueStable(0, iCols, vmb, vix);
}
if (bOp.fn instanceof LessThan || bOp.fn instanceof LessThanEquals || bOp.fn instanceof GreaterThan || bOp.fn instanceof GreaterThanEquals) {
boolean bPrimeCumSum = false;
if (bOp.fn instanceof GreaterThan || bOp.fn instanceof GreaterThanEquals)
bPrimeCumSum = true;
double[] dvix = new double[vix.length];
if (bPrimeCumSum)
for (int i = 0; i < vix.length; i++) dvix[vix.length - 1 - i] = vix[i];
else
for (int i = 0; i < vix.length; i++) dvix[i] = vix[i];
MatrixBlock mbix = DataConverter.convertToMatrixBlock(dvix, true);
UnaryOperator u_op = new UnaryOperator(Builtin.getBuiltinFnObject(Builtin.BuiltinCode.CUMMIN));
MatrixBlock mbResult = (MatrixBlock) mbix.unaryOperations(u_op, new MatrixBlock());
vixCumSum = DataConverter.convertToIntVector(mbResult);
if (bPrimeCumSum)
for (int i = 0; i < (vixCumSum.length + 1) / 2; i++) {
int iTemp = vixCumSum[vixCumSum.length - 1 - i];
vixCumSum[vixCumSum.length - 1 - i] = vixCumSum[i];
vixCumSum[i] = iTemp;
}
adjustRowIndicesMin(vixCumSum, vmb, bOp);
} else if (bOp.fn instanceof Equals || bOp.fn instanceof NotEquals) {
adjustRowIndicesMin(vix, vmb, bOp);
vixCumSum = vix;
}
return vixCumSum;
}
Aggregations