idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
25,700
public static void changeSign ( DMatrixSparseCSC A , DMatrixSparseCSC B ) { if ( A != B ) { B . copyStructure ( A ) ; } for ( int i = 0 ; i < A . nz_length ; i ++ ) { B . nz_values [ i ] = - A . nz_values [ i ] ; } }
B = - A . Changes the sign of elements in A and stores it in B . A and B can be the same instance .
25,701
public static double elementMin ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double min = A . isFull ( ) ? A . nz_values [ 0 ] : 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { double val = A . nz_values [ i ] ; if ( val < min ) { min = val ; } } return min ; }
Returns the value of the element with the minimum value
25,702
public static double elementMax ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double max = A . isFull ( ) ? A . nz_values [ 0 ] : 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { double val = A . nz_values [ i ] ; if ( val > max ) { max = val ; } } return max ; }
Returns the value of the element with the largest value
25,703
public static double elementSum ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double sum = 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { sum += A . nz_values [ i ] ; } return sum ; }
Sum of all elements
25,704
public static void columnMaxAbs ( DMatrixSparseCSC A , double [ ] values ) { if ( values . length < A . numCols ) throw new IllegalArgumentException ( "Array is too small. " + values . length + " < " + A . numCols ) ; for ( int i = 0 ; i < A . numCols ; i ++ ) { int idx0 = A . col_idx [ i ] ; int idx1 = A . col_idx [ i...
Finds the maximum abs in each column of A and stores it into values
25,705
public static DMatrixSparseCSC diag ( double ... values ) { int N = values . length ; return diag ( new DMatrixSparseCSC ( N , N , N ) , values , 0 , N ) ; }
Returns a diagonal matrix with the specified diagonal elements .
25,706
public static void permutationVector ( DMatrixSparseCSC P , int [ ] vector ) { if ( P . numCols != P . numRows ) { throw new MatrixDimensionException ( "Expected a square matrix" ) ; } else if ( P . nz_length != P . numCols ) { throw new IllegalArgumentException ( "Expected N non-zero elements in permutation matrix" ) ...
Converts the permutation matrix into a vector
25,707
public static void permutationInverse ( int [ ] original , int [ ] inverse , int length ) { for ( int i = 0 ; i < length ; i ++ ) { inverse [ original [ i ] ] = i ; } }
Computes the inverse permutation vector
25,708
public static void zero ( DMatrixSparseCSC A , int row0 , int row1 , int col0 , int col1 ) { for ( int col = col1 - 1 ; col >= col0 ; col -- ) { int numRemoved = 0 ; int idx0 = A . col_idx [ col ] , idx1 = A . col_idx [ col + 1 ] ; for ( int i = idx0 ; i < idx1 ; i ++ ) { int row = A . nz_rows [ i ] ; if ( row >= row0 ...
Zeros an inner rectangle inside the matrix .
25,709
public static void removeZeros ( DMatrixSparseCSC input , DMatrixSparseCSC output , double tol ) { ImplCommonOps_DSCC . removeZeros ( input , output , tol ) ; }
Copies all elements from input into output which are &gt ; tol .
25,710
public void growMaxLength ( int arrayLength , boolean preserveValue ) { if ( arrayLength < 0 ) throw new IllegalArgumentException ( "Negative array length. Overflow?" ) ; if ( numRows != 0 && numCols <= Integer . MAX_VALUE / numRows ) { arrayLength = Math . min ( numRows * numCols , arrayLength ) ; } if ( nz_values == ...
Increases the maximum size of the data array so that it can store sparse data up to length . The class parameter nz_length is not modified by this function call .
25,711
public void growMaxColumns ( int desiredColumns , boolean preserveValue ) { if ( col_idx . length < desiredColumns + 1 ) { int [ ] c = new int [ desiredColumns + 1 ] ; if ( preserveValue ) System . arraycopy ( col_idx , 0 , c , 0 , col_idx . length ) ; col_idx = c ; } }
Increases the maximum number of columns in the matrix .
25,712
public void histogramToStructure ( int histogram [ ] ) { col_idx [ 0 ] = 0 ; int index = 0 ; for ( int i = 1 ; i <= numCols ; i ++ ) { col_idx [ i ] = index += histogram [ i - 1 ] ; } nz_length = index ; growMaxLength ( nz_length , false ) ; if ( col_idx [ numCols ] != nz_length ) throw new RuntimeException ( "Egads" )...
Given the histogram of columns compute the col_idx for the matrix . nz_length is automatically set and nz_values will grow if needed .
25,713
public void sortIndices ( SortCoupledArray_F64 sorter ) { if ( sorter == null ) sorter = new SortCoupledArray_F64 ( ) ; sorter . quick ( col_idx , numCols + 1 , nz_rows , nz_values ) ; indicesSorted = true ; }
Sorts the row indices in ascending order .
25,714
public void copyStructure ( DMatrixSparseCSC orig ) { reshape ( orig . numRows , orig . numCols , orig . nz_length ) ; this . nz_length = orig . nz_length ; System . arraycopy ( orig . col_idx , 0 , col_idx , 0 , orig . numCols + 1 ) ; System . arraycopy ( orig . nz_rows , 0 , nz_rows , 0 , orig . nz_length ) ; }
Copies the non - zero structure of orig into this
25,715
public static boolean bidiagOuterBlocks ( final int blockLength , final DSubmatrixD1 A , final double gammasU [ ] , final double gammasV [ ] ) { int width = Math . min ( blockLength , A . col1 - A . col0 ) ; int height = Math . min ( blockLength , A . row1 - A . row0 ) ; int min = Math . min ( width , height ) ; for ( ...
Performs a standard bidiagonal decomposition just on the outer blocks of the provided matrix
25,716
public boolean setA ( DMatrixRBlock A ) { if ( ! decomposer . decompose ( A ) ) return false ; blockLength = A . blockLength ; return true ; }
Decomposes and overwrites the input matrix .
25,717
public void solve ( DMatrixRBlock B , DMatrixRBlock X ) { if ( B . blockLength != blockLength ) throw new IllegalArgumentException ( "Unexpected blocklength in B." ) ; DSubmatrixD1 L = new DSubmatrixD1 ( decomposer . getT ( null ) ) ; if ( X != null ) { if ( X . blockLength != blockLength ) throw new IllegalArgumentExc...
If X == null then the solution is written into B . Otherwise the solution is copied from B into X .
25,718
public void growInternal ( int amount ) { int tmp [ ] = new int [ data . length + amount ] ; System . arraycopy ( data , 0 , tmp , 0 , data . length ) ; this . data = tmp ; }
Increases the internal array s length by the specified amount . Previous values are preserved . The length value is not modified since this does not change the meaning of the array just increases the amount of data which can be stored in it .
25,719
public static boolean lower ( double [ ] T , int indexT , int n ) { double el_ii ; double div_el_ii = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { double sum = T [ indexT + j * n + i ] ; for ( int k = 0 ; k < i ; k ++ ) { sum -= T [ indexT + i * n + k ] * T [ indexT + j * n + k ] ; } if ( i...
Performs an inline lower Cholesky decomposition on an inner row - major matrix . Only the lower triangular portion of the matrix is read or written to .
25,720
public static LinearSolverDense < DMatrixRMaj > general ( int numRows , int numCols ) { if ( numRows == numCols ) return linear ( numRows ) ; else return leastSquares ( numRows , numCols ) ; }
Creates a general purpose solver . Use this if you are not sure what you need .
25,721
public static LinearSolverDense < DMatrixRMaj > symmPosDef ( int matrixWidth ) { if ( matrixWidth < EjmlParameters . SWITCH_BLOCK64_CHOLESKY ) { CholeskyDecompositionCommon_DDRM decomp = new CholeskyDecompositionInner_DDRM ( true ) ; return new LinearSolverChol_DDRM ( decomp ) ; } else { if ( EjmlParameters . MEMORY ==...
Creates a solver for symmetric positive definite matrices .
25,722
public void setConvergence ( int maxIterations , double ftol , double gtol ) { this . maxIterations = maxIterations ; this . ftol = ftol ; this . gtol = gtol ; }
Specifies convergence criteria
25,723
private void computeGradientAndHessian ( DMatrixRMaj param ) { function . compute ( param , residuals ) ; computeNumericalJacobian ( param , jacobian ) ; CommonOps_DDRM . multTransA ( jacobian , residuals , g ) ; CommonOps_DDRM . multTransA ( jacobian , jacobian , H ) ; CommonOps_DDRM . extractDiag ( H , Hdiag ) ; }
Computes the d and H parameters .
25,724
public static DMatrixRMaj wrap ( int numRows , int numCols , double [ ] data ) { DMatrixRMaj s = new DMatrixRMaj ( ) ; s . data = data ; s . numRows = numRows ; s . numCols = numCols ; return s ; }
Creates a new DMatrixRMaj around the provided data . The data must encode a row - major matrix . Any modification to the returned matrix will modify the provided data .
25,725
public void add ( int row , int col , double value ) { if ( col < 0 || col >= numCols || row < 0 || row >= numRows ) { throw new IllegalArgumentException ( "Specified element is out of bounds" ) ; } data [ row * numCols + col ] += value ; }
todo move to commonops
25,726
public double get ( int row , int col ) { if ( col < 0 || col >= numCols || row < 0 || row >= numRows ) { throw new IllegalArgumentException ( "Specified element is out of bounds: " + row + " " + col ) ; } return data [ row * numCols + col ] ; }
Returns the value of the specified matrix element . Performs a bounds check to make sure the requested element is part of the matrix .
25,727
public void set ( int numRows , int numCols , boolean rowMajor , double ... data ) { reshape ( numRows , numCols ) ; int length = numRows * numCols ; if ( length > this . data . length ) throw new IllegalArgumentException ( "The length of this matrix's data array is too small." ) ; if ( rowMajor ) { System . arraycopy ...
Sets this matrix equal to the matrix encoded in the array .
25,728
public void solve ( DMatrixRMaj B , DMatrixRMaj X ) { blockB . reshape ( B . numRows , B . numCols , false ) ; MatrixOps_DDRB . convert ( B , blockB ) ; alg . solve ( blockB , null ) ; MatrixOps_DDRB . convert ( blockB , X ) ; }
Only converts the B matrix and passes that onto solve . Te result is then copied into the input X matrix .
25,729
public List < Complex_F64 > getEigenvalues ( ) { List < Complex_F64 > ret = new ArrayList < Complex_F64 > ( ) ; if ( is64 ) { EigenDecomposition_F64 d = ( EigenDecomposition_F64 ) eig ; for ( int i = 0 ; i < eig . getNumberOfEigenvalues ( ) ; i ++ ) { ret . add ( d . getEigenvalue ( i ) ) ; } } else { EigenDecompositio...
Returns a list of all the eigenvalues
25,730
public int getIndexMax ( ) { int indexMax = 0 ; double max = getEigenvalue ( 0 ) . getMagnitude2 ( ) ; final int N = getNumberOfEigenvalues ( ) ; for ( int i = 1 ; i < N ; i ++ ) { double m = getEigenvalue ( i ) . getMagnitude2 ( ) ; if ( m > max ) { max = m ; indexMax = i ; } } return indexMax ; }
Returns the index of the eigenvalue which has the largest magnitude .
25,731
public int getIndexMin ( ) { int indexMin = 0 ; double min = getEigenvalue ( 0 ) . getMagnitude2 ( ) ; final int N = getNumberOfEigenvalues ( ) ; for ( int i = 1 ; i < N ; i ++ ) { double m = getEigenvalue ( i ) . getMagnitude2 ( ) ; if ( m < min ) { min = m ; indexMin = i ; } } return indexMin ; }
Returns the index of the eigenvalue which has the smallest magnitude .
25,732
public boolean process ( DMatrixSparseCSC A ) { init ( A ) ; TriangularSolver_DSCC . eliminationTree ( A , true , parent , gwork ) ; countNonZeroInR ( parent ) ; countNonZeroInV ( parent ) ; if ( m < n ) { for ( int row = 0 ; row < m ; row ++ ) { if ( gwork . data [ head + row ] < 0 ) { return false ; } } } return true...
Examins the structure of A for QR decomposition
25,733
void init ( DMatrixSparseCSC A ) { this . A = A ; this . m = A . numRows ; this . n = A . numCols ; this . next = 0 ; this . head = m ; this . tail = m + n ; this . nque = m + 2 * n ; if ( parent . length < n || leftmost . length < m ) { parent = new int [ n ] ; post = new int [ n ] ; pinv = new int [ m + n ] ; countsR...
Initializes data structures
25,734
void countNonZeroInR ( int [ ] parent ) { TriangularSolver_DSCC . postorder ( parent , n , post , gwork ) ; columnCounts . process ( A , parent , post , countsR ) ; nz_in_R = 0 ; for ( int k = 0 ; k < n ; k ++ ) { nz_in_R += countsR [ k ] ; } if ( nz_in_R < 0 ) throw new RuntimeException ( "Too many elements. Numerical...
Count the number of non - zero elements in R
25,735
void countNonZeroInV ( int [ ] parent ) { int [ ] w = gwork . data ; findMinElementIndexInRows ( leftmost ) ; createRowElementLinkedLists ( leftmost , w ) ; countNonZeroUsingLinkedList ( parent , w ) ; }
Count the number of non - zero elements in V
25,736
void countNonZeroUsingLinkedList ( int parent [ ] , int ll [ ] ) { Arrays . fill ( pinv , 0 , m , - 1 ) ; nz_in_V = 0 ; m2 = m ; for ( int k = 0 ; k < n ; k ++ ) { int i = ll [ head + k ] ; nz_in_V ++ ; if ( i < 0 ) i = m2 ++ ; pinv [ i ] = k ; if ( -- ll [ nque + k ] <= 0 ) continue ; nz_in_V += ll [ nque + k ] ; int ...
Non - zero counts of Householder vectors and computes a permutation matrix that ensures diagonal entires are all structurally nonzero .
25,737
public void alias ( DMatrixRMaj variable , String name ) { if ( isReserved ( name ) ) throw new RuntimeException ( "Reserved word or contains a reserved character" ) ; VariableMatrix old = ( VariableMatrix ) variables . get ( name ) ; if ( old == null ) { variables . put ( name , new VariableMatrix ( variable ) ) ; } e...
Adds a new Matrix variable . If one already has the same name it is written over .
25,738
public void alias ( double value , String name ) { if ( isReserved ( name ) ) throw new RuntimeException ( "Reserved word or contains a reserved character. '" + name + "'" ) ; VariableDouble old = ( VariableDouble ) variables . get ( name ) ; if ( old == null ) { variables . put ( name , new VariableDouble ( value ) ) ...
Adds a new floating point variable . If one already has the same name it is written over .
25,739
public void alias ( Object ... args ) { if ( args . length % 2 == 1 ) throw new RuntimeException ( "Even number of arguments expected" ) ; for ( int i = 0 ; i < args . length ; i += 2 ) { aliasGeneric ( args [ i ] , ( String ) args [ i + 1 ] ) ; } }
Creates multiple aliases at once .
25,740
protected void aliasGeneric ( Object variable , String name ) { if ( variable . getClass ( ) == Integer . class ) { alias ( ( ( Integer ) variable ) . intValue ( ) , name ) ; } else if ( variable . getClass ( ) == Double . class ) { alias ( ( ( Double ) variable ) . doubleValue ( ) , name ) ; } else if ( variable . get...
Aliases variables with an unknown type .
25,741
public Sequence compile ( String equation , boolean assignment , boolean debug ) { functions . setManagerTemp ( managerTemp ) ; Sequence sequence = new Sequence ( ) ; TokenList tokens = extractTokens ( equation , managerTemp ) ; if ( tokens . size ( ) < 3 ) throw new RuntimeException ( "Too few tokens" ) ; TokenList . ...
Parses the equation and compiles it into a sequence which can be executed later on
25,742
private void parseMacro ( TokenList tokens , Sequence sequence ) { Macro macro = new Macro ( ) ; TokenList . Token t = tokens . getFirst ( ) . next ; if ( t . word == null ) { throw new ParseError ( "Expected the macro's name after " + tokens . getFirst ( ) . word ) ; } List < TokenList . Token > variableTokens = new A...
Parse a macro defintion .
25,743
private void checkForUnknownVariables ( TokenList tokens ) { TokenList . Token t = tokens . getFirst ( ) ; while ( t != null ) { if ( t . getType ( ) == Type . WORD ) throw new ParseError ( "Unknown variable on right side. " + t . getWord ( ) ) ; t = t . next ; } }
Examines the list of variables for any unknown variables and throws an exception if one is found
25,744
private Variable createVariableInferred ( TokenList . Token t0 , Variable variableRight ) { Variable result ; if ( t0 . getType ( ) == Type . WORD ) { switch ( variableRight . getType ( ) ) { case MATRIX : alias ( new DMatrixRMaj ( 1 , 1 ) , t0 . getWord ( ) ) ; break ; case SCALAR : if ( variableRight instanceof Varia...
Infer the type of and create a new output variable using the results from the right side of the equation . If the type is already known just return that .
25,745
private List < Variable > parseAssignRange ( Sequence sequence , TokenList tokens , TokenList . Token t0 ) { TokenList . Token tokenAssign = t0 . next ; while ( tokenAssign != null && tokenAssign . symbol != Symbol . ASSIGN ) { tokenAssign = tokenAssign . next ; } if ( tokenAssign == null ) throw new ParseError ( "Can'...
See if a range for assignment is specified . If so return the range otherwise return null
25,746
protected void handleParentheses ( TokenList tokens , Sequence sequence ) { List < TokenList . Token > left = new ArrayList < TokenList . Token > ( ) ; TokenList . Token t = tokens . first ; while ( t != null ) { TokenList . Token next = t . next ; if ( t . getType ( ) == Type . SYMBOL ) { if ( t . getSymbol ( ) == Sym...
Searches for pairs of parentheses and processes blocks inside of them . Embedded parentheses are handled with no problem . On output only a single token should be in tokens .
25,747
protected List < TokenList . Token > parseParameterCommaBlock ( TokenList tokens , Sequence sequence ) { List < TokenList . Token > commas = new ArrayList < TokenList . Token > ( ) ; TokenList . Token token = tokens . first ; int numBracket = 0 ; while ( token != null ) { if ( token . getType ( ) == Type . SYMBOL ) { s...
Searches for commas in the set of tokens . Used for inputs to functions .
25,748
protected TokenList . Token parseSubmatrixToExtract ( TokenList . Token variableTarget , TokenList tokens , Sequence sequence ) { List < TokenList . Token > inputs = parseParameterCommaBlock ( tokens , sequence ) ; List < Variable > variables = new ArrayList < Variable > ( ) ; variables . add ( variableTarget . getVari...
Converts a submatrix into an extract matrix operation .
25,749
private void addSubMatrixVariables ( List < TokenList . Token > inputs , List < Variable > variables ) { for ( int i = 0 ; i < inputs . size ( ) ; i ++ ) { TokenList . Token t = inputs . get ( i ) ; if ( t . getType ( ) != Type . VARIABLE ) throw new ParseError ( "Expected variables only in sub-matrix input, not " + t ...
Goes through the token lists and adds all the variables which can be used to define a sub - matrix . If anything else is found an excpetion is thrown
25,750
protected TokenList . Token parseBlockNoParentheses ( TokenList tokens , Sequence sequence , boolean insideMatrixConstructor ) { if ( ! insideMatrixConstructor ) { parseBracketCreateMatrix ( tokens , sequence ) ; } parseSequencesWithColons ( tokens , sequence ) ; parseNegOp ( tokens , sequence ) ; parseOperationsL ( to...
Parses a code block with no parentheses and no commas . After it is done there should be a single token left which is returned .
25,751
private void stripCommas ( TokenList tokens ) { TokenList . Token t = tokens . getFirst ( ) ; while ( t != null ) { TokenList . Token next = t . next ; if ( t . getSymbol ( ) == Symbol . COMMA ) { tokens . remove ( t ) ; } t = next ; } }
Removes all commas from the token list
25,752
protected void parseSequencesWithColons ( TokenList tokens , Sequence sequence ) { TokenList . Token t = tokens . getFirst ( ) ; if ( t == null ) return ; int state = 0 ; TokenList . Token start = null ; TokenList . Token middle = null ; TokenList . Token prev = t ; boolean last = false ; while ( true ) { if ( state ==...
Searches for descriptions of integer sequences and array ranges that have a colon character in them
25,753
protected void parseIntegerLists ( TokenList tokens ) { TokenList . Token t = tokens . getFirst ( ) ; if ( t == null || t . next == null ) return ; int state = 0 ; TokenList . Token start = null ; TokenList . Token prev = t ; boolean last = false ; while ( true ) { if ( state == 0 ) { if ( isVariableInteger ( t ) ) { s...
Searches for a sequence of integers
25,754
protected void parseCombineIntegerLists ( TokenList tokens ) { TokenList . Token t = tokens . getFirst ( ) ; if ( t == null || t . next == null ) return ; int numFound = 0 ; TokenList . Token start = null ; TokenList . Token end = null ; while ( t != null ) { if ( t . getType ( ) == Type . VARIABLE && ( isVariableInteg...
Looks for sequences of integer lists and combine them into one big sequence
25,755
private static boolean isVariableInteger ( TokenList . Token t ) { if ( t == null ) return false ; return t . getScalarType ( ) == VariableScalar . Type . INTEGER ; }
Checks to see if the token is an integer scalar
25,756
protected void parseBracketCreateMatrix ( TokenList tokens , Sequence sequence ) { List < TokenList . Token > left = new ArrayList < TokenList . Token > ( ) ; TokenList . Token t = tokens . getFirst ( ) ; while ( t != null ) { TokenList . Token next = t . next ; if ( t . getSymbol ( ) == Symbol . BRACKET_LEFT ) { left ...
Searches for brackets which are only used to construct new matrices by concatenating 1 or more matrices together
25,757
protected void parseNegOp ( TokenList tokens , Sequence sequence ) { if ( tokens . size == 0 ) return ; TokenList . Token token = tokens . first ; while ( token != null ) { TokenList . Token next = token . next ; escape : if ( token . getSymbol ( ) == Symbol . MINUS ) { if ( token . previous != null && token . previous...
Searches for cases where a minus sign means negative operator . That happens when there is a minus sign with a variable to its right and no variable to its left
25,758
protected void parseOperationsL ( TokenList tokens , Sequence sequence ) { if ( tokens . size == 0 ) return ; TokenList . Token token = tokens . first ; if ( token . getType ( ) != Type . VARIABLE ) throw new ParseError ( "The first token in an equation needs to be a variable and not " + token ) ; while ( token != null...
Parses operations where the input comes from variables to its left only . Hard coded to only look for transpose for now
25,759
protected void parseOperationsLR ( Symbol ops [ ] , TokenList tokens , Sequence sequence ) { if ( tokens . size == 0 ) return ; TokenList . Token token = tokens . first ; if ( token . getType ( ) != Type . VARIABLE ) throw new ParseError ( "The first token in an equation needs to be a variable and not " + token ) ; boo...
Parses operations where the input comes from variables to its left and right
25,760
public < T extends Variable > T lookupVariable ( String token ) { Variable result = variables . get ( token ) ; return ( T ) result ; }
Looks up a variable given its name . If none is found then return null .
25,761
void insertMacros ( TokenList tokens ) { TokenList . Token t = tokens . getFirst ( ) ; while ( t != null ) { if ( t . getType ( ) == Type . WORD ) { Macro v = lookupMacro ( t . word ) ; if ( v != null ) { TokenList . Token before = t . previous ; List < TokenList . Token > inputs = new ArrayList < TokenList . Token > (...
Checks to see if a WORD matches the name of a macro . if it does it applies the macro at that location
25,762
protected static boolean isTargetOp ( TokenList . Token token , Symbol [ ] ops ) { Symbol c = token . symbol ; for ( int i = 0 ; i < ops . length ; i ++ ) { if ( c == ops [ i ] ) return true ; } return false ; }
Checks to see if the token is in the list of allowed character operations . Used to apply order of operations
25,763
protected static boolean isOperatorLR ( Symbol s ) { if ( s == null ) return false ; switch ( s ) { case ELEMENT_DIVIDE : case ELEMENT_TIMES : case ELEMENT_POWER : case RDIVIDE : case LDIVIDE : case TIMES : case POWER : case PLUS : case MINUS : case ASSIGN : return true ; } return false ; }
Operators which affect the variables to its left and right
25,764
protected boolean isReserved ( String name ) { if ( functions . isFunctionName ( name ) ) return true ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { if ( ! isLetter ( name . charAt ( i ) ) ) return true ; } return false ; }
Returns true if the specified name is NOT allowed . It isn t allowed if it matches a built in operator or if it contains a restricted character .
25,765
public Equation process ( String equation , boolean debug ) { compile ( equation , true , debug ) . perform ( ) ; return this ; }
Compiles and performs the provided equation .
25,766
public void print ( String equation ) { Variable v = lookupVariable ( equation ) ; if ( v == null ) { Sequence sequence = compile ( equation , false , false ) ; sequence . perform ( ) ; v = sequence . output ; } if ( v instanceof VariableMatrix ) { ( ( VariableMatrix ) v ) . matrix . print ( ) ; } else if ( v instanceo...
Prints the results of the equation to standard out . Useful for debugging
25,767
public static double computeTauAndDivide ( final int j , final int numRows , final double [ ] u , final double max ) { double tau = 0 ; for ( int i = j ; i < numRows ; i ++ ) { double d = u [ i ] /= max ; tau += d * d ; } tau = Math . sqrt ( tau ) ; if ( u [ j ] < 0 ) tau = - tau ; return tau ; }
Normalizes elements in u by dividing by max and computes the norm2 of the normalized array u . Adjust the sign of the returned value depending on the size of the first element in u . Normalization is done to avoid overflow .
25,768
public static boolean isSameStructure ( DMatrixSparseCSC a , DMatrixSparseCSC b ) { if ( a . numRows == b . numRows && a . numCols == b . numCols && a . nz_length == b . nz_length ) { for ( int i = 0 ; i <= a . numCols ; i ++ ) { if ( a . col_idx [ i ] != b . col_idx [ i ] ) return false ; } for ( int i = 0 ; i < a . n...
Checks to see if the two matrices have the same shape and same pattern of non - zero elements
25,769
public static boolean isVector ( DMatrixSparseCSC a ) { return ( a . numCols == 1 && a . numRows > 1 ) || ( a . numRows == 1 && a . numCols > 1 ) ; }
Returns true if the input is a vector
25,770
public static boolean isSymmetric ( DMatrixSparseCSC A , double tol ) { if ( A . numRows != A . numCols ) return false ; int N = A . numCols ; for ( int i = 0 ; i < N ; i ++ ) { int idx0 = A . col_idx [ i ] ; int idx1 = A . col_idx [ i + 1 ] ; for ( int index = idx0 ; index < idx1 ; index ++ ) { int j = A . nz_rows [ i...
Checks to see if the matrix is symmetric to within tolerance .
25,771
public void implicitDoubleStep ( int x1 , int x2 ) { if ( printHumps ) System . out . println ( "Performing implicit double step" ) ; double z11 = A . get ( x2 - 1 , x2 - 1 ) ; double z12 = A . get ( x2 - 1 , x2 ) ; double z21 = A . get ( x2 , x2 - 1 ) ; double z22 = A . get ( x2 , x2 ) ; double a11 = A . get ( x1 , x1...
Performs an implicit double step using the values contained in the lower right hand side of the submatrix for the estimated eigenvector values .
25,772
public void performImplicitDoubleStep ( int x1 , int x2 , double real , double img ) { double a11 = A . get ( x1 , x1 ) ; double a21 = A . get ( x1 + 1 , x1 ) ; double a12 = A . get ( x1 , x1 + 1 ) ; double a22 = A . get ( x1 + 1 , x1 + 1 ) ; double a32 = A . get ( x1 + 2 , x1 + 1 ) ; double p_plus_t = 2.0 * real ; dou...
Performs an implicit double step given the set of two imaginary eigenvalues provided . Since one eigenvalue is the complex conjugate of the other only one set of real and imaginary numbers is needed .
25,773
public boolean process ( DMatrixRMaj A , int numSingularValues , DMatrixRMaj nullspace ) { decomposition . decompose ( A ) ; if ( A . numRows > A . numCols ) { Q . reshape ( A . numCols , Math . min ( A . numRows , A . numCols ) ) ; decomposition . getQ ( Q , true ) ; } else { Q . reshape ( A . numCols , A . numCols ) ...
Finds the null space of A
25,774
public static boolean isInverse ( DMatrixRMaj a , DMatrixRMaj b , double tol ) { if ( a . numRows != b . numRows || a . numCols != b . numCols ) { return false ; } int numRows = a . numRows ; int numCols = a . numCols ; for ( int i = 0 ; i < numRows ; i ++ ) { for ( int j = 0 ; j < numCols ; j ++ ) { double total = 0 ;...
Checks to see if the two matrices are inverses of each other .
25,775
public static boolean isRowsLinearIndependent ( DMatrixRMaj A ) { LUDecomposition < DMatrixRMaj > lu = DecompositionFactory_DDRM . lu ( A . numRows , A . numCols ) ; if ( lu . inputModified ( ) ) A = A . copy ( ) ; if ( ! lu . decompose ( A ) ) throw new RuntimeException ( "Decompositon failed?" ) ; return ! lu . isSin...
Checks to see if the rows of the provided matrix are linearly independent .
25,776
public static boolean isConstantVal ( DMatrixRMaj mat , double val , double tol ) { int index = 0 ; for ( int i = 0 ; i < mat . numRows ; i ++ ) { for ( int j = 0 ; j < mat . numCols ; j ++ ) { if ( ! ( Math . abs ( mat . get ( index ++ ) - val ) <= tol ) ) return false ; } } return true ; }
Checks to see if every value in the matrix is the specified value .
25,777
public static boolean isDiagonalPositive ( DMatrixRMaj a ) { for ( int i = 0 ; i < a . numRows ; i ++ ) { if ( ! ( a . get ( i , i ) >= 0 ) ) return false ; } return true ; }
Checks to see if all the diagonal elements in the matrix are positive .
25,778
public static int rank ( DMatrixRMaj A , double threshold ) { SingularValueDecomposition_F64 < DMatrixRMaj > svd = DecompositionFactory_DDRM . svd ( A . numRows , A . numCols , false , false , true ) ; if ( svd . inputModified ( ) ) A = A . copy ( ) ; if ( ! svd . decompose ( A ) ) throw new RuntimeException ( "Decompo...
Computes the rank of a matrix using the specified tolerance .
25,779
public static int countNonZero ( DMatrixRMaj A ) { int total = 0 ; for ( int row = 0 , index = 0 ; row < A . numRows ; row ++ ) { for ( int col = 0 ; col < A . numCols ; col ++ , index ++ ) { if ( A . data [ index ] != 0 ) { total ++ ; } } } return total ; }
Counts the number of elements in A which are not zero .
25,780
public static boolean invertSPD ( DMatrixRMaj mat , DMatrixRMaj result ) { if ( mat . numRows != mat . numCols ) throw new IllegalArgumentException ( "Must be a square matrix" ) ; result . reshape ( mat . numRows , mat . numRows ) ; if ( mat . numRows <= UnrolledCholesky_DDRM . MAX ) { if ( ! UnrolledCholesky_DDRM . lo...
Matrix inverse for symmetric positive definite matrices . For small matrices an unrolled cholesky is used . Otherwise a standard decomposition .
25,781
public static DMatrixRMaj identity ( int numRows , int numCols ) { DMatrixRMaj ret = new DMatrixRMaj ( numRows , numCols ) ; int small = numRows < numCols ? numRows : numCols ; for ( int i = 0 ; i < small ; i ++ ) { ret . set ( i , i , 1.0 ) ; } return ret ; }
Creates a rectangular matrix which is zero except along the diagonals .
25,782
public static void extract ( DMatrix src , int srcY0 , int srcY1 , int srcX0 , int srcX1 , DMatrix dst ) { ( ( ReshapeMatrix ) dst ) . reshape ( srcY1 - srcY0 , srcX1 - srcX0 ) ; extract ( src , srcY0 , srcY1 , srcX0 , srcX1 , dst , 0 , 0 ) ; }
Extract where the destination is reshaped to match the extracted region
25,783
public static void extract ( DMatrixRMaj src , int rows [ ] , int rowsSize , int cols [ ] , int colsSize , DMatrixRMaj dst ) { if ( rowsSize != dst . numRows || colsSize != dst . numCols ) throw new MatrixDimensionException ( "Unexpected number of rows and/or columns in dst matrix" ) ; int indexDst = 0 ; for ( int i = ...
Extracts out a matrix from source given a sub matrix with arbitrary rows and columns specified in two array lists
25,784
public static void extract ( DMatrixRMaj src , int indexes [ ] , int length , DMatrixRMaj dst ) { if ( ! MatrixFeatures_DDRM . isVector ( dst ) ) throw new MatrixDimensionException ( "Dst must be a vector" ) ; if ( length != dst . getNumElements ( ) ) throw new MatrixDimensionException ( "Unexpected number of elements ...
Extracts the elements from the source matrix by their 1D index .
25,785
public static DMatrixRMaj extractRow ( DMatrixRMaj a , int row , DMatrixRMaj out ) { if ( out == null ) out = new DMatrixRMaj ( 1 , a . numCols ) ; else if ( ! MatrixFeatures_DDRM . isVector ( out ) || out . getNumElements ( ) != a . numCols ) throw new MatrixDimensionException ( "Output must be a vector of length " + ...
Extracts the row from a matrix .
25,786
public static DMatrixRMaj extractColumn ( DMatrixRMaj a , int column , DMatrixRMaj out ) { if ( out == null ) out = new DMatrixRMaj ( a . numRows , 1 ) ; else if ( ! MatrixFeatures_DDRM . isVector ( out ) || out . getNumElements ( ) != a . numRows ) throw new MatrixDimensionException ( "Output must be a vector of lengt...
Extracts the column from a matrix .
25,787
public static void removeColumns ( DMatrixRMaj A , int col0 , int col1 ) { if ( col1 < col0 ) { throw new IllegalArgumentException ( "col1 must be >= col0" ) ; } else if ( col0 >= A . numCols || col1 >= A . numCols ) { throw new IllegalArgumentException ( "Columns which are to be removed must be in bounds" ) ; } int st...
Removes columns from the matrix .
25,788
public static void scaleRow ( double alpha , DMatrixRMaj A , int row ) { int idx = row * A . numCols ; for ( int col = 0 ; col < A . numCols ; col ++ ) { A . data [ idx ++ ] *= alpha ; } }
In - place scaling of a row in A
25,789
public static void scaleCol ( double alpha , DMatrixRMaj A , int col ) { int idx = col ; for ( int row = 0 ; row < A . numRows ; row ++ , idx += A . numCols ) { A . data [ idx ] *= alpha ; } }
In - place scaling of a column in A
25,790
public static BMatrixRMaj elementLessThan ( DMatrixRMaj A , double value , BMatrixRMaj output ) { if ( output == null ) { output = new BMatrixRMaj ( A . numRows , A . numCols ) ; } output . reshape ( A . numRows , A . numCols ) ; int N = A . getNumElements ( ) ; for ( int i = 0 ; i < N ; i ++ ) { output . data [ i ] = ...
Applies the &gt ; operator to each element in A . Results are stored in a boolean matrix .
25,791
public static DMatrixRMaj elements ( DMatrixRMaj A , BMatrixRMaj marked , DMatrixRMaj output ) { if ( A . numRows != marked . numRows || A . numCols != marked . numCols ) throw new MatrixDimensionException ( "Input matrices must have the same shape" ) ; if ( output == null ) output = new DMatrixRMaj ( 1 , 1 ) ; output ...
Returns a row matrix which contains all the elements in A which are flagged as true in marked
25,792
public static int countTrue ( BMatrixRMaj A ) { int total = 0 ; int N = A . getNumElements ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A . data [ i ] ) total ++ ; } return total ; }
Counts the number of elements in A which are true
25,793
public static void symmLowerToFull ( DMatrixRMaj A ) { if ( A . numRows != A . numCols ) throw new MatrixDimensionException ( "Must be a square matrix" ) ; final int cols = A . numCols ; for ( int row = 0 ; row < A . numRows ; row ++ ) { for ( int col = row + 1 ; col < cols ; col ++ ) { A . data [ row * cols + col ] = ...
Given a symmetric matrix which is represented by a lower triangular matrix convert it back into a full symmetric matrix .
25,794
public void init ( DMatrixRMaj A ) { if ( A . numRows != A . numCols ) throw new IllegalArgumentException ( "Must be square" ) ; if ( A . numCols != N ) { N = A . numCols ; QT . reshape ( N , N , false ) ; if ( w . length < N ) { w = new double [ N ] ; gammas = new double [ N ] ; b = new double [ N ] ; } } QT . set ( A...
If needed declares and sets up internal data structures .
25,795
public static void inner_reorder_lower ( DMatrix1Row A , DMatrix1Row B ) { final int cols = A . numCols ; B . reshape ( cols , cols ) ; Arrays . fill ( B . data , 0 ) ; for ( int i = 0 ; i < cols ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { B . data [ i * cols + j ] += A . data [ i ] * A . data [ j ] ; } for ( int k ...
Computes the inner product of A times A and stores the results in B . The inner product is symmetric and this function will only store the lower triangle . The value of the upper triangular matrix is undefined .
25,796
public static void pow ( ComplexPolar_F64 a , int N , ComplexPolar_F64 result ) { result . r = Math . pow ( a . r , N ) ; result . theta = N * a . theta ; }
Computes the power of a complex number in polar notation
25,797
public static void sqrt ( Complex_F64 input , Complex_F64 root ) { double r = input . getMagnitude ( ) ; double a = input . real ; root . real = Math . sqrt ( ( r + a ) / 2.0 ) ; root . imaginary = Math . sqrt ( ( r - a ) / 2.0 ) ; if ( input . imaginary < 0 ) root . imaginary = - root . imaginary ; }
Computes the square root of the complex number .
25,798
public boolean computeDirect ( DMatrixRMaj A ) { initPower ( A ) ; boolean converged = false ; for ( int i = 0 ; i < maxIterations && ! converged ; i ++ ) { CommonOps_DDRM . mult ( A , q0 , q1 ) ; double s = NormOps_DDRM . normPInf ( q1 ) ; CommonOps_DDRM . divide ( q1 , s , q2 ) ; converged = checkConverged ( A ) ; } ...
This method computes the eigen vector with the largest eigen value by using the direct power method . This technique is the easiest to implement but the slowest to converge . Works only if all the eigenvalues are real .
25,799
private boolean checkConverged ( DMatrixRMaj A ) { double worst = 0 ; double worst2 = 0 ; for ( int j = 0 ; j < A . numRows ; j ++ ) { double val = Math . abs ( q2 . data [ j ] - q0 . data [ j ] ) ; if ( val > worst ) worst = val ; val = Math . abs ( q2 . data [ j ] + q0 . data [ j ] ) ; if ( val > worst2 ) worst2 = va...
Test for convergence by seeing if the element with the largest change is smaller than the tolerance . In some test cases it alternated between the + and - values of the eigen vector . When this happens it seems to have converged to a non - dominant eigen vector . At least in the case I looked at . I haven t devoted a l...