コード例 #1
0
  @Override
  public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    // get inputs
    MatrixBlock matBlock1 = ec.getMatrixInput(input1.getName());
    MatrixBlock matBlock2 = ec.getMatrixInput(input2.getName());

    // check input dimensions
    if (_type == AppendType.CBIND && matBlock1.getNumRows() != matBlock2.getNumRows()) {
      throw new DMLRuntimeException(
          "Append-cbind is not possible for input matrices "
              + input1.getName()
              + " and "
              + input2.getName()
              + " with different number of rows: "
              + matBlock1.getNumRows()
              + " vs "
              + matBlock2.getNumRows());
    } else if (_type == AppendType.RBIND
        && matBlock1.getNumColumns() != matBlock2.getNumColumns()) {
      throw new DMLRuntimeException(
          "Append-rbind is not possible for input matrices "
              + input1.getName()
              + " and "
              + input2.getName()
              + " with different number of columns: "
              + matBlock1.getNumColumns()
              + " vs "
              + matBlock2.getNumColumns());
    }

    // execute append operations (append both inputs to initially empty output)
    MatrixBlock ret =
        matBlock1.appendOperations(matBlock2, new MatrixBlock(), _type == AppendType.CBIND);

    // set output and release inputs
    ec.setMatrixOutput(output.getName(), ret);
    ec.releaseMatrixInput(input1.getName());
    ec.releaseMatrixInput(input2.getName());
  }
  @Override
  public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    CPOperand mat = (input1.getDataType() == DataType.MATRIX) ? input1 : input2;
    CPOperand scalar = (input1.getDataType() == DataType.MATRIX) ? input2 : input1;

    MatrixBlock inBlock = ec.getMatrixInput(mat.getName());
    ScalarObject constant =
        (ScalarObject)
            ec.getScalarInput(scalar.getName(), scalar.getValueType(), scalar.isLiteral());

    ScalarOperator sc_op = (ScalarOperator) _optr;
    sc_op.setConstant(constant.getDoubleValue());

    MatrixBlock retBlock = (MatrixBlock) inBlock.scalarOperations(sc_op, new MatrixBlock());

    ec.releaseMatrixInput(mat.getName());

    // Ensure right dense/sparse output representation (guarded by released input memory)
    if (checkGuardedRepresentationChange(inBlock, retBlock)) {
      retBlock.examSparsity();
    }

    ec.setMatrixOutput(output.getName(), retBlock);
  }