public static MatrixBlock convertToMatrixBlock(FrameBlock frame) throws DMLRuntimeException {
  int m=frame.getNumRows();
  int n=frame.getNumColumns();
  MatrixBlock mb=new MatrixBlock(m,n,false);
  mb.allocateDenseBlock();
  ValueType[] schema=frame.getSchema();
  int dFreq=UtilFunctions.frequency(schema,ValueType.DOUBLE);
  if (dFreq == schema.length) {
    double[][] a=new double[n][];
    double[] c=mb.getDenseBlock();
    for (int j=0; j < n; j++)     a[j]=(double[])frame.getColumn(j);
    int blocksizeIJ=16;
    for (int bi=0; bi < m; bi+=blocksizeIJ)     for (int bj=0; bj < n; bj+=blocksizeIJ) {
      int bimin=Math.min(bi + blocksizeIJ,m);
      int bjmin=Math.min(bj + blocksizeIJ,n);
      for (int i=bi, aix=bi * n; i < bimin; i++, aix+=n)       for (int j=bj; j < bjmin; j++)       c[aix + j]=a[j][i];
    }
  }
 else {
    for (int i=0; i < frame.getNumRows(); i++)     for (int j=0; j < frame.getNumColumns(); j++) {
      mb.appendValue(i,j,UtilFunctions.objectToDouble(schema[j],frame.get(i,j)));
    }
  }
  mb.examSparsity();
  return mb;
}

public static MatrixBlock convertToMatrixBlock ( FrameBlock frame ) throws DMLRuntimeException { int m = frame . getNumRows ( ) ; int n = frame . getNumColumns ( ) ; MatrixBlock mb = new MatrixBlock ( m , n , false ) ; mb . allocateDenseBlock ( ) ; ValueType [ ] schema = frame . getSchema ( ) ; int dFreq = UtilFunctions . frequency ( schema , ValueType . DOUBLE ) ; if ( dFreq == schema . length ) { double [ ] [ ] a = new double [ n ] [ ] ; double [ ] c = mb . getDenseBlock ( ) ; for ( int j = 0 ; j < n ; j ++ ) a [ j ] = ( double [ ] ) frame . getColumn ( j ) ; int blocksizeIJ = 16 ; for ( int bi = 0 ; bi < m ; bi += blocksizeIJ ) for ( int bj = 0 ; bj < n ; bj += blocksizeIJ ) { int bimin = Math . min ( bi + blocksizeIJ , m ) ; int bjmin = Math . min ( bj + blocksizeIJ , n ) ; for ( int i = bi , aix = bi * n ; i < bimin ; i ++ , aix += n ) for ( int j = bj ; j < bjmin ; j ++ ) c [ aix + j ] = a [ j ] [ i ] ; } } else { for ( int i = 0 ; i < frame . getNumRows ( ) ; i ++ ) for ( int j = 0 ; j < frame . getNumColumns ( ) ; j ++ ) { mb . appendValue ( i , j , UtilFunctions . objectToDouble ( schema [ j ] , frame . get ( i , j ) ) ) ; } } mb . examSparsity ( ) ; return mb ; }
converts a frame block with arbitrary schema into a matrix block . since matrix block only supports value type double , we do a best effort conversion of non - double types which might result in errors for non - numerical data .
