public static DMatrixSparseCSC rectangle ( int numRows , int numCols , int nz_total , double min , double max , Random rand ) { nz_total = Math . min ( numCols * numRows , nz_total ) ; int [ ] selected = UtilEjml . shuffled ( numRows * numCols , nz_total , rand ) ; Arrays . sort ( selected , 0 , nz_total ) ; DMatrixSparseCSC ret = new DMatrixSparseCSC ( numRows , numCols , nz_total ) ; ret . indicesSorted = true ; // compute the number of elements in each column int hist [ ] = new int [ numCols ] ; for ( int i = 0 ; i < nz_total ; i ++ ) { hist [ selected [ i ] / numRows ] ++ ; } // define col_idx ret . histogramToStructure ( hist ) ; for ( int i = 0 ; i < nz_total ; i ++ ) { int row = selected [ i ] % numRows ; ret . nz_rows [ i ] = row ; ret . nz_values [ i ] = rand . nextDouble ( ) * ( max - min ) + min ; } return ret ; }
Randomly generates matrix with the specified number of non - zero elements filled with values from min to max .