idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
36,200
private void setup ( ) { st = new StreamTokenizer ( this ) ; st . resetSyntax ( ) ; st . eolIsSignificant ( false ) ; st . lowerCaseMode ( true ) ; st . wordChars ( '0' , '9' ) ; st . wordChars ( '-' , '.' ) ; st . wordChars ( '\u0000' , '\u00FF' ) ; st . commentChar ( '%' ) ; st . whitespaceChars ( ' ' , ' ' ) ; st . whitespaceChars ( '\u0009' , '\u000e' ) ; }
Sets up the stream tokenizer
36,201
public void add ( int num , int [ ] indices ) { for ( int i = 0 ; i < indices . length ; ++ i ) indices [ i ] += num ; }
Shifts the indices . Useful for converting between 0 - and 1 - based indicing .
36,202
private String readTrimmedLine ( ) throws IOException { String line = readLine ( ) ; if ( line != null ) return line . trim ( ) ; else throw new EOFException ( ) ; }
Reads a line and trims it of surrounding whitespace
36,203
public MatrixInfo readMatrixInfo ( ) throws IOException { String [ ] component = readTrimmedLine ( ) . split ( " +" ) ; if ( component . length != 5 ) throw new IOException ( "Current line unparsable. It must consist of 5 tokens" ) ; if ( ! component [ 0 ] . equalsIgnoreCase ( "%%MatrixMarket" ) ) throw new IOException ( "Not in Matrix Market exchange format" ) ; if ( ! component [ 1 ] . equalsIgnoreCase ( "matrix" ) ) throw new IOException ( "Expected \"matrix\", got " + component [ 1 ] ) ; boolean sparse = false ; if ( component [ 2 ] . equalsIgnoreCase ( "coordinate" ) ) sparse = true ; else if ( component [ 2 ] . equalsIgnoreCase ( "array" ) ) sparse = false ; else throw new IOException ( "Unknown layout " + component [ 2 ] ) ; MatrixInfo . MatrixField field = null ; if ( component [ 3 ] . equalsIgnoreCase ( "real" ) ) field = MatrixInfo . MatrixField . Real ; else if ( component [ 3 ] . equalsIgnoreCase ( "integer" ) ) field = MatrixInfo . MatrixField . Integer ; else if ( component [ 3 ] . equalsIgnoreCase ( "complex" ) ) field = MatrixInfo . MatrixField . Complex ; else if ( component [ 3 ] . equalsIgnoreCase ( "pattern" ) ) field = MatrixInfo . MatrixField . Pattern ; else throw new IOException ( "Unknown field specification " + component [ 3 ] ) ; MatrixInfo . MatrixSymmetry symmetry = null ; if ( component [ 4 ] . equalsIgnoreCase ( "general" ) ) symmetry = MatrixInfo . MatrixSymmetry . General ; else if ( component [ 4 ] . equalsIgnoreCase ( "symmetric" ) ) symmetry = MatrixInfo . MatrixSymmetry . Symmetric ; else if ( component [ 4 ] . equalsIgnoreCase ( "skew-symmetric" ) ) symmetry = MatrixInfo . MatrixSymmetry . SkewSymmetric ; else if ( component [ 4 ] . equalsIgnoreCase ( "Hermitian" ) ) symmetry = MatrixInfo . MatrixSymmetry . Hermitian ; else throw new IOException ( "Unknown symmetry specification " + component [ 4 ] ) ; return new MatrixInfo ( sparse , field , symmetry ) ; }
Reads the matrix info for the Matrix Market exchange format . The line must consist of exactly 5 space - separated entries the first being %%MatrixMarket
36,204
public VectorInfo readVectorInfo ( ) throws IOException { String [ ] component = readTrimmedLine ( ) . split ( " +" ) ; if ( component . length != 4 ) throw new IOException ( "Current line unparsable. It must consist of 4 tokens" ) ; if ( ! component [ 0 ] . equalsIgnoreCase ( "%%MatrixMarket" ) ) throw new IOException ( "Not in Matrix Market exchange format" ) ; if ( ! component [ 1 ] . equalsIgnoreCase ( "vector" ) ) throw new IOException ( "Expected \"vector\", got " + component [ 1 ] ) ; boolean sparse = false ; if ( component [ 2 ] . equalsIgnoreCase ( "coordinate" ) ) sparse = true ; else if ( component [ 2 ] . equalsIgnoreCase ( "array" ) ) sparse = false ; else throw new IOException ( "Unknown layout " + component [ 2 ] ) ; VectorInfo . VectorField field = null ; if ( component [ 3 ] . equalsIgnoreCase ( "real" ) ) field = VectorInfo . VectorField . Real ; else if ( component [ 3 ] . equalsIgnoreCase ( "integer" ) ) field = VectorInfo . VectorField . Integer ; else if ( component [ 3 ] . equalsIgnoreCase ( "complex" ) ) field = VectorInfo . VectorField . Complex ; else if ( component [ 3 ] . equalsIgnoreCase ( "pattern" ) ) field = VectorInfo . VectorField . Pattern ; else throw new IOException ( "Unknown field specification " + component [ 3 ] ) ; return new VectorInfo ( sparse , field ) ; }
Reads the vector info for the Matrix Market exchange format . The line must consist of exactly 4 space - separated entries the first being %%MatrixMarket
36,205
public MatrixSize readMatrixSize ( MatrixInfo info ) throws IOException { int numRows = getInt ( ) , numColumns = getInt ( ) ; if ( info . isDense ( ) ) return new MatrixSize ( numRows , numColumns , info ) ; else { int numEntries = getInt ( ) ; return new MatrixSize ( numRows , numColumns , numEntries ) ; } }
Reads in the size of a matrix . Skips initial comments
36,206
public MatrixSize readArraySize ( ) throws IOException { int numRows = getInt ( ) , numColumns = getInt ( ) ; return new MatrixSize ( numRows , numColumns , numRows * numColumns ) ; }
Reads in the size of an array matrix . Skips initial comments
36,207
public MatrixSize readCoordinateSize ( ) throws IOException { int numRows = getInt ( ) , numColumns = getInt ( ) , numEntries = getInt ( ) ; return new MatrixSize ( numRows , numColumns , numEntries ) ; }
Reads in the size of a coordinate matrix . Skips initial comments
36,208
public VectorSize readVectorSize ( VectorInfo info ) throws IOException { int size = getInt ( ) ; if ( info . isDense ( ) ) return new VectorSize ( size ) ; else { int numEntries = getInt ( ) ; return new VectorSize ( size , numEntries ) ; } }
Reads in the size of a vector . Skips initial comments
36,209
public VectorSize readVectorCoordinateSize ( ) throws IOException { int size = getInt ( ) , numEntries = getInt ( ) ; return new VectorSize ( size , numEntries ) ; }
Reads in the size of a coordinate vector . Skips initial comments
36,210
public void readArray ( double [ ] dataR , double [ ] dataI ) throws IOException { int size = dataR . length ; if ( size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { dataR [ i ] = getDouble ( ) ; dataI [ i ] = getDouble ( ) ; } }
Reads the array data . The first array will contain real entries while the second contain imaginary entries
36,211
public void readCoordinate ( int [ ] index , double [ ] data ) throws IOException { int size = index . length ; if ( size != data . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { index [ i ] = getInt ( ) ; data [ i ] = getDouble ( ) ; } }
Reads a coordinate vector
36,212
public void readCoordinate ( int [ ] index , float [ ] dataR , float [ ] dataI ) throws IOException { int size = index . length ; if ( size != dataR . length || size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { index [ i ] = getInt ( ) ; dataR [ i ] = getFloat ( ) ; dataI [ i ] = getFloat ( ) ; } }
Reads a coordinate vector . First data array contains real entries and the second contains imaginary entries
36,213
public void readPattern ( int [ ] index ) throws IOException { int size = index . length ; for ( int i = 0 ; i < size ; ++ i ) index [ i ] = getInt ( ) ; }
Reads a pattern vector
36,214
public void readCoordinate ( int [ ] row , int [ ] column , double [ ] data ) throws IOException { int size = row . length ; if ( size != column . length || size != data . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { row [ i ] = getInt ( ) ; column [ i ] = getInt ( ) ; data [ i ] = getDouble ( ) ; } }
Reads a coordinate matrix
36,215
public void readPattern ( int [ ] row , int [ ] column ) throws IOException { int size = row . length ; if ( size != column . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { row [ i ] = getInt ( ) ; column [ i ] = getInt ( ) ; } }
Reads a pattern matrix
36,216
public void readCoordinate ( int [ ] row , int [ ] column , double [ ] dataR , double [ ] dataI ) throws IOException { int size = row . length ; if ( size != column . length || size != dataR . length || size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) { row [ i ] = getInt ( ) ; column [ i ] = getInt ( ) ; dataR [ i ] = getDouble ( ) ; dataI [ i ] = getDouble ( ) ; } }
Reads a coordinate matrix . First data array contains real entries and the second contains imaginary entries
36,217
private float getFloat ( ) throws IOException { st . nextToken ( ) ; if ( st . ttype == StreamTokenizer . TT_WORD ) return Float . parseFloat ( st . sval ) ; else if ( st . ttype == StreamTokenizer . TT_EOF ) throw new EOFException ( "End-of-File encountered during parsing" ) ; else throw new IOException ( "Unknown token found during parsing" ) ; }
Reads a float
36,218
private int getDiagSize ( int diagonal ) { if ( diagonal < 0 ) return Math . min ( numRows + diagonal , numColumns ) ; else return Math . min ( numRows , numColumns - diagonal ) ; }
Finds the size of the requested diagonal to be allocated
36,219
public PermutationMatrix getP ( ) { PermutationMatrix perm = PermutationMatrix . fromPartialPivots ( piv ) ; perm . transpose ( ) ; return perm ; }
Returns the permutation matrix .
36,220
public QRP factor ( Matrix A ) { if ( Q . numRows ( ) != A . numRows ( ) ) throw new IllegalArgumentException ( "Q.numRows() != A.numRows()" ) ; else if ( R . numColumns ( ) != A . numColumns ( ) ) throw new IllegalArgumentException ( "R.numColumns() != A.numColumns()" ) ; Afact . zero ( ) ; for ( MatrixEntry e : A ) { Afact . set ( e . row ( ) , e . column ( ) , e . get ( ) ) ; } intW info = new intW ( 0 ) ; LAPACK lapack = LAPACK . getInstance ( ) ; double [ ] factorWorkOptimalSize = { 0.0 } ; double [ ] factorWork ; lapack . dgeqp3 ( m , n , Afact . getData ( ) , Matrices . ld ( m ) , jpvt , tau , factorWorkOptimalSize , - 1 , info ) ; factorWork = new double [ ( int ) factorWorkOptimalSize [ 0 ] ] ; lapack . dgeqp3 ( m , n , Afact . getData ( ) , Matrices . ld ( m ) , jpvt , tau , factorWork , factorWork . length , info ) ; if ( info . val < 0 ) { throw new IllegalArgumentException ( "DGEQP3 was " + info . val ) ; } R . zero ( ) ; for ( MatrixEntry e : Afact ) { if ( e . row ( ) <= e . column ( ) && e . column ( ) < R . numColumns ( ) ) { R . set ( e . row ( ) , e . column ( ) , e . get ( ) ) ; } } final double EPS = 1e-12 ; for ( rank = 0 ; rank < k ; rank ++ ) { if ( Math . abs ( R . get ( rank , rank ) ) < EPS ) break ; } lapack . dorgqr ( m , m , k , Afact . getData ( ) , Matrices . ld ( m ) , tau , work , work . length , info ) ; for ( MatrixEntry e : Afact ) { if ( e . column ( ) < Q . numColumns ( ) ) Q . set ( e . row ( ) , e . column ( ) , e . get ( ) ) ; } if ( info . val < 0 ) throw new IllegalArgumentException ( ) ; for ( int i = 0 ; i < jpvt . length ; i ++ ) { -- jpvt [ i ] ; } return this ; }
Executes a QR factorization for the given matrix .
36,221
public void apply ( Matrix H , int column , int i1 , int i2 ) { double temp = c * H . get ( i1 , column ) + s * H . get ( i2 , column ) ; H . set ( i2 , column , - s * H . get ( i1 , column ) + c * H . get ( i2 , column ) ) ; H . set ( i1 , column , temp ) ; }
Applies the Givens rotation to two elements in a matrix column
36,222
public void apply ( Vector x , int i1 , int i2 ) { double temp = c * x . get ( i1 ) + s * x . get ( i2 ) ; x . set ( i2 , - s * x . get ( i1 ) + c * x . get ( i2 ) ) ; x . set ( i1 , temp ) ; }
Applies the Givens rotation to two elements of a vector
36,223
public static LQ factorize ( Matrix A ) { return new LQ ( A . numRows ( ) , A . numColumns ( ) ) . factor ( new DenseMatrix ( A ) ) ; }
Convenience method to compute a LQ decomposition
36,224
private void validate ( ) { if ( isDense ( ) && isPattern ( ) ) throw new IllegalArgumentException ( "Matrix cannot be dense with pattern storage" ) ; if ( isReal ( ) && isHermitian ( ) ) throw new IllegalArgumentException ( "Data cannot be real with hermitian symmetry" ) ; if ( ! isComplex ( ) && isHermitian ( ) ) throw new IllegalArgumentException ( "Data must be complex with hermitian symmetry" ) ; if ( isPattern ( ) && isSkewSymmetric ( ) ) throw new IllegalArgumentException ( "Storage cannot be pattern and skew symmetrical" ) ; }
Validates the representation
36,225
public static RQ factorize ( Matrix A ) { return new RQ ( A . numRows ( ) , A . numColumns ( ) ) . factor ( new DenseMatrix ( A ) ) ; }
Convenience method to compute an RQ decomposition
36,226
public void setRestart ( int restart ) { this . restart = restart ; if ( restart <= 0 ) throw new IllegalArgumentException ( "restart must be a positive integer" ) ; s = new DenseVector ( restart + 1 ) ; H = new DenseMatrix ( restart + 1 , restart ) ; rotation = new GivensRotation [ restart + 1 ] ; v = new Vector [ restart + 1 ] ; for ( int i = 0 ; i < v . length ; ++ i ) v [ i ] = r . copy ( ) . zero ( ) ; }
Sets the restart parameter
36,227
private static void scatter ( SparseVector v , double [ ] z ) { int [ ] index = v . getIndex ( ) ; int used = v . getUsed ( ) ; double [ ] data = v . getData ( ) ; Arrays . fill ( z , 0 ) ; for ( int i = 0 ; i < used ; ++ i ) z [ index [ i ] ] = data [ i ] ; }
Copies the sparse vector into a dense array
36,228
private void gather ( double [ ] z , SparseVector v , double taui , int d ) { int nl = 0 , nu = 0 ; for ( VectorEntry e : v ) { if ( e . index ( ) < d ) nl ++ ; else if ( e . index ( ) > d ) nu ++ ; } v . zero ( ) ; lower . clear ( ) ; for ( int i = 0 ; i < d ; ++ i ) if ( Math . abs ( z [ i ] ) > taui ) lower . add ( new IntDoubleEntry ( i , z [ i ] ) ) ; upper . clear ( ) ; for ( int i = d + 1 ; i < z . length ; ++ i ) if ( Math . abs ( z [ i ] ) > taui ) upper . add ( new IntDoubleEntry ( i , z [ i ] ) ) ; Collections . sort ( lower ) ; Collections . sort ( upper ) ; v . set ( d , z [ d ] ) ; for ( int i = 0 ; i < Math . min ( nl + p , lower . size ( ) ) ; ++ i ) { IntDoubleEntry e = lower . get ( i ) ; v . set ( e . index , e . value ) ; } for ( int i = 0 ; i < Math . min ( nu + p , upper . size ( ) ) ; ++ i ) { IntDoubleEntry e = upper . get ( i ) ; v . set ( e . index , e . value ) ; } }
Copies the dense array back into the sparse vector applying a numerical dropping rule and keeping only a given number of entries
36,229
public void setEigenvalues ( double eigmin , double eigmax ) { this . eigmin = eigmin ; this . eigmax = eigmax ; if ( eigmin <= 0 ) throw new IllegalArgumentException ( "eigmin <= 0" ) ; if ( eigmax <= 0 ) throw new IllegalArgumentException ( "eigmax <= 0" ) ; if ( eigmin > eigmax ) throw new IllegalArgumentException ( "eigmin > eigmax" ) ; }
Sets the eigenvalue estimates .
36,230
private static void checkKhatriRaoArguments ( Matrix A , Matrix B ) { if ( A . numColumns ( ) != B . numColumns ( ) ) throw new IndexOutOfBoundsException ( "A.numColumns != B.numColumns (" + A . numColumns ( ) + " != " + B . numColumns ( ) + ")" ) ; }
Tests if the matrices have an equal number of columns .
36,231
public void printMatrixSize ( MatrixSize size , MatrixInfo info ) { format ( Locale . ENGLISH , "%10d %10d" , size . numRows ( ) , size . numColumns ( ) ) ; if ( info . isCoordinate ( ) ) format ( Locale . ENGLISH , " %19d" , size . numEntries ( ) ) ; println ( ) ; }
Prints the matrix size
36,232
public void printMatrixSize ( MatrixSize size ) { format ( Locale . ENGLISH , "%10d %10d %19d%n" , size . numRows ( ) , size . numColumns ( ) , size . numEntries ( ) ) ; }
Prints the matrix size . Assumes coordinate format
36,233
public void printVectorSize ( VectorSize size , VectorInfo info ) { format ( Locale . ENGLISH , "%10d" , size . size ( ) ) ; if ( info . isCoordinate ( ) ) format ( Locale . ENGLISH , " %19d" , size . numEntries ( ) ) ; println ( ) ; }
Prints the vector size
36,234
public void printVectorSize ( VectorSize size ) { format ( Locale . ENGLISH , "%10d %19d%n" , size . size ( ) , size . numEntries ( ) ) ; }
Prints the vector size . Assumes coordinate format
36,235
public void printArray ( double [ ] data ) { for ( int i = 0 ; i < data . length ; ++ i ) format ( Locale . ENGLISH , "% .12e%n" , data [ i ] ) ; }
Prints an array to the underlying stream . One entry per line .
36,236
public void printArray ( float [ ] dataR , float [ ] dataI ) { int size = dataR . length ; if ( size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "% .12e % .12e%n" , dataR [ i ] , dataI [ i ] ) ; }
Prints an array to the underlying stream . One entry per line . The first array specifies the real entries and the second is the imaginary entries
36,237
public void printCoordinate ( int [ ] index , long [ ] data , int offset ) { int size = index . length ; if ( size != data . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d %10d%n" , index [ i ] + offset , data [ i ] ) ; }
Prints the coordinate format to the underlying stream . One index and entry on each line . The offset is added to the index typically this can transform from a 0 - based indicing to a 1 - based .
36,238
public void printCoordinate ( int [ ] index , float [ ] dataR , float [ ] dataI , int offset ) { int size = index . length ; if ( size != dataR . length || size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d % .12e % .12e%n" , index [ i ] + offset , dataR [ i ] , dataI [ i ] ) ; }
Prints the coordinate format to the underlying stream . One index and entry on each line . The offset is added to each index typically this can transform from a 0 - based indicing to a 1 - based . The first float array specifies the real entries and the second is the imaginary entries
36,239
public void printCoordinate ( int [ ] row , int [ ] column , float [ ] dataR , float [ ] dataI , int offset ) { int size = row . length ; if ( size != column . length || size != dataR . length || size != dataI . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d %10d % .12e % .12e%n" , row [ i ] + offset , column [ i ] + offset , dataR [ i ] , dataI [ i ] ) ; }
Prints the coordinate format to the underlying stream . One index pair and entry on each line . The offset is added to each index typically this can transform from a 0 - based indicing to a 1 - based . The first float array specifies the real entries and the second is the imaginary entries
36,240
public void printCoordinate ( int [ ] row , int [ ] column , long [ ] data , int offset ) { int size = row . length ; if ( size != column . length || size != data . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d %10d %19d%n" , row [ i ] + offset , column [ i ] + offset , data [ i ] ) ; }
Prints the coordinate format to the underlying stream . One index pair and entry on each line . The offset is added to each index typically this can transform from a 0 - based indicing to a 1 - based .
36,241
public void printPattern ( int [ ] row , int [ ] column , int offset ) { int size = row . length ; if ( size != column . length ) throw new IllegalArgumentException ( "All arrays must be of the same size" ) ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d %10d%n" , row [ i ] + offset , column [ i ] + offset ) ; }
Prints the coordinates to the underlying stream . One index pair on each line . The offset is added to each index typically this can transform from a 0 - based indicing to a 1 - based .
36,242
public void printPattern ( int [ ] index , int offset ) { int size = index . length ; for ( int i = 0 ; i < size ; ++ i ) format ( Locale . ENGLISH , "%10d%n" , index [ i ] + offset ) ; }
Prints the coordinates to the underlying stream . One index on each line . The offset is added to each index typically this can transform from a 0 - based indicing to a 1 - based .
36,243
public void printCoordinate ( int [ ] row , int [ ] column , float [ ] dataR , float [ ] dataI ) { printCoordinate ( row , column , dataR , dataI , 0 ) ; }
Prints the coordinate format to the underlying stream . One index pair and entry on each line . The first double array specifies the real entries and the second is the imaginary entries
36,244
public static QL factorize ( Matrix A ) { return new QL ( A . numRows ( ) , A . numColumns ( ) ) . factor ( new DenseMatrix ( A ) ) ; }
Convenience method to compute a QL decomposition
36,245
private static int [ ] findDiagonalIndices ( CompRowMatrix A ) { int [ ] rowptr = A . getRowPointers ( ) ; int [ ] colind = A . getColumnIndices ( ) ; int [ ] diagIndices = new int [ A . numRows ( ) ] ; for ( int i = 0 ; i < A . numRows ( ) ; ++ i ) { diagIndices [ i ] = no . uib . cipr . matrix . sparse . Arrays . binarySearch ( colind , i , rowptr [ i ] , rowptr [ i + 1 ] ) ; if ( diagIndices [ i ] < 0 ) throw new RuntimeException ( "Matrix is missing a diagonal entry on row " + ( i + 1 ) ) ; } return diagIndices ; }
Finds the diagonal indices of the matrix
36,246
private List < Set < Integer > > findNodeNeighborhood ( CompRowMatrix A , int [ ] diagind , double eps ) { N = new ArrayList < Set < Integer > > ( A . numRows ( ) ) ; int [ ] rowptr = A . getRowPointers ( ) ; int [ ] colind = A . getColumnIndices ( ) ; double [ ] data = A . getData ( ) ; for ( int i = 0 ; i < A . numRows ( ) ; ++ i ) { Set < Integer > Ni = new HashSet < Integer > ( ) ; double aii = data [ diagind [ i ] ] ; for ( int j = rowptr [ i ] ; j < rowptr [ i + 1 ] ; ++ j ) { double aij = data [ j ] ; double ajj = data [ diagind [ colind [ j ] ] ] ; if ( Math . abs ( aij ) >= eps * Math . sqrt ( aii * ajj ) ) Ni . add ( colind [ j ] ) ; } N . add ( Ni ) ; } return N ; }
Finds the strongly coupled node neighborhoods
36,247
private static boolean [ ] createInitialR ( CompRowMatrix A ) { boolean [ ] R = new boolean [ A . numRows ( ) ] ; int [ ] rowptr = A . getRowPointers ( ) ; int [ ] colind = A . getColumnIndices ( ) ; double [ ] data = A . getData ( ) ; for ( int i = 0 ; i < A . numRows ( ) ; ++ i ) { boolean hasOffDiagonal = false ; for ( int j = rowptr [ i ] ; j < rowptr [ i + 1 ] ; ++ j ) if ( colind [ j ] != i && data [ j ] != 0 ) { hasOffDiagonal = true ; break ; } R [ i ] = hasOffDiagonal ; } return R ; }
Creates the initial R - set by including only the connected nodes
36,248
private List < Set < Integer > > createInitialAggregates ( List < Set < Integer > > N , boolean [ ] R ) { C = new ArrayList < Set < Integer > > ( ) ; for ( int i = 0 ; i < R . length ; ++ i ) { if ( ! R [ i ] ) continue ; boolean free = true ; for ( int j : N . get ( i ) ) free &= R [ j ] ; if ( free ) { C . add ( new HashSet < Integer > ( N . get ( i ) ) ) ; for ( int j : N . get ( i ) ) R [ j ] = false ; } } return C ; }
Creates the initial aggregates
36,249
private static List < Set < Integer > > enlargeAggregates ( List < Set < Integer > > C , List < Set < Integer > > N , boolean [ ] R ) { List < List < Integer > > belong = new ArrayList < List < Integer > > ( R . length ) ; for ( int i = 0 ; i < R . length ; ++ i ) belong . add ( new ArrayList < Integer > ( ) ) ; for ( int k = 0 ; k < C . size ( ) ; ++ k ) for ( int j : C . get ( k ) ) belong . get ( j ) . add ( k ) ; int [ ] intersect = new int [ C . size ( ) ] ; for ( int i = 0 ; i < R . length ; ++ i ) { if ( ! R [ i ] ) continue ; Arrays . fill ( intersect , 0 ) ; int largest = 0 , maxValue = 0 ; for ( int j : N . get ( i ) ) for ( int k : belong . get ( j ) ) { intersect [ k ] ++ ; if ( intersect [ k ] > maxValue ) { largest = k ; maxValue = intersect [ largest ] ; } } if ( maxValue > 0 ) { R [ i ] = false ; C . get ( largest ) . add ( i ) ; } } return C ; }
Enlarges the aggregates
36,250
private static List < Set < Integer > > createFinalAggregates ( List < Set < Integer > > C , List < Set < Integer > > N , boolean [ ] R ) { for ( int i = 0 ; i < R . length ; ++ i ) { if ( ! R [ i ] ) continue ; Set < Integer > Cn = new HashSet < Integer > ( ) ; for ( int j : N . get ( i ) ) if ( R [ j ] ) { R [ j ] = false ; Cn . add ( j ) ; } if ( ! Cn . isEmpty ( ) ) C . add ( Cn ) ; } return C ; }
Creates final aggregates from the remaining unallocated nodes
36,251
public static SVD factorize ( Matrix A ) throws NotConvergedException { return new SVD ( A . numRows ( ) , A . numColumns ( ) ) . factor ( new DenseMatrix ( A ) ) ; }
Convenience method for computing a full SVD
36,252
public SVD factor ( DenseMatrix A ) throws NotConvergedException { if ( A . numRows ( ) != m ) throw new IllegalArgumentException ( "A.numRows() != m" ) ; else if ( A . numColumns ( ) != n ) throw new IllegalArgumentException ( "A.numColumns() != n" ) ; intW info = new intW ( 0 ) ; LAPACK . getInstance ( ) . dgesdd ( job . netlib ( ) , m , n , A . getData ( ) , Matrices . ld ( m ) , S , vectors ? U . getData ( ) : new double [ 0 ] , Matrices . ld ( m ) , vectors ? Vt . getData ( ) : new double [ 0 ] , Matrices . ld ( n ) , work , work . length , iwork , info ) ; if ( info . val > 0 ) throw new NotConvergedException ( NotConvergedException . Reason . Iterations ) ; else if ( info . val < 0 ) throw new IllegalArgumentException ( ) ; return this ; }
Computes an SVD
36,253
public static int binarySearchGreater ( int [ ] index , int key , int begin , int end ) { return binarySearchInterval ( index , key , begin , end , true ) ; }
Searches for a key in a sorted array and returns an index to an element which is greater than or equal key .
36,254
public static int binarySearchSmaller ( int [ ] index , int key , int begin , int end ) { return binarySearchInterval ( index , key , begin , end , false ) ; }
Searches for a key in a sorted array and returns an index to an element which is smaller than or equal key .
36,255
public static int binarySearch ( int [ ] index , int key , int begin , int end ) { return java . util . Arrays . binarySearch ( index , begin , end , key ) ; }
Searches for a key in a subset of a sorted array .
36,256
public static int [ ] bandwidth ( int num , int [ ] ind ) { int [ ] nz = new int [ num ] ; for ( int i = 0 ; i < ind . length ; ++ i ) nz [ ind [ i ] ] ++ ; return nz ; }
Finds the number of repeated entries
36,257
public void setColumn ( int i , SparseVector x ) { if ( x . size ( ) != numRows ) throw new IllegalArgumentException ( "New column must be of the same size as existing column" ) ; colD [ i ] = x ; }
Sets the given column equal the passed vector
36,258
public void setRow ( int i , SparseVector x ) { if ( x . size ( ) != numColumns ) throw new IllegalArgumentException ( "New row must be of the same size as existing row" ) ; rowD [ i ] = x ; }
Sets the given row equal the passed vector
36,259
public double rcond ( Matrix A ) { if ( n != A . numRows ( ) ) throw new IllegalArgumentException ( "n != A.numRows()" ) ; if ( ! A . isSquare ( ) ) throw new IllegalArgumentException ( "!A.isSquare()" ) ; double anorm = A . norm ( Norm . One ) ; double [ ] work = new double [ 3 * n ] ; int [ ] iwork = new int [ n ] ; intW info = new intW ( 0 ) ; doubleW rcond = new doubleW ( 0 ) ; if ( upper ) LAPACK . getInstance ( ) . dpocon ( UpLo . Upper . netlib ( ) , n , Cu . getData ( ) , Matrices . ld ( n ) , anorm , rcond , work , iwork , info ) ; else LAPACK . getInstance ( ) . dpocon ( UpLo . Lower . netlib ( ) , n , Cl . getData ( ) , Matrices . ld ( n ) , anorm , rcond , work , iwork , info ) ; if ( info . val < 0 ) throw new IllegalArgumentException ( ) ; return rcond . val ; }
Computes the reciprocal condition number
36,260
public static EVD factorize ( Matrix A ) throws NotConvergedException { return new EVD ( A . numRows ( ) ) . factor ( new DenseMatrix ( A ) ) ; }
Convenience method for computing the complete eigenvalue decomposition of the given matrix
36,261
public Matrix calcOrig ( ) { if ( ! Coordinates . equals ( getSource ( ) . getSize ( ) , getSize ( ) ) ) { throw new RuntimeException ( "Cannot change Matrix size. Use calc(Ret.NEW) or calc(Ret.LINK) instead." ) ; } long [ ] newCoordinates = new long [ position . length ] ; for ( long [ ] c : newContent . allCoordinates ( ) ) { Coordinates . plus ( newCoordinates , position , c ) ; getSource ( ) . setAsObject ( getObject ( newCoordinates ) , newCoordinates ) ; } getSource ( ) . fireValueChanged ( ) ; return getSource ( ) ; }
not the whole matrix
36,262
public Rectangle getCellRect ( int row , int column , boolean includeSpacing ) { Rectangle r = new Rectangle ( ) ; boolean valid = true ; if ( row < 0 ) { valid = false ; } else if ( row >= getRowCount ( ) ) { r . y = getHeight ( ) ; valid = false ; } else { r . height = getRowHeight ( row ) ; r . y = row * r . height ; } if ( column < 0 ) { if ( ! getComponentOrientation ( ) . isLeftToRight ( ) ) { r . x = getWidth ( ) ; } valid = false ; } else if ( column >= getColumnCount ( ) ) { if ( getComponentOrientation ( ) . isLeftToRight ( ) ) { r . x = getWidth ( ) ; } valid = false ; } else { TableColumnModel64 cm = getColumnModel64 ( ) ; if ( getComponentOrientation ( ) . isLeftToRight ( ) ) { for ( int i = 0 ; i < column ; i ++ ) { r . x += cm . getColumnWidth ( i ) ; } } else { for ( int i = cm . getColumnCount ( ) - 1 ; i > column ; i -- ) { r . x += cm . getColumnWidth ( i ) ; } } r . width = cm . getColumnWidth ( column ) ; } if ( valid && ! includeSpacing ) { int rm = Math . min ( getRowMargin ( ) , r . height ) ; int cm = Math . min ( getColumnModel ( ) . getColumnMargin ( ) , r . width ) ; r . setBounds ( r . x + cm / 2 , r . y + rm / 2 , r . width - cm , r . height - rm ) ; } return r ; }
must be override otherwise it will iterate over all columns
36,263
public void addEvents ( Matrix events ) { int seriesCount = getSeriesCount ( ) ; for ( int r = 0 ; r < events . getRowCount ( ) ; r ++ ) { long timestamp = events . getAsLong ( r , 0 ) ; for ( int c = 1 ; c < events . getColumnCount ( ) ; c ++ ) { double value = events . getAsDouble ( r , c ) ; addEvent ( timestamp , seriesCount + c - 1 , value ) ; } } }
Adds the events of a new Matrix to the time series . The first column of the matrix must contain the timestamps .
36,264
public void fill ( final double [ ] [ ] data , final int startRow , final int startCol ) { final int rows = data . length ; final int cols = data [ 0 ] . length ; verifyTrue ( startRow < rows && startRow < getRowCount ( ) , "illegal startRow: %s" , startRow ) ; verifyTrue ( startCol < cols && startCol < getColumnCount ( ) , "illegal startCol: %s" , startCol ) ; verifyTrue ( rows <= getRowCount ( ) , "too many rows in input: %s: max allowed = %s" , rows , getRowCount ( ) ) ; verifyTrue ( cols <= getColumnCount ( ) , "too many columns in input: %s: max allowed = %s" , cols , getColumnCount ( ) ) ; for ( int i = startRow ; i < rows ; i ++ ) { for ( int j = startCol ; j < cols ; j ++ ) { setDouble ( data [ i ] [ j ] , i , j ) ; } } }
Populate matrix with given data .
36,265
double [ ] getBlockData ( int row , int column ) { int blockNumber = layout . getBlockNumber ( row , column ) ; double [ ] block = data [ blockNumber ] ; if ( null == block ) { block = new double [ layout . getBlockSize ( row , column ) ] ; data [ blockNumber ] = block ; } return data [ blockNumber ] ; }
Get block holding the specified row and column . If none exist create one .
36,266
public Matrix mtimes ( Matrix m2 ) { if ( m2 instanceof DenseDoubleMatrix2D ) { final DenseDoubleMatrix2D result = new BlockDenseDoubleMatrix2D ( ( int ) getRowCount ( ) , ( int ) m2 . getColumnCount ( ) , layout . blockStripe , BlockOrder . ROWMAJOR ) ; Mtimes . DENSEDOUBLEMATRIX2D . calc ( this , ( DenseDoubleMatrix2D ) m2 , result ) ; return result ; } else { return super . mtimes ( m2 ) ; } }
Shortcut to create a BlockMatrix for target
36,267
public static final int nextInteger ( int min , int max ) { return min == max ? min : min + getRandom ( ) . nextInt ( max - min ) ; }
Returns a random value in the desired interval
36,268
public final < V > SynchronizedGenericMatrix < V > synchronizedMatrix ( GenericMatrix < V > matrix ) { return new SynchronizedGenericMatrix < V > ( matrix ) ; }
Wraps another Matrix so that all methods are executed synchronized .
36,269
public static boolean canSwapRows ( Matrix matrix , int row1 , int row2 , int col1 ) { boolean response = true ; for ( int col = 0 ; col < col1 ; ++ col ) { if ( 0 == matrix . getAsDouble ( row1 , col ) ) { if ( 0 != matrix . getAsDouble ( row2 , col ) ) { response = false ; break ; } } } return response ; }
Check to see if a non - zero and a zero value in the rows leading up to this column can be swapped . This is part of the bandwidth reduction algorithm .
36,270
public static boolean canSwapCols ( Matrix matrix , int col1 , int col2 , int row1 ) { boolean response = true ; for ( int row = row1 + 1 ; row < matrix . getRowCount ( ) ; ++ row ) { if ( 0 == matrix . getAsDouble ( row , col1 ) ) { if ( 0 != matrix . getAsDouble ( row , col2 ) ) { response = false ; break ; } } } return response ; }
Check to see if columns can be swapped - part of the bandwidth reduction algorithm .
36,271
public static Matrix reduce ( Matrix source ) { Matrix response = Matrix . Factory . zeros ( source . getRowCount ( ) , 1 ) ; for ( int row = 0 ; row < source . getRowCount ( ) ; ++ row ) { response . setAsDouble ( row , row , 0 ) ; } return source . getRowCount ( ) == source . getColumnCount ( ) ? Ginv . reduce ( source , response ) : response ; }
Mathematical operator to reduce the bandwidth of a HusoMatrix . The HusoMatrix must be a square HusoMatrix or no operations are performed .
36,272
public Matrix [ ] svd ( ) { GMatrix m = ( GMatrix ) matrix . clone ( ) ; int nrows = ( int ) getRowCount ( ) ; int ncols = ( int ) getColumnCount ( ) ; GMatrix u = new GMatrix ( nrows , nrows ) ; GMatrix s = new GMatrix ( nrows , ncols ) ; GMatrix v = new GMatrix ( ncols , ncols ) ; m . SVD ( u , s , v ) ; Matrix U = new VecMathDenseDoubleMatrix2D ( u ) ; Matrix S = new VecMathDenseDoubleMatrix2D ( s ) ; Matrix V = new VecMathDenseDoubleMatrix2D ( v ) ; return new Matrix [ ] { U , S , V } ; }
in S all entries on the diagonal are 1
36,273
public Matrix [ ] lu ( ) { if ( isSquare ( ) ) { GMatrix m = ( GMatrix ) matrix . clone ( ) ; GMatrix lu = ( GMatrix ) matrix . clone ( ) ; GVector piv = new GVector ( matrix . getNumCol ( ) ) ; m . LUD ( lu , piv ) ; Matrix l = new VecMathDenseDoubleMatrix2D ( lu ) . tril ( Ret . NEW , 0 ) ; for ( int i = ( int ) l . getRowCount ( ) - 1 ; i != - 1 ; i -- ) { l . setAsDouble ( 1 , i , i ) ; } Matrix u = new VecMathDenseDoubleMatrix2D ( lu ) . triu ( Ret . NEW , 0 ) ; VecMathDenseDoubleMatrix2D p = new VecMathDenseDoubleMatrix2D ( MathUtil . longToInt ( getRowCount ( ) ) , MathUtil . longToInt ( getColumnCount ( ) ) ) ; for ( int i = piv . getSize ( ) - 1 ; i != - 1 ; i -- ) { p . setDouble ( 1 , i , ( int ) piv . getElement ( i ) ) ; } return new Matrix [ ] { l , u , p } ; } else { throw new RuntimeException ( "only allowed for square matrices" ) ; } }
non - singular matrices only
36,274
private int selectBlocksPerTaskDimJ ( int blockStripe , int iMax , int jMax , int kMax ) { int adjust = ( jMax % blockStripe > 0 ) ? 1 : 0 ; if ( jMax < ( 5 * blockStripe ) || jMax <= iMax ) { return jMax / blockStripe + adjust ; } else { return Math . max ( 1 , ( jMax / blockStripe + adjust ) / 2 ) ; } }
- if set too large then may not fully exploit parallelism
36,275
public String initializedGroupStatus ( ) throws Exception { String status = null ; if ( clusteringEnabled ) { initClusterNodeStatus ( ) ; status = updateNodeStatus ( ) ; } return status ; }
Called from ClusterSyncManagerLeaderListener
36,276
@ SuppressWarnings ( "unchecked" ) protected void restoreState ( Object [ ] objects ) { if ( objects != null && objects . length != 0 ) { variable = ( Variable ) objects [ 0 ] ; constants = ( List < Variable > ) objects [ 1 ] ; lastObjectHash = ( Map < String , Object > ) objects [ 2 ] ; } }
This method is used to restore from the persisted state
36,277
private static final long gatherLongLE ( final byte [ ] data , final int index ) { int i1 = gatherIntLE ( data , index ) ; long l2 = gatherIntLE ( data , index + 4 ) ; return uintToLong ( i1 ) | ( l2 << 32 ) ; }
gather a long from the specified index into the byte array
36,278
private static final long gatherPartialLongLE ( final byte [ ] data , final int index , final int available ) { if ( available >= 4 ) { int i = gatherIntLE ( data , index ) ; long l = uintToLong ( i ) ; int left = available - 4 ; if ( left == 0 ) { return l ; } int i2 = gatherPartialIntLE ( data , index + 4 , left ) ; l <<= ( left << 3 ) ; l |= ( long ) i2 ; return l ; } else { return ( long ) gatherPartialIntLE ( data , index , available ) ; } }
gather a partial long from the specified index using the specified number of bytes into the byte array
36,279
private static final int gatherIntLE ( final byte [ ] data , final int index ) { int i = data [ index ] & 0xFF ; i |= ( data [ index + 1 ] & 0xFF ) << 8 ; i |= ( data [ index + 2 ] & 0xFF ) << 16 ; i |= ( data [ index + 3 ] << 24 ) ; return i ; }
gather an int from the specified index into the byte array
36,280
private static final int gatherPartialIntLE ( final byte [ ] data , final int index , final int available ) { int i = data [ index ] & 0xFF ; if ( available > 1 ) { i |= ( data [ index + 1 ] & 0xFF ) << 8 ; if ( available > 2 ) { i |= ( data [ index + 2 ] & 0xFF ) << 16 ; } } return i ; }
gather a partial int from the specified index using the specified number of bytes into the byte array
36,281
public static Map < Method , Method > findManagedMethods ( Class < ? > clazz ) { Map < Method , Method > result = new HashMap < > ( ) ; for ( Method method : clazz . getMethods ( ) ) { if ( method . isSynthetic ( ) || method . isBridge ( ) ) { continue ; } Method managedMethod = findManagedMethod ( clazz , method . getName ( ) , method . getParameterTypes ( ) ) ; if ( managedMethod != null ) { result . put ( method , managedMethod ) ; } } return result ; }
Find methods that are tagged as managed somewhere in the hierarchy
36,282
public Map < String , Exception > unexportAllAndReportMissing ( ) { Map < String , Exception > errors = new HashMap < > ( ) ; synchronized ( exportedObjects ) { List < ObjectName > toRemove = new ArrayList < > ( exportedObjects . size ( ) ) ; for ( ObjectName objectName : exportedObjects . keySet ( ) ) { try { server . unregisterMBean ( objectName ) ; toRemove . add ( objectName ) ; } catch ( InstanceNotFoundException e ) { toRemove . add ( objectName ) ; } catch ( MBeanRegistrationException e ) { errors . put ( objectName . toString ( ) , e ) ; } } exportedObjects . keySet ( ) . removeAll ( toRemove ) ; } return errors ; }
Unexports all MBeans that have been exported through this MBeanExporter .
36,283
public static int byteArrayToInt ( final byte [ ] byteArray , final int startPos , final int length ) { if ( byteArray == null ) { throw new IllegalArgumentException ( "Parameter 'byteArray' cannot be null" ) ; } if ( length <= 0 || length > 4 ) { throw new IllegalArgumentException ( "Length must be between 1 and 4. Length = " + length ) ; } if ( startPos < 0 || byteArray . length < startPos + length ) { throw new IllegalArgumentException ( "Length or startPos not valid" ) ; } int value = 0 ; for ( int i = 0 ; i < length ; i ++ ) { value += ( byteArray [ startPos + i ] & 0xFF ) << 8 * ( length - i - 1 ) ; } return value ; }
Method used to convert byte array to int
36,284
private static String formatByte ( final byte [ ] pByte , final boolean pSpace , final boolean pTruncate ) { String result ; if ( pByte == null ) { result = "" ; } else { int i = 0 ; if ( pTruncate ) { while ( i < pByte . length && pByte [ i ] == 0 ) { i ++ ; } } if ( i < pByte . length ) { int sizeMultiplier = pSpace ? 3 : 2 ; char [ ] c = new char [ ( pByte . length - i ) * sizeMultiplier ] ; byte b ; for ( int j = 0 ; i < pByte . length ; i ++ , j ++ ) { b = ( byte ) ( ( pByte [ i ] & LEFT_MASK ) >> 4 ) ; c [ j ] = ( char ) ( b > 9 ? b + CHAR_DIGIT_SEVEN : b + CHAR_DIGIT_ZERO ) ; b = ( byte ) ( pByte [ i ] & RIGHT_MASK ) ; c [ ++ j ] = ( char ) ( b > 9 ? b + CHAR_DIGIT_SEVEN : b + CHAR_DIGIT_ZERO ) ; if ( pSpace ) { c [ ++ j ] = CHAR_SPACE ; } } result = pSpace ? new String ( c , 0 , c . length - 1 ) : new String ( c ) ; } else { result = "" ; } } return result ; }
Private method to format bytes to hexa string
36,285
public static byte [ ] fromString ( final String pData ) { if ( pData == null ) { throw new IllegalArgumentException ( "Argument can't be null" ) ; } StringBuilder sb = new StringBuilder ( pData ) ; int j = 0 ; for ( int i = 0 ; i < sb . length ( ) ; i ++ ) { if ( ! Character . isWhitespace ( sb . charAt ( i ) ) ) { sb . setCharAt ( j ++ , sb . charAt ( i ) ) ; } } sb . delete ( j , sb . length ( ) ) ; if ( sb . length ( ) % 2 != 0 ) { throw new IllegalArgumentException ( "Hex binary needs to be even-length :" + pData ) ; } byte [ ] result = new byte [ sb . length ( ) / 2 ] ; j = 0 ; for ( int i = 0 ; i < sb . length ( ) ; i += 2 ) { result [ j ++ ] = ( byte ) ( ( Character . digit ( sb . charAt ( i ) , 16 ) << 4 ) + Character . digit ( sb . charAt ( i + 1 ) , 16 ) ) ; } return result ; }
Method to get bytes form string
36,286
public static boolean matchBitByBitIndex ( final int pVal , final int pBitIndex ) { if ( pBitIndex < 0 || pBitIndex > MAX_BIT_INTEGER ) { throw new IllegalArgumentException ( "parameter 'pBitIndex' must be between 0 and 31. pBitIndex=" + pBitIndex ) ; } return ( pVal & 1 << pBitIndex ) != 0 ; }
Test if bit at given index of given value is = 1 .
36,287
public static byte setBit ( final byte pData , final int pBitIndex , final boolean pOn ) { if ( pBitIndex < 0 || pBitIndex > 7 ) { throw new IllegalArgumentException ( "parameter 'pBitIndex' must be between 0 and 7. pBitIndex=" + pBitIndex ) ; } byte ret = pData ; if ( pOn ) { ret |= 1 << pBitIndex ; } else { ret &= ~ ( 1 << pBitIndex ) ; } return ret ; }
Method used to set a bit index to 1 or 0 .
36,288
public static String toBinary ( final byte [ ] pBytes ) { String ret = null ; if ( pBytes != null && pBytes . length > 0 ) { BigInteger val = new BigInteger ( bytesToStringNoSpace ( pBytes ) , HEXA ) ; StringBuilder build = new StringBuilder ( val . toString ( 2 ) ) ; for ( int i = build . length ( ) ; i < pBytes . length * BitUtils . BYTE_SIZE ; i ++ ) { build . insert ( 0 , 0 ) ; } ret = build . toString ( ) ; } return ret ; }
Convert byte array to binary String
36,289
public byte [ ] getData ( ) { byte [ ] ret = new byte [ byteTab . length ] ; System . arraycopy ( byteTab , 0 , ret , 0 , byteTab . length ) ; return ret ; }
Method to get all data
36,290
public byte getMask ( final int pIndex , final int pLength ) { byte ret = ( byte ) DEFAULT_VALUE ; ret = ( byte ) ( ret << pIndex ) ; ret = ( byte ) ( ( ret & DEFAULT_VALUE ) >> pIndex ) ; int dec = BYTE_SIZE - ( pLength + pIndex ) ; if ( dec > 0 ) { ret = ( byte ) ( ret >> dec ) ; ret = ( byte ) ( ret << dec ) ; } return ret ; }
This method is used to get a mask dynamically
36,291
public byte [ ] getNextByte ( final int pSize , final boolean pShift ) { byte [ ] tab = new byte [ ( int ) Math . ceil ( pSize / BYTE_SIZE_F ) ] ; if ( currentBitIndex % BYTE_SIZE != 0 ) { int index = 0 ; int max = currentBitIndex + pSize ; while ( currentBitIndex < max ) { int mod = currentBitIndex % BYTE_SIZE ; int modTab = index % BYTE_SIZE ; int length = Math . min ( max - currentBitIndex , Math . min ( BYTE_SIZE - mod , BYTE_SIZE - modTab ) ) ; byte val = ( byte ) ( byteTab [ currentBitIndex / BYTE_SIZE ] & getMask ( mod , length ) ) ; if ( pShift || pSize % BYTE_SIZE == 0 ) { if ( mod != 0 ) { val = ( byte ) ( val << Math . min ( mod , BYTE_SIZE - length ) ) ; } else { val = ( byte ) ( ( val & DEFAULT_VALUE ) >> modTab ) ; } } tab [ index / BYTE_SIZE ] |= val ; currentBitIndex += length ; index += length ; } if ( ! pShift && pSize % BYTE_SIZE != 0 ) { tab [ tab . length - 1 ] = ( byte ) ( tab [ tab . length - 1 ] & getMask ( ( max - pSize - 1 ) % BYTE_SIZE , BYTE_SIZE ) ) ; } } else { System . arraycopy ( byteTab , currentBitIndex / BYTE_SIZE , tab , 0 , tab . length ) ; int val = pSize % BYTE_SIZE ; if ( val == 0 ) { val = BYTE_SIZE ; } tab [ tab . length - 1 ] = ( byte ) ( tab [ tab . length - 1 ] & getMask ( currentBitIndex % BYTE_SIZE , val ) ) ; currentBitIndex += pSize ; } return tab ; }
Method to get The next bytes with the specified size
36,292
public Date getNextDate ( final int pSize , final String pPattern , final boolean pUseBcd ) { Date date = null ; SimpleDateFormat sdf = new SimpleDateFormat ( pPattern ) ; String dateTxt = null ; if ( pUseBcd ) { dateTxt = getNextHexaString ( pSize ) ; } else { dateTxt = getNextString ( pSize ) ; } try { date = sdf . parse ( dateTxt ) ; } catch ( ParseException e ) { LOGGER . error ( "Parsing date error. date:" + dateTxt + " pattern:" + pPattern , e ) ; } return date ; }
Method to get the next date
36,293
public long getNextLongSigned ( final int pLength ) { if ( pLength > Long . SIZE ) { throw new IllegalArgumentException ( "Long overflow with length > 64" ) ; } long decimal = getNextLong ( pLength ) ; long signMask = 1 << pLength - 1 ; if ( ( decimal & signMask ) != 0 ) { return - ( signMask - ( signMask ^ decimal ) ) ; } return decimal ; }
Method used to get get a signed long with the specified size
36,294
public long getNextLong ( final int pLength ) { ByteBuffer buffer = ByteBuffer . allocate ( BYTE_SIZE * 2 ) ; long finalValue = 0 ; long currentValue = 0 ; int readSize = pLength ; int max = currentBitIndex + pLength ; while ( currentBitIndex < max ) { int mod = currentBitIndex % BYTE_SIZE ; currentValue = byteTab [ currentBitIndex / BYTE_SIZE ] & getMask ( mod , readSize ) & DEFAULT_VALUE ; int dec = Math . max ( BYTE_SIZE - ( mod + readSize ) , 0 ) ; currentValue = ( currentValue & DEFAULT_VALUE ) >>> dec & DEFAULT_VALUE ; finalValue = finalValue << Math . min ( readSize , BYTE_SIZE ) | currentValue ; int val = BYTE_SIZE - mod ; readSize = readSize - val ; currentBitIndex = Math . min ( currentBitIndex + val , max ) ; } buffer . putLong ( finalValue ) ; buffer . rewind ( ) ; return buffer . getLong ( ) ; }
This method is used to get a long with the specified size
36,295
public String getNextString ( final int pSize , final Charset pCharset ) { return new String ( getNextByte ( pSize , true ) , pCharset ) ; }
This method is used to get the next String with the specified size
36,296
public void resetNextBits ( final int pLength ) { int max = currentBitIndex + pLength ; while ( currentBitIndex < max ) { int mod = currentBitIndex % BYTE_SIZE ; int length = Math . min ( max - currentBitIndex , BYTE_SIZE - mod ) ; byteTab [ currentBitIndex / BYTE_SIZE ] &= ~ getMask ( mod , length ) ; currentBitIndex += length ; } }
Set to 0 the next N bits
36,297
public void setNextByte ( final byte [ ] pValue , final int pLength , final boolean pPadBefore ) { int totalSize = ( int ) Math . ceil ( pLength / BYTE_SIZE_F ) ; ByteBuffer buffer = ByteBuffer . allocate ( totalSize ) ; int size = Math . max ( totalSize - pValue . length , 0 ) ; if ( pPadBefore ) { for ( int i = 0 ; i < size ; i ++ ) { buffer . put ( ( byte ) 0 ) ; } } buffer . put ( pValue , 0 , Math . min ( totalSize , pValue . length ) ) ; if ( ! pPadBefore ) { for ( int i = 0 ; i < size ; i ++ ) { buffer . put ( ( byte ) 0 ) ; } } byte tab [ ] = buffer . array ( ) ; if ( currentBitIndex % BYTE_SIZE != 0 ) { int index = 0 ; int max = currentBitIndex + pLength ; while ( currentBitIndex < max ) { int mod = currentBitIndex % BYTE_SIZE ; int modTab = index % BYTE_SIZE ; int length = Math . min ( max - currentBitIndex , Math . min ( BYTE_SIZE - mod , BYTE_SIZE - modTab ) ) ; byte val = ( byte ) ( tab [ index / BYTE_SIZE ] & getMask ( modTab , length ) ) ; if ( mod == 0 ) { val = ( byte ) ( val << Math . min ( modTab , BYTE_SIZE - length ) ) ; } else { val = ( byte ) ( ( val & DEFAULT_VALUE ) >> mod ) ; } byteTab [ currentBitIndex / BYTE_SIZE ] |= val ; currentBitIndex += length ; index += length ; } } else { System . arraycopy ( tab , 0 , byteTab , currentBitIndex / BYTE_SIZE , tab . length ) ; currentBitIndex += pLength ; } }
Method to write bytes with the max length
36,298
public void setNextDate ( final Date pValue , final String pPattern , final boolean pUseBcd ) { SimpleDateFormat sdf = new SimpleDateFormat ( pPattern ) ; String value = sdf . format ( pValue ) ; if ( pUseBcd ) { setNextHexaString ( value , value . length ( ) * 4 ) ; } else { setNextString ( value , value . length ( ) * 8 ) ; } }
Method to write a date
36,299
public void setNextLong ( final long pValue , final int pLength ) { if ( pLength > Long . SIZE ) { throw new IllegalArgumentException ( "Long overflow with length > 64" ) ; } setNextValue ( pValue , pLength , Long . SIZE - 1 ) ; }
Add Long to the current position with the specified size