id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
162,400 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/simple/SimpleBase.java
|
SimpleBase.convertToDense
|
public void convertToDense() {
switch ( mat.getType() ) {
case DSCC: {
DMatrix m = new DMatrixRMaj(mat.getNumRows(), mat.getNumCols());
ConvertDMatrixStruct.convert((DMatrix) mat, m);
setMatrix(m);
} break;
case FSCC: {
FMatrix m = new FMatrixRMaj(mat.getNumRows(), mat.getNumCols());
ConvertFMatrixStruct.convert((FMatrix) mat, m);
setMatrix(m);
} break;
case DDRM:
case FDRM:
case ZDRM:
case CDRM:
break;
default:
throw new RuntimeException("Not a sparse matrix!");
}
}
|
java
|
public void convertToDense() {
switch ( mat.getType() ) {
case DSCC: {
DMatrix m = new DMatrixRMaj(mat.getNumRows(), mat.getNumCols());
ConvertDMatrixStruct.convert((DMatrix) mat, m);
setMatrix(m);
} break;
case FSCC: {
FMatrix m = new FMatrixRMaj(mat.getNumRows(), mat.getNumCols());
ConvertFMatrixStruct.convert((FMatrix) mat, m);
setMatrix(m);
} break;
case DDRM:
case FDRM:
case ZDRM:
case CDRM:
break;
default:
throw new RuntimeException("Not a sparse matrix!");
}
}
|
[
"public",
"void",
"convertToDense",
"(",
")",
"{",
"switch",
"(",
"mat",
".",
"getType",
"(",
")",
")",
"{",
"case",
"DSCC",
":",
"{",
"DMatrix",
"m",
"=",
"new",
"DMatrixRMaj",
"(",
"mat",
".",
"getNumRows",
"(",
")",
",",
"mat",
".",
"getNumCols",
"(",
")",
")",
";",
"ConvertDMatrixStruct",
".",
"convert",
"(",
"(",
"DMatrix",
")",
"mat",
",",
"m",
")",
";",
"setMatrix",
"(",
"m",
")",
";",
"}",
"break",
";",
"case",
"FSCC",
":",
"{",
"FMatrix",
"m",
"=",
"new",
"FMatrixRMaj",
"(",
"mat",
".",
"getNumRows",
"(",
")",
",",
"mat",
".",
"getNumCols",
"(",
")",
")",
";",
"ConvertFMatrixStruct",
".",
"convert",
"(",
"(",
"FMatrix",
")",
"mat",
",",
"m",
")",
";",
"setMatrix",
"(",
"m",
")",
";",
"}",
"break",
";",
"case",
"DDRM",
":",
"case",
"FDRM",
":",
"case",
"ZDRM",
":",
"case",
"CDRM",
":",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"Not a sparse matrix!\"",
")",
";",
"}",
"}"
] |
Switches from a sparse to dense matrix
|
[
"Switches",
"from",
"a",
"sparse",
"to",
"dense",
"matrix"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/simple/SimpleBase.java#L1525-L1545
|
162,401 |
lessthanoptimal/ejml
|
main/ejml-experimental/src/org/ejml/dense/blockd3/BlockD3MatrixOps.java
|
BlockD3MatrixOps.multBlockAdd
|
private static void multBlockAdd( double []blockA, double []blockB, double []blockC,
final int m, final int n, final int o,
final int blockLength ) {
// for( int i = 0; i < m; i++ ) {
// for( int j = 0; j < o; j++ ) {
// double val = 0;
// for( int k = 0; k < n; k++ ) {
// val += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
// }
//
// blockC[ i*blockLength + j] += val;
// }
// }
// int rowA = 0;
// for( int i = 0; i < m; i++ , rowA += blockLength) {
// for( int j = 0; j < o; j++ ) {
// double val = 0;
// int indexB = j;
// int indexA = rowA;
// int end = indexA + n;
// for( ; indexA != end; indexA++ , indexB += blockLength ) {
// val += blockA[ indexA ]*blockB[ indexB ];
// }
//
// blockC[ rowA + j] += val;
// }
// }
// for( int k = 0; k < n; k++ ) {
// for( int i = 0; i < m; i++ ) {
// for( int j = 0; j < o; j++ ) {
// blockC[ i*blockLength + j] += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
// }
// }
// }
for( int k = 0; k < n; k++ ) {
int rowB = k*blockLength;
int endB = rowB+o;
for( int i = 0; i < m; i++ ) {
int indexC = i*blockLength;
double valA = blockA[ indexC + k];
int indexB = rowB;
while( indexB != endB ) {
blockC[ indexC++ ] += valA*blockB[ indexB++];
}
}
}
}
|
java
|
private static void multBlockAdd( double []blockA, double []blockB, double []blockC,
final int m, final int n, final int o,
final int blockLength ) {
// for( int i = 0; i < m; i++ ) {
// for( int j = 0; j < o; j++ ) {
// double val = 0;
// for( int k = 0; k < n; k++ ) {
// val += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
// }
//
// blockC[ i*blockLength + j] += val;
// }
// }
// int rowA = 0;
// for( int i = 0; i < m; i++ , rowA += blockLength) {
// for( int j = 0; j < o; j++ ) {
// double val = 0;
// int indexB = j;
// int indexA = rowA;
// int end = indexA + n;
// for( ; indexA != end; indexA++ , indexB += blockLength ) {
// val += blockA[ indexA ]*blockB[ indexB ];
// }
//
// blockC[ rowA + j] += val;
// }
// }
// for( int k = 0; k < n; k++ ) {
// for( int i = 0; i < m; i++ ) {
// for( int j = 0; j < o; j++ ) {
// blockC[ i*blockLength + j] += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
// }
// }
// }
for( int k = 0; k < n; k++ ) {
int rowB = k*blockLength;
int endB = rowB+o;
for( int i = 0; i < m; i++ ) {
int indexC = i*blockLength;
double valA = blockA[ indexC + k];
int indexB = rowB;
while( indexB != endB ) {
blockC[ indexC++ ] += valA*blockB[ indexB++];
}
}
}
}
|
[
"private",
"static",
"void",
"multBlockAdd",
"(",
"double",
"[",
"]",
"blockA",
",",
"double",
"[",
"]",
"blockB",
",",
"double",
"[",
"]",
"blockC",
",",
"final",
"int",
"m",
",",
"final",
"int",
"n",
",",
"final",
"int",
"o",
",",
"final",
"int",
"blockLength",
")",
"{",
"// for( int i = 0; i < m; i++ ) {",
"// for( int j = 0; j < o; j++ ) {",
"// double val = 0;",
"// for( int k = 0; k < n; k++ ) {",
"// val += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];",
"// }",
"//",
"// blockC[ i*blockLength + j] += val;",
"// }",
"// }",
"// int rowA = 0;",
"// for( int i = 0; i < m; i++ , rowA += blockLength) {",
"// for( int j = 0; j < o; j++ ) {",
"// double val = 0;",
"// int indexB = j;",
"// int indexA = rowA;",
"// int end = indexA + n;",
"// for( ; indexA != end; indexA++ , indexB += blockLength ) {",
"// val += blockA[ indexA ]*blockB[ indexB ];",
"// }",
"//",
"// blockC[ rowA + j] += val;",
"// }",
"// }",
"// for( int k = 0; k < n; k++ ) {",
"// for( int i = 0; i < m; i++ ) {",
"// for( int j = 0; j < o; j++ ) {",
"// blockC[ i*blockLength + j] += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];",
"// }",
"// }",
"// }",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"n",
";",
"k",
"++",
")",
"{",
"int",
"rowB",
"=",
"k",
"*",
"blockLength",
";",
"int",
"endB",
"=",
"rowB",
"+",
"o",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"m",
";",
"i",
"++",
")",
"{",
"int",
"indexC",
"=",
"i",
"*",
"blockLength",
";",
"double",
"valA",
"=",
"blockA",
"[",
"indexC",
"+",
"k",
"]",
";",
"int",
"indexB",
"=",
"rowB",
";",
"while",
"(",
"indexB",
"!=",
"endB",
")",
"{",
"blockC",
"[",
"indexC",
"++",
"]",
"+=",
"valA",
"*",
"blockB",
"[",
"indexB",
"++",
"]",
";",
"}",
"}",
"}",
"}"
] |
Performs a matrix multiplication between inner block matrices.
(m , o) += (m , n) * (n , o)
|
[
"Performs",
"a",
"matrix",
"multiplication",
"between",
"inner",
"block",
"matrices",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-experimental/src/org/ejml/dense/blockd3/BlockD3MatrixOps.java#L169-L219
|
162,402 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/lu/LUDecompositionBase_DDRM.java
|
LUDecompositionBase_DDRM._solveVectorInternal
|
public void _solveVectorInternal( double []vv )
{
// Solve L*Y = B
int ii = 0;
for( int i = 0; i < n; i++ ) {
int ip = indx[i];
double sum = vv[ip];
vv[ip] = vv[i];
if( ii != 0 ) {
// for( int j = ii-1; j < i; j++ )
// sum -= dataLU[i* n +j]*vv[j];
int index = i*n + ii-1;
for( int j = ii-1; j < i; j++ )
sum -= dataLU[index++]*vv[j];
} else if( sum != 0.0 ) {
ii=i+1;
}
vv[i] = sum;
}
// Solve U*X = Y;
TriangularSolver_DDRM.solveU(dataLU,vv,n);
}
|
java
|
public void _solveVectorInternal( double []vv )
{
// Solve L*Y = B
int ii = 0;
for( int i = 0; i < n; i++ ) {
int ip = indx[i];
double sum = vv[ip];
vv[ip] = vv[i];
if( ii != 0 ) {
// for( int j = ii-1; j < i; j++ )
// sum -= dataLU[i* n +j]*vv[j];
int index = i*n + ii-1;
for( int j = ii-1; j < i; j++ )
sum -= dataLU[index++]*vv[j];
} else if( sum != 0.0 ) {
ii=i+1;
}
vv[i] = sum;
}
// Solve U*X = Y;
TriangularSolver_DDRM.solveU(dataLU,vv,n);
}
|
[
"public",
"void",
"_solveVectorInternal",
"(",
"double",
"[",
"]",
"vv",
")",
"{",
"// Solve L*Y = B",
"int",
"ii",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"int",
"ip",
"=",
"indx",
"[",
"i",
"]",
";",
"double",
"sum",
"=",
"vv",
"[",
"ip",
"]",
";",
"vv",
"[",
"ip",
"]",
"=",
"vv",
"[",
"i",
"]",
";",
"if",
"(",
"ii",
"!=",
"0",
")",
"{",
"// for( int j = ii-1; j < i; j++ )",
"// sum -= dataLU[i* n +j]*vv[j];",
"int",
"index",
"=",
"i",
"*",
"n",
"+",
"ii",
"-",
"1",
";",
"for",
"(",
"int",
"j",
"=",
"ii",
"-",
"1",
";",
"j",
"<",
"i",
";",
"j",
"++",
")",
"sum",
"-=",
"dataLU",
"[",
"index",
"++",
"]",
"*",
"vv",
"[",
"j",
"]",
";",
"}",
"else",
"if",
"(",
"sum",
"!=",
"0.0",
")",
"{",
"ii",
"=",
"i",
"+",
"1",
";",
"}",
"vv",
"[",
"i",
"]",
"=",
"sum",
";",
"}",
"// Solve U*X = Y;",
"TriangularSolver_DDRM",
".",
"solveU",
"(",
"dataLU",
",",
"vv",
",",
"n",
")",
";",
"}"
] |
a specialized version of solve that avoid additional checks that are not needed.
|
[
"a",
"specialized",
"version",
"of",
"solve",
"that",
"avoid",
"additional",
"checks",
"that",
"are",
"not",
"needed",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/lu/LUDecompositionBase_DDRM.java#L213-L236
|
162,403 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.resize
|
protected void resize( VariableMatrix mat , int numRows , int numCols ) {
if( mat.isTemp() ) {
mat.matrix.reshape(numRows,numCols);
}
}
|
java
|
protected void resize( VariableMatrix mat , int numRows , int numCols ) {
if( mat.isTemp() ) {
mat.matrix.reshape(numRows,numCols);
}
}
|
[
"protected",
"void",
"resize",
"(",
"VariableMatrix",
"mat",
",",
"int",
"numRows",
",",
"int",
"numCols",
")",
"{",
"if",
"(",
"mat",
".",
"isTemp",
"(",
")",
")",
"{",
"mat",
".",
"matrix",
".",
"reshape",
"(",
"numRows",
",",
"numCols",
")",
";",
"}",
"}"
] |
If the variable is a local temporary variable it will be resized so that the operation can complete. If not
temporary then it will not be reshaped
@param mat Variable containing the matrix
@param numRows Desired number of rows
@param numCols Desired number of columns
|
[
"If",
"the",
"variable",
"is",
"a",
"local",
"temporary",
"variable",
"it",
"will",
"be",
"resized",
"so",
"that",
"the",
"operation",
"can",
"complete",
".",
"If",
"not",
"temporary",
"then",
"it",
"will",
"not",
"be",
"reshaped"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L61-L65
|
162,404 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.neg
|
public static Info neg(final Variable A, ManagerTempVariables manager) {
Info ret = new Info();
if( A instanceof VariableInteger ) {
final VariableInteger output = manager.createInteger();
ret.output = output;
ret.op = new Operation("neg-i") {
@Override
public void process() {
output.value = -((VariableInteger)A).value;
}
};
} else if( A instanceof VariableScalar ) {
final VariableDouble output = manager.createDouble();
ret.output = output;
ret.op = new Operation("neg-s") {
@Override
public void process() {
output.value = -((VariableScalar)A).getDouble();
}
};
} else if( A instanceof VariableMatrix ) {
final VariableMatrix output = manager.createMatrix();
ret.output = output;
ret.op = new Operation("neg-m") {
@Override
public void process() {
DMatrixRMaj a = ((VariableMatrix)A).matrix;
output.matrix.reshape(a.numRows, a.numCols);
CommonOps_DDRM.changeSign(a, output.matrix);
}
};
} else {
throw new RuntimeException("Unsupported variable "+A);
}
return ret;
}
|
java
|
public static Info neg(final Variable A, ManagerTempVariables manager) {
Info ret = new Info();
if( A instanceof VariableInteger ) {
final VariableInteger output = manager.createInteger();
ret.output = output;
ret.op = new Operation("neg-i") {
@Override
public void process() {
output.value = -((VariableInteger)A).value;
}
};
} else if( A instanceof VariableScalar ) {
final VariableDouble output = manager.createDouble();
ret.output = output;
ret.op = new Operation("neg-s") {
@Override
public void process() {
output.value = -((VariableScalar)A).getDouble();
}
};
} else if( A instanceof VariableMatrix ) {
final VariableMatrix output = manager.createMatrix();
ret.output = output;
ret.op = new Operation("neg-m") {
@Override
public void process() {
DMatrixRMaj a = ((VariableMatrix)A).matrix;
output.matrix.reshape(a.numRows, a.numCols);
CommonOps_DDRM.changeSign(a, output.matrix);
}
};
} else {
throw new RuntimeException("Unsupported variable "+A);
}
return ret;
}
|
[
"public",
"static",
"Info",
"neg",
"(",
"final",
"Variable",
"A",
",",
"ManagerTempVariables",
"manager",
")",
"{",
"Info",
"ret",
"=",
"new",
"Info",
"(",
")",
";",
"if",
"(",
"A",
"instanceof",
"VariableInteger",
")",
"{",
"final",
"VariableInteger",
"output",
"=",
"manager",
".",
"createInteger",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"neg-i\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"output",
".",
"value",
"=",
"-",
"(",
"(",
"VariableInteger",
")",
"A",
")",
".",
"value",
";",
"}",
"}",
";",
"}",
"else",
"if",
"(",
"A",
"instanceof",
"VariableScalar",
")",
"{",
"final",
"VariableDouble",
"output",
"=",
"manager",
".",
"createDouble",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"neg-s\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"output",
".",
"value",
"=",
"-",
"(",
"(",
"VariableScalar",
")",
"A",
")",
".",
"getDouble",
"(",
")",
";",
"}",
"}",
";",
"}",
"else",
"if",
"(",
"A",
"instanceof",
"VariableMatrix",
")",
"{",
"final",
"VariableMatrix",
"output",
"=",
"manager",
".",
"createMatrix",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"neg-m\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"DMatrixRMaj",
"a",
"=",
"(",
"(",
"VariableMatrix",
")",
"A",
")",
".",
"matrix",
";",
"output",
".",
"matrix",
".",
"reshape",
"(",
"a",
".",
"numRows",
",",
"a",
".",
"numCols",
")",
";",
"CommonOps_DDRM",
".",
"changeSign",
"(",
"a",
",",
"output",
".",
"matrix",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unsupported variable \"",
"+",
"A",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Returns the negative of the input variable
|
[
"Returns",
"the",
"negative",
"of",
"the",
"input",
"variable"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L202-L239
|
162,405 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.eye
|
public static Info eye( final Variable A , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableMatrix ) {
ret.op = new Operation("eye-m") {
@Override
public void process() {
DMatrixRMaj mA = ((VariableMatrix)A).matrix;
output.matrix.reshape(mA.numRows,mA.numCols);
CommonOps_DDRM.setIdentity(output.matrix);
}
};
} else if( A instanceof VariableInteger ) {
ret.op = new Operation("eye-i") {
@Override
public void process() {
int N = ((VariableInteger)A).value;
output.matrix.reshape(N,N);
CommonOps_DDRM.setIdentity(output.matrix);
}
};
} else {
throw new RuntimeException("Unsupported variable type "+A);
}
return ret;
}
|
java
|
public static Info eye( final Variable A , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableMatrix ) {
ret.op = new Operation("eye-m") {
@Override
public void process() {
DMatrixRMaj mA = ((VariableMatrix)A).matrix;
output.matrix.reshape(mA.numRows,mA.numCols);
CommonOps_DDRM.setIdentity(output.matrix);
}
};
} else if( A instanceof VariableInteger ) {
ret.op = new Operation("eye-i") {
@Override
public void process() {
int N = ((VariableInteger)A).value;
output.matrix.reshape(N,N);
CommonOps_DDRM.setIdentity(output.matrix);
}
};
} else {
throw new RuntimeException("Unsupported variable type "+A);
}
return ret;
}
|
[
"public",
"static",
"Info",
"eye",
"(",
"final",
"Variable",
"A",
",",
"ManagerTempVariables",
"manager",
")",
"{",
"Info",
"ret",
"=",
"new",
"Info",
"(",
")",
";",
"final",
"VariableMatrix",
"output",
"=",
"manager",
".",
"createMatrix",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"if",
"(",
"A",
"instanceof",
"VariableMatrix",
")",
"{",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"eye-m\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"DMatrixRMaj",
"mA",
"=",
"(",
"(",
"VariableMatrix",
")",
"A",
")",
".",
"matrix",
";",
"output",
".",
"matrix",
".",
"reshape",
"(",
"mA",
".",
"numRows",
",",
"mA",
".",
"numCols",
")",
";",
"CommonOps_DDRM",
".",
"setIdentity",
"(",
"output",
".",
"matrix",
")",
";",
"}",
"}",
";",
"}",
"else",
"if",
"(",
"A",
"instanceof",
"VariableInteger",
")",
"{",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"eye-i\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"int",
"N",
"=",
"(",
"(",
"VariableInteger",
")",
"A",
")",
".",
"value",
";",
"output",
".",
"matrix",
".",
"reshape",
"(",
"N",
",",
"N",
")",
";",
"CommonOps_DDRM",
".",
"setIdentity",
"(",
"output",
".",
"matrix",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unsupported variable type \"",
"+",
"A",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Returns an identity matrix
|
[
"Returns",
"an",
"identity",
"matrix"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L1260-L1288
|
162,406 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.ones
|
public static Info ones( final Variable A , final Variable B , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableInteger && B instanceof VariableInteger ) {
ret.op = new Operation("ones-ii") {
@Override
public void process() {
int numRows = ((VariableInteger)A).value;
int numCols = ((VariableInteger)B).value;
output.matrix.reshape(numRows,numCols);
CommonOps_DDRM.fill(output.matrix, 1);
}
};
} else {
throw new RuntimeException("Expected two integers got "+A+" "+B);
}
return ret;
}
|
java
|
public static Info ones( final Variable A , final Variable B , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableInteger && B instanceof VariableInteger ) {
ret.op = new Operation("ones-ii") {
@Override
public void process() {
int numRows = ((VariableInteger)A).value;
int numCols = ((VariableInteger)B).value;
output.matrix.reshape(numRows,numCols);
CommonOps_DDRM.fill(output.matrix, 1);
}
};
} else {
throw new RuntimeException("Expected two integers got "+A+" "+B);
}
return ret;
}
|
[
"public",
"static",
"Info",
"ones",
"(",
"final",
"Variable",
"A",
",",
"final",
"Variable",
"B",
",",
"ManagerTempVariables",
"manager",
")",
"{",
"Info",
"ret",
"=",
"new",
"Info",
"(",
")",
";",
"final",
"VariableMatrix",
"output",
"=",
"manager",
".",
"createMatrix",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"if",
"(",
"A",
"instanceof",
"VariableInteger",
"&&",
"B",
"instanceof",
"VariableInteger",
")",
"{",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"ones-ii\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"int",
"numRows",
"=",
"(",
"(",
"VariableInteger",
")",
"A",
")",
".",
"value",
";",
"int",
"numCols",
"=",
"(",
"(",
"VariableInteger",
")",
"B",
")",
".",
"value",
";",
"output",
".",
"matrix",
".",
"reshape",
"(",
"numRows",
",",
"numCols",
")",
";",
"CommonOps_DDRM",
".",
"fill",
"(",
"output",
".",
"matrix",
",",
"1",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Expected two integers got \"",
"+",
"A",
"+",
"\" \"",
"+",
"B",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Returns a matrix full of ones
|
[
"Returns",
"a",
"matrix",
"full",
"of",
"ones"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L1349-L1369
|
162,407 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.rng
|
public static Info rng( final Variable A , ManagerTempVariables manager) {
Info ret = new Info();
if( A instanceof VariableInteger ) {
ret.op = new Operation("rng") {
@Override
public void process() {
int seed = ((VariableInteger)A).value;
manager.getRandom().setSeed(seed);
}
};
} else {
throw new RuntimeException("Expected one integer");
}
return ret;
}
|
java
|
public static Info rng( final Variable A , ManagerTempVariables manager) {
Info ret = new Info();
if( A instanceof VariableInteger ) {
ret.op = new Operation("rng") {
@Override
public void process() {
int seed = ((VariableInteger)A).value;
manager.getRandom().setSeed(seed);
}
};
} else {
throw new RuntimeException("Expected one integer");
}
return ret;
}
|
[
"public",
"static",
"Info",
"rng",
"(",
"final",
"Variable",
"A",
",",
"ManagerTempVariables",
"manager",
")",
"{",
"Info",
"ret",
"=",
"new",
"Info",
"(",
")",
";",
"if",
"(",
"A",
"instanceof",
"VariableInteger",
")",
"{",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"rng\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"int",
"seed",
"=",
"(",
"(",
"VariableInteger",
")",
"A",
")",
".",
"value",
";",
"manager",
".",
"getRandom",
"(",
")",
".",
"setSeed",
"(",
"seed",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Expected one integer\"",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Sets the seed for random number generator
|
[
"Sets",
"the",
"seed",
"for",
"random",
"number",
"generator"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L1374-L1391
|
162,408 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.rand
|
public static Info rand( final Variable A , final Variable B , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableInteger && B instanceof VariableInteger ) {
ret.op = new Operation("rand-ii") {
@Override
public void process() {
int numRows = ((VariableInteger)A).value;
int numCols = ((VariableInteger)B).value;
output.matrix.reshape(numRows,numCols);
RandomMatrices_DDRM.fillUniform(output.matrix, 0,1,manager.getRandom());
}
};
} else {
throw new RuntimeException("Expected two integers got "+A+" "+B);
}
return ret;
}
|
java
|
public static Info rand( final Variable A , final Variable B , ManagerTempVariables manager) {
Info ret = new Info();
final VariableMatrix output = manager.createMatrix();
ret.output = output;
if( A instanceof VariableInteger && B instanceof VariableInteger ) {
ret.op = new Operation("rand-ii") {
@Override
public void process() {
int numRows = ((VariableInteger)A).value;
int numCols = ((VariableInteger)B).value;
output.matrix.reshape(numRows,numCols);
RandomMatrices_DDRM.fillUniform(output.matrix, 0,1,manager.getRandom());
}
};
} else {
throw new RuntimeException("Expected two integers got "+A+" "+B);
}
return ret;
}
|
[
"public",
"static",
"Info",
"rand",
"(",
"final",
"Variable",
"A",
",",
"final",
"Variable",
"B",
",",
"ManagerTempVariables",
"manager",
")",
"{",
"Info",
"ret",
"=",
"new",
"Info",
"(",
")",
";",
"final",
"VariableMatrix",
"output",
"=",
"manager",
".",
"createMatrix",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"if",
"(",
"A",
"instanceof",
"VariableInteger",
"&&",
"B",
"instanceof",
"VariableInteger",
")",
"{",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"rand-ii\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"int",
"numRows",
"=",
"(",
"(",
"VariableInteger",
")",
"A",
")",
".",
"value",
";",
"int",
"numCols",
"=",
"(",
"(",
"VariableInteger",
")",
"B",
")",
".",
"value",
";",
"output",
".",
"matrix",
".",
"reshape",
"(",
"numRows",
",",
"numCols",
")",
";",
"RandomMatrices_DDRM",
".",
"fillUniform",
"(",
"output",
".",
"matrix",
",",
"0",
",",
"1",
",",
"manager",
".",
"getRandom",
"(",
")",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Expected two integers got \"",
"+",
"A",
"+",
"\" \"",
"+",
"B",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Uniformly random numbers
|
[
"Uniformly",
"random",
"numbers"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L1396-L1416
|
162,409 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Operation.java
|
Operation.extractSimpleExtents
|
private static boolean extractSimpleExtents(Variable var, Extents e, boolean row, int length) {
int lower;
int upper;
if( var.getType() == VariableType.INTEGER_SEQUENCE ) {
IntegerSequence sequence = ((VariableIntegerSequence)var).sequence;
if( sequence.getType() == IntegerSequence.Type.FOR ) {
IntegerSequence.For seqFor = (IntegerSequence.For)sequence;
seqFor.initialize(length);
if( seqFor.getStep() == 1 ) {
lower = seqFor.getStart();
upper = seqFor.getEnd();
} else {
return false;
}
} else {
return false;
}
} else if( var.getType() == VariableType.SCALAR ) {
lower = upper = ((VariableInteger)var).value;
} else {
throw new RuntimeException("How did a bad variable get put here?!?!");
}
if( row ) {
e.row0 = lower;
e.row1 = upper;
} else {
e.col0 = lower;
e.col1 = upper;
}
return true;
}
|
java
|
private static boolean extractSimpleExtents(Variable var, Extents e, boolean row, int length) {
int lower;
int upper;
if( var.getType() == VariableType.INTEGER_SEQUENCE ) {
IntegerSequence sequence = ((VariableIntegerSequence)var).sequence;
if( sequence.getType() == IntegerSequence.Type.FOR ) {
IntegerSequence.For seqFor = (IntegerSequence.For)sequence;
seqFor.initialize(length);
if( seqFor.getStep() == 1 ) {
lower = seqFor.getStart();
upper = seqFor.getEnd();
} else {
return false;
}
} else {
return false;
}
} else if( var.getType() == VariableType.SCALAR ) {
lower = upper = ((VariableInteger)var).value;
} else {
throw new RuntimeException("How did a bad variable get put here?!?!");
}
if( row ) {
e.row0 = lower;
e.row1 = upper;
} else {
e.col0 = lower;
e.col1 = upper;
}
return true;
}
|
[
"private",
"static",
"boolean",
"extractSimpleExtents",
"(",
"Variable",
"var",
",",
"Extents",
"e",
",",
"boolean",
"row",
",",
"int",
"length",
")",
"{",
"int",
"lower",
";",
"int",
"upper",
";",
"if",
"(",
"var",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"INTEGER_SEQUENCE",
")",
"{",
"IntegerSequence",
"sequence",
"=",
"(",
"(",
"VariableIntegerSequence",
")",
"var",
")",
".",
"sequence",
";",
"if",
"(",
"sequence",
".",
"getType",
"(",
")",
"==",
"IntegerSequence",
".",
"Type",
".",
"FOR",
")",
"{",
"IntegerSequence",
".",
"For",
"seqFor",
"=",
"(",
"IntegerSequence",
".",
"For",
")",
"sequence",
";",
"seqFor",
".",
"initialize",
"(",
"length",
")",
";",
"if",
"(",
"seqFor",
".",
"getStep",
"(",
")",
"==",
"1",
")",
"{",
"lower",
"=",
"seqFor",
".",
"getStart",
"(",
")",
";",
"upper",
"=",
"seqFor",
".",
"getEnd",
"(",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"var",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"SCALAR",
")",
"{",
"lower",
"=",
"upper",
"=",
"(",
"(",
"VariableInteger",
")",
"var",
")",
".",
"value",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"How did a bad variable get put here?!?!\"",
")",
";",
"}",
"if",
"(",
"row",
")",
"{",
"e",
".",
"row0",
"=",
"lower",
";",
"e",
".",
"row1",
"=",
"upper",
";",
"}",
"else",
"{",
"e",
".",
"col0",
"=",
"lower",
";",
"e",
".",
"col1",
"=",
"upper",
";",
"}",
"return",
"true",
";",
"}"
] |
See if a simple sequence can be used to extract the array. A simple extent is a continuous block from
a min to max index
@return true if it is a simple range or false if not
|
[
"See",
"if",
"a",
"simple",
"sequence",
"can",
"be",
"used",
"to",
"extract",
"the",
"array",
".",
"A",
"simple",
"extent",
"is",
"a",
"continuous",
"block",
"from",
"a",
"min",
"to",
"max",
"index"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Operation.java#L1686-L1716
|
162,410 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.add
|
public Token add( Function function ) {
Token t = new Token(function);
push( t );
return t;
}
|
java
|
public Token add( Function function ) {
Token t = new Token(function);
push( t );
return t;
}
|
[
"public",
"Token",
"add",
"(",
"Function",
"function",
")",
"{",
"Token",
"t",
"=",
"new",
"Token",
"(",
"function",
")",
";",
"push",
"(",
"t",
")",
";",
"return",
"t",
";",
"}"
] |
Adds a function to the end of the token list
@param function Function which is to be added
@return The new Token created around function
|
[
"Adds",
"a",
"function",
"to",
"the",
"end",
"of",
"the",
"token",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L57-L61
|
162,411 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.add
|
public Token add( Variable variable ) {
Token t = new Token(variable);
push( t );
return t;
}
|
java
|
public Token add( Variable variable ) {
Token t = new Token(variable);
push( t );
return t;
}
|
[
"public",
"Token",
"add",
"(",
"Variable",
"variable",
")",
"{",
"Token",
"t",
"=",
"new",
"Token",
"(",
"variable",
")",
";",
"push",
"(",
"t",
")",
";",
"return",
"t",
";",
"}"
] |
Adds a variable to the end of the token list
@param variable Variable which is to be added
@return The new Token created around variable
|
[
"Adds",
"a",
"variable",
"to",
"the",
"end",
"of",
"the",
"token",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L68-L72
|
162,412 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.add
|
public Token add( Symbol symbol ) {
Token t = new Token(symbol);
push( t );
return t;
}
|
java
|
public Token add( Symbol symbol ) {
Token t = new Token(symbol);
push( t );
return t;
}
|
[
"public",
"Token",
"add",
"(",
"Symbol",
"symbol",
")",
"{",
"Token",
"t",
"=",
"new",
"Token",
"(",
"symbol",
")",
";",
"push",
"(",
"t",
")",
";",
"return",
"t",
";",
"}"
] |
Adds a symbol to the end of the token list
@param symbol Symbol which is to be added
@return The new Token created around symbol
|
[
"Adds",
"a",
"symbol",
"to",
"the",
"end",
"of",
"the",
"token",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L79-L83
|
162,413 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.add
|
public Token add( String word ) {
Token t = new Token(word);
push( t );
return t;
}
|
java
|
public Token add( String word ) {
Token t = new Token(word);
push( t );
return t;
}
|
[
"public",
"Token",
"add",
"(",
"String",
"word",
")",
"{",
"Token",
"t",
"=",
"new",
"Token",
"(",
"word",
")",
";",
"push",
"(",
"t",
")",
";",
"return",
"t",
";",
"}"
] |
Adds a word to the end of the token list
@param word word which is to be added
@return The new Token created around symbol
|
[
"Adds",
"a",
"word",
"to",
"the",
"end",
"of",
"the",
"token",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L90-L94
|
162,414 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.push
|
public void push( Token token ) {
size++;
if( first == null ) {
first = token;
last = token;
token.previous = null;
token.next = null;
} else {
last.next = token;
token.previous = last;
token.next = null;
last = token;
}
}
|
java
|
public void push( Token token ) {
size++;
if( first == null ) {
first = token;
last = token;
token.previous = null;
token.next = null;
} else {
last.next = token;
token.previous = last;
token.next = null;
last = token;
}
}
|
[
"public",
"void",
"push",
"(",
"Token",
"token",
")",
"{",
"size",
"++",
";",
"if",
"(",
"first",
"==",
"null",
")",
"{",
"first",
"=",
"token",
";",
"last",
"=",
"token",
";",
"token",
".",
"previous",
"=",
"null",
";",
"token",
".",
"next",
"=",
"null",
";",
"}",
"else",
"{",
"last",
".",
"next",
"=",
"token",
";",
"token",
".",
"previous",
"=",
"last",
";",
"token",
".",
"next",
"=",
"null",
";",
"last",
"=",
"token",
";",
"}",
"}"
] |
Adds a new Token to the end of the linked list
|
[
"Adds",
"a",
"new",
"Token",
"to",
"the",
"end",
"of",
"the",
"linked",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L99-L112
|
162,415 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.insert
|
public void insert( Token where , Token token ) {
if( where == null ) {
// put at the front of the list
if( size == 0 )
push(token);
else {
first.previous = token;
token.previous = null;
token.next = first;
first = token;
size++;
}
} else if( where == last || null == last ) {
push(token);
} else {
token.next = where.next;
token.previous = where;
where.next.previous = token;
where.next = token;
size++;
}
}
|
java
|
public void insert( Token where , Token token ) {
if( where == null ) {
// put at the front of the list
if( size == 0 )
push(token);
else {
first.previous = token;
token.previous = null;
token.next = first;
first = token;
size++;
}
} else if( where == last || null == last ) {
push(token);
} else {
token.next = where.next;
token.previous = where;
where.next.previous = token;
where.next = token;
size++;
}
}
|
[
"public",
"void",
"insert",
"(",
"Token",
"where",
",",
"Token",
"token",
")",
"{",
"if",
"(",
"where",
"==",
"null",
")",
"{",
"// put at the front of the list",
"if",
"(",
"size",
"==",
"0",
")",
"push",
"(",
"token",
")",
";",
"else",
"{",
"first",
".",
"previous",
"=",
"token",
";",
"token",
".",
"previous",
"=",
"null",
";",
"token",
".",
"next",
"=",
"first",
";",
"first",
"=",
"token",
";",
"size",
"++",
";",
"}",
"}",
"else",
"if",
"(",
"where",
"==",
"last",
"||",
"null",
"==",
"last",
")",
"{",
"push",
"(",
"token",
")",
";",
"}",
"else",
"{",
"token",
".",
"next",
"=",
"where",
".",
"next",
";",
"token",
".",
"previous",
"=",
"where",
";",
"where",
".",
"next",
".",
"previous",
"=",
"token",
";",
"where",
".",
"next",
"=",
"token",
";",
"size",
"++",
";",
"}",
"}"
] |
Inserts 'token' after 'where'. if where is null then it is inserted to the beginning of the list.
@param where Where 'token' should be inserted after. if null the put at it at the beginning
@param token The token that is to be inserted
|
[
"Inserts",
"token",
"after",
"where",
".",
"if",
"where",
"is",
"null",
"then",
"it",
"is",
"inserted",
"to",
"the",
"beginning",
"of",
"the",
"list",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L119-L140
|
162,416 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.remove
|
public void remove( Token token ) {
if( token == first ) {
first = first.next;
}
if( token == last ) {
last = last.previous;
}
if( token.next != null ) {
token.next.previous = token.previous;
}
if( token.previous != null ) {
token.previous.next = token.next;
}
token.next = token.previous = null;
size--;
}
|
java
|
public void remove( Token token ) {
if( token == first ) {
first = first.next;
}
if( token == last ) {
last = last.previous;
}
if( token.next != null ) {
token.next.previous = token.previous;
}
if( token.previous != null ) {
token.previous.next = token.next;
}
token.next = token.previous = null;
size--;
}
|
[
"public",
"void",
"remove",
"(",
"Token",
"token",
")",
"{",
"if",
"(",
"token",
"==",
"first",
")",
"{",
"first",
"=",
"first",
".",
"next",
";",
"}",
"if",
"(",
"token",
"==",
"last",
")",
"{",
"last",
"=",
"last",
".",
"previous",
";",
"}",
"if",
"(",
"token",
".",
"next",
"!=",
"null",
")",
"{",
"token",
".",
"next",
".",
"previous",
"=",
"token",
".",
"previous",
";",
"}",
"if",
"(",
"token",
".",
"previous",
"!=",
"null",
")",
"{",
"token",
".",
"previous",
".",
"next",
"=",
"token",
".",
"next",
";",
"}",
"token",
".",
"next",
"=",
"token",
".",
"previous",
"=",
"null",
";",
"size",
"--",
";",
"}"
] |
Removes the token from the list
@param token Token which is to be removed
|
[
"Removes",
"the",
"token",
"from",
"the",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L146-L162
|
162,417 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.replace
|
public void replace( Token original , Token target ) {
if( first == original )
first = target;
if( last == original )
last = target;
target.next = original.next;
target.previous = original.previous;
if( original.next != null )
original.next.previous = target;
if( original.previous != null )
original.previous.next = target;
original.next = original.previous = null;
}
|
java
|
public void replace( Token original , Token target ) {
if( first == original )
first = target;
if( last == original )
last = target;
target.next = original.next;
target.previous = original.previous;
if( original.next != null )
original.next.previous = target;
if( original.previous != null )
original.previous.next = target;
original.next = original.previous = null;
}
|
[
"public",
"void",
"replace",
"(",
"Token",
"original",
",",
"Token",
"target",
")",
"{",
"if",
"(",
"first",
"==",
"original",
")",
"first",
"=",
"target",
";",
"if",
"(",
"last",
"==",
"original",
")",
"last",
"=",
"target",
";",
"target",
".",
"next",
"=",
"original",
".",
"next",
";",
"target",
".",
"previous",
"=",
"original",
".",
"previous",
";",
"if",
"(",
"original",
".",
"next",
"!=",
"null",
")",
"original",
".",
"next",
".",
"previous",
"=",
"target",
";",
"if",
"(",
"original",
".",
"previous",
"!=",
"null",
")",
"original",
".",
"previous",
".",
"next",
"=",
"target",
";",
"original",
".",
"next",
"=",
"original",
".",
"previous",
"=",
"null",
";",
"}"
] |
Removes 'original' and places 'target' at the same location
|
[
"Removes",
"original",
"and",
"places",
"target",
"at",
"the",
"same",
"location"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L167-L182
|
162,418 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.extractSubList
|
public TokenList extractSubList( Token begin , Token end ) {
if( begin == end ) {
remove(begin);
return new TokenList(begin,begin);
} else {
if( first == begin ) {
first = end.next;
}
if( last == end ) {
last = begin.previous;
}
if( begin.previous != null ) {
begin.previous.next = end.next;
}
if( end.next != null ) {
end.next.previous = begin.previous;
}
begin.previous = null;
end.next = null;
TokenList ret = new TokenList(begin,end);
size -= ret.size();
return ret;
}
}
|
java
|
public TokenList extractSubList( Token begin , Token end ) {
if( begin == end ) {
remove(begin);
return new TokenList(begin,begin);
} else {
if( first == begin ) {
first = end.next;
}
if( last == end ) {
last = begin.previous;
}
if( begin.previous != null ) {
begin.previous.next = end.next;
}
if( end.next != null ) {
end.next.previous = begin.previous;
}
begin.previous = null;
end.next = null;
TokenList ret = new TokenList(begin,end);
size -= ret.size();
return ret;
}
}
|
[
"public",
"TokenList",
"extractSubList",
"(",
"Token",
"begin",
",",
"Token",
"end",
")",
"{",
"if",
"(",
"begin",
"==",
"end",
")",
"{",
"remove",
"(",
"begin",
")",
";",
"return",
"new",
"TokenList",
"(",
"begin",
",",
"begin",
")",
";",
"}",
"else",
"{",
"if",
"(",
"first",
"==",
"begin",
")",
"{",
"first",
"=",
"end",
".",
"next",
";",
"}",
"if",
"(",
"last",
"==",
"end",
")",
"{",
"last",
"=",
"begin",
".",
"previous",
";",
"}",
"if",
"(",
"begin",
".",
"previous",
"!=",
"null",
")",
"{",
"begin",
".",
"previous",
".",
"next",
"=",
"end",
".",
"next",
";",
"}",
"if",
"(",
"end",
".",
"next",
"!=",
"null",
")",
"{",
"end",
".",
"next",
".",
"previous",
"=",
"begin",
".",
"previous",
";",
"}",
"begin",
".",
"previous",
"=",
"null",
";",
"end",
".",
"next",
"=",
"null",
";",
"TokenList",
"ret",
"=",
"new",
"TokenList",
"(",
"begin",
",",
"end",
")",
";",
"size",
"-=",
"ret",
".",
"size",
"(",
")",
";",
"return",
"ret",
";",
"}",
"}"
] |
Removes elements from begin to end from the list, inclusive. Returns a new list which
is composed of the removed elements
|
[
"Removes",
"elements",
"from",
"begin",
"to",
"end",
"from",
"the",
"list",
"inclusive",
".",
"Returns",
"a",
"new",
"list",
"which",
"is",
"composed",
"of",
"the",
"removed",
"elements"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L188-L212
|
162,419 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/TokenList.java
|
TokenList.insertAfter
|
public void insertAfter(Token before, TokenList list ) {
Token after = before.next;
before.next = list.first;
list.first.previous = before;
if( after == null ) {
last = list.last;
} else {
after.previous = list.last;
list.last.next = after;
}
size += list.size;
}
|
java
|
public void insertAfter(Token before, TokenList list ) {
Token after = before.next;
before.next = list.first;
list.first.previous = before;
if( after == null ) {
last = list.last;
} else {
after.previous = list.last;
list.last.next = after;
}
size += list.size;
}
|
[
"public",
"void",
"insertAfter",
"(",
"Token",
"before",
",",
"TokenList",
"list",
")",
"{",
"Token",
"after",
"=",
"before",
".",
"next",
";",
"before",
".",
"next",
"=",
"list",
".",
"first",
";",
"list",
".",
"first",
".",
"previous",
"=",
"before",
";",
"if",
"(",
"after",
"==",
"null",
")",
"{",
"last",
"=",
"list",
".",
"last",
";",
"}",
"else",
"{",
"after",
".",
"previous",
"=",
"list",
".",
"last",
";",
"list",
".",
"last",
".",
"next",
"=",
"after",
";",
"}",
"size",
"+=",
"list",
".",
"size",
";",
"}"
] |
Inserts the LokenList immediately following the 'before' token
|
[
"Inserts",
"the",
"LokenList",
"immediately",
"following",
"the",
"before",
"token"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/TokenList.java#L217-L229
|
162,420 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/CovarianceOps_DDRM.java
|
CovarianceOps_DDRM.isValid
|
public static int isValid( DMatrixRMaj cov ) {
if( !MatrixFeatures_DDRM.isDiagonalPositive(cov) )
return 1;
if( !MatrixFeatures_DDRM.isSymmetric(cov,TOL) )
return 2;
if( !MatrixFeatures_DDRM.isPositiveSemidefinite(cov) )
return 3;
return 0;
}
|
java
|
public static int isValid( DMatrixRMaj cov ) {
if( !MatrixFeatures_DDRM.isDiagonalPositive(cov) )
return 1;
if( !MatrixFeatures_DDRM.isSymmetric(cov,TOL) )
return 2;
if( !MatrixFeatures_DDRM.isPositiveSemidefinite(cov) )
return 3;
return 0;
}
|
[
"public",
"static",
"int",
"isValid",
"(",
"DMatrixRMaj",
"cov",
")",
"{",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isDiagonalPositive",
"(",
"cov",
")",
")",
"return",
"1",
";",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isSymmetric",
"(",
"cov",
",",
"TOL",
")",
")",
"return",
"2",
";",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isPositiveSemidefinite",
"(",
"cov",
")",
")",
"return",
"3",
";",
"return",
"0",
";",
"}"
] |
Performs a variety of tests to see if the provided matrix is a valid
covariance matrix.
@return 0 = is valid 1 = failed positive diagonal, 2 = failed on symmetry, 2 = failed on positive definite
|
[
"Performs",
"a",
"variety",
"of",
"tests",
"to",
"see",
"if",
"the",
"provided",
"matrix",
"is",
"a",
"valid",
"covariance",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CovarianceOps_DDRM.java#L57-L68
|
162,421 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/CovarianceOps_DDRM.java
|
CovarianceOps_DDRM.invert
|
public static boolean invert(final DMatrixRMaj cov , final DMatrixRMaj cov_inv ) {
if( cov.numCols <= 4 ) {
if( cov.numCols != cov.numRows ) {
throw new IllegalArgumentException("Must be a square matrix.");
}
if( cov.numCols >= 2 )
UnrolledInverseFromMinor_DDRM.inv(cov,cov_inv);
else
cov_inv.data[0] = 1.0/cov.data[0];
} else {
LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.symmPosDef(cov.numRows);
// wrap it to make sure the covariance is not modified.
solver = new LinearSolverSafe<DMatrixRMaj>(solver);
if( !solver.setA(cov) )
return false;
solver.invert(cov_inv);
}
return true;
}
|
java
|
public static boolean invert(final DMatrixRMaj cov , final DMatrixRMaj cov_inv ) {
if( cov.numCols <= 4 ) {
if( cov.numCols != cov.numRows ) {
throw new IllegalArgumentException("Must be a square matrix.");
}
if( cov.numCols >= 2 )
UnrolledInverseFromMinor_DDRM.inv(cov,cov_inv);
else
cov_inv.data[0] = 1.0/cov.data[0];
} else {
LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.symmPosDef(cov.numRows);
// wrap it to make sure the covariance is not modified.
solver = new LinearSolverSafe<DMatrixRMaj>(solver);
if( !solver.setA(cov) )
return false;
solver.invert(cov_inv);
}
return true;
}
|
[
"public",
"static",
"boolean",
"invert",
"(",
"final",
"DMatrixRMaj",
"cov",
",",
"final",
"DMatrixRMaj",
"cov_inv",
")",
"{",
"if",
"(",
"cov",
".",
"numCols",
"<=",
"4",
")",
"{",
"if",
"(",
"cov",
".",
"numCols",
"!=",
"cov",
".",
"numRows",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Must be a square matrix.\"",
")",
";",
"}",
"if",
"(",
"cov",
".",
"numCols",
">=",
"2",
")",
"UnrolledInverseFromMinor_DDRM",
".",
"inv",
"(",
"cov",
",",
"cov_inv",
")",
";",
"else",
"cov_inv",
".",
"data",
"[",
"0",
"]",
"=",
"1.0",
"/",
"cov",
".",
"data",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"LinearSolverDense",
"<",
"DMatrixRMaj",
">",
"solver",
"=",
"LinearSolverFactory_DDRM",
".",
"symmPosDef",
"(",
"cov",
".",
"numRows",
")",
";",
"// wrap it to make sure the covariance is not modified.",
"solver",
"=",
"new",
"LinearSolverSafe",
"<",
"DMatrixRMaj",
">",
"(",
"solver",
")",
";",
"if",
"(",
"!",
"solver",
".",
"setA",
"(",
"cov",
")",
")",
"return",
"false",
";",
"solver",
".",
"invert",
"(",
"cov_inv",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Performs a matrix inversion operations that takes advantage of the special
properties of a covariance matrix.
@param cov A covariance matrix. Not modified.
@param cov_inv The inverse of cov. Modified.
@return true if it could invert the matrix false if it could not.
|
[
"Performs",
"a",
"matrix",
"inversion",
"operations",
"that",
"takes",
"advantage",
"of",
"the",
"special",
"properties",
"of",
"a",
"covariance",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CovarianceOps_DDRM.java#L89-L109
|
162,422 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/BMatrixRMaj.java
|
BMatrixRMaj.sum
|
public int sum() {
int total = 0;
int N = getNumElements();
for (int i = 0; i < N; i++) {
if( data[i] )
total += 1;
}
return total;
}
|
java
|
public int sum() {
int total = 0;
int N = getNumElements();
for (int i = 0; i < N; i++) {
if( data[i] )
total += 1;
}
return total;
}
|
[
"public",
"int",
"sum",
"(",
")",
"{",
"int",
"total",
"=",
"0",
";",
"int",
"N",
"=",
"getNumElements",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"i",
"]",
")",
"total",
"+=",
"1",
";",
"}",
"return",
"total",
";",
"}"
] |
Returns the total number of elements which are true.
@return number of elements which are set to true
|
[
"Returns",
"the",
"total",
"number",
"of",
"elements",
"which",
"are",
"true",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/BMatrixRMaj.java#L103-L111
|
162,423 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java
|
BidiagonalDecompositionRow_DDRM.init
|
protected void init(DMatrixRMaj A ) {
UBV = A;
m = UBV.numRows;
n = UBV.numCols;
min = Math.min(m,n);
int max = Math.max(m,n);
if( b.length < max+1 ) {
b = new double[ max+1 ];
u = new double[ max+1 ];
}
if( gammasU.length < m ) {
gammasU = new double[ m ];
}
if( gammasV.length < n ) {
gammasV = new double[ n ];
}
}
|
java
|
protected void init(DMatrixRMaj A ) {
UBV = A;
m = UBV.numRows;
n = UBV.numCols;
min = Math.min(m,n);
int max = Math.max(m,n);
if( b.length < max+1 ) {
b = new double[ max+1 ];
u = new double[ max+1 ];
}
if( gammasU.length < m ) {
gammasU = new double[ m ];
}
if( gammasV.length < n ) {
gammasV = new double[ n ];
}
}
|
[
"protected",
"void",
"init",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"UBV",
"=",
"A",
";",
"m",
"=",
"UBV",
".",
"numRows",
";",
"n",
"=",
"UBV",
".",
"numCols",
";",
"min",
"=",
"Math",
".",
"min",
"(",
"m",
",",
"n",
")",
";",
"int",
"max",
"=",
"Math",
".",
"max",
"(",
"m",
",",
"n",
")",
";",
"if",
"(",
"b",
".",
"length",
"<",
"max",
"+",
"1",
")",
"{",
"b",
"=",
"new",
"double",
"[",
"max",
"+",
"1",
"]",
";",
"u",
"=",
"new",
"double",
"[",
"max",
"+",
"1",
"]",
";",
"}",
"if",
"(",
"gammasU",
".",
"length",
"<",
"m",
")",
"{",
"gammasU",
"=",
"new",
"double",
"[",
"m",
"]",
";",
"}",
"if",
"(",
"gammasV",
".",
"length",
"<",
"n",
")",
"{",
"gammasV",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"}",
"}"
] |
Sets up internal data structures and creates a copy of the input matrix.
@param A The input matrix. Not modified.
|
[
"Sets",
"up",
"internal",
"data",
"structures",
"and",
"creates",
"a",
"copy",
"of",
"the",
"input",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java#L91-L110
|
162,424 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java
|
BidiagonalDecompositionRow_DDRM.getU
|
@Override
public DMatrixRMaj getU(DMatrixRMaj U , boolean transpose , boolean compact ) {
U = handleU(U, transpose, compact,m,n,min);
CommonOps_DDRM.setIdentity(U);
for( int i = 0; i < m; i++ ) u[i] = 0;
for( int j = min-1; j >= 0; j-- ) {
u[j] = 1;
for( int i = j+1; i < m; i++ ) {
u[i] = UBV.get(i,j);
}
if( transpose )
QrHelperFunctions_DDRM.rank1UpdateMultL(U, u, gammasU[j], j, j, m);
else
QrHelperFunctions_DDRM.rank1UpdateMultR(U, u, gammasU[j], j, j, m, this.b);
}
return U;
}
|
java
|
@Override
public DMatrixRMaj getU(DMatrixRMaj U , boolean transpose , boolean compact ) {
U = handleU(U, transpose, compact,m,n,min);
CommonOps_DDRM.setIdentity(U);
for( int i = 0; i < m; i++ ) u[i] = 0;
for( int j = min-1; j >= 0; j-- ) {
u[j] = 1;
for( int i = j+1; i < m; i++ ) {
u[i] = UBV.get(i,j);
}
if( transpose )
QrHelperFunctions_DDRM.rank1UpdateMultL(U, u, gammasU[j], j, j, m);
else
QrHelperFunctions_DDRM.rank1UpdateMultR(U, u, gammasU[j], j, j, m, this.b);
}
return U;
}
|
[
"@",
"Override",
"public",
"DMatrixRMaj",
"getU",
"(",
"DMatrixRMaj",
"U",
",",
"boolean",
"transpose",
",",
"boolean",
"compact",
")",
"{",
"U",
"=",
"handleU",
"(",
"U",
",",
"transpose",
",",
"compact",
",",
"m",
",",
"n",
",",
"min",
")",
";",
"CommonOps_DDRM",
".",
"setIdentity",
"(",
"U",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"m",
";",
"i",
"++",
")",
"u",
"[",
"i",
"]",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"min",
"-",
"1",
";",
"j",
">=",
"0",
";",
"j",
"--",
")",
"{",
"u",
"[",
"j",
"]",
"=",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"j",
"+",
"1",
";",
"i",
"<",
"m",
";",
"i",
"++",
")",
"{",
"u",
"[",
"i",
"]",
"=",
"UBV",
".",
"get",
"(",
"i",
",",
"j",
")",
";",
"}",
"if",
"(",
"transpose",
")",
"QrHelperFunctions_DDRM",
".",
"rank1UpdateMultL",
"(",
"U",
",",
"u",
",",
"gammasU",
"[",
"j",
"]",
",",
"j",
",",
"j",
",",
"m",
")",
";",
"else",
"QrHelperFunctions_DDRM",
".",
"rank1UpdateMultR",
"(",
"U",
",",
"u",
",",
"gammasU",
"[",
"j",
"]",
",",
"j",
",",
"j",
",",
"m",
",",
"this",
".",
"b",
")",
";",
"}",
"return",
"U",
";",
"}"
] |
Returns the orthogonal U matrix.
@param U If not null then the results will be stored here. Otherwise a new matrix will be created.
@return The extracted Q matrix.
|
[
"Returns",
"the",
"orthogonal",
"U",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java#L181-L200
|
162,425 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java
|
BidiagonalDecompositionRow_DDRM.getV
|
@Override
public DMatrixRMaj getV(DMatrixRMaj V , boolean transpose , boolean compact ) {
V = handleV(V, transpose, compact,m,n,min);
CommonOps_DDRM.setIdentity(V);
// UBV.print();
// todo the very first multiplication can be avoided by setting to the rank1update output
for( int j = min-1; j >= 0; j-- ) {
u[j+1] = 1;
for( int i = j+2; i < n; i++ ) {
u[i] = UBV.get(j,i);
}
if( transpose )
QrHelperFunctions_DDRM.rank1UpdateMultL(V, u, gammasV[j], j + 1, j + 1, n);
else
QrHelperFunctions_DDRM.rank1UpdateMultR(V, u, gammasV[j], j + 1, j + 1, n, this.b);
}
return V;
}
|
java
|
@Override
public DMatrixRMaj getV(DMatrixRMaj V , boolean transpose , boolean compact ) {
V = handleV(V, transpose, compact,m,n,min);
CommonOps_DDRM.setIdentity(V);
// UBV.print();
// todo the very first multiplication can be avoided by setting to the rank1update output
for( int j = min-1; j >= 0; j-- ) {
u[j+1] = 1;
for( int i = j+2; i < n; i++ ) {
u[i] = UBV.get(j,i);
}
if( transpose )
QrHelperFunctions_DDRM.rank1UpdateMultL(V, u, gammasV[j], j + 1, j + 1, n);
else
QrHelperFunctions_DDRM.rank1UpdateMultR(V, u, gammasV[j], j + 1, j + 1, n, this.b);
}
return V;
}
|
[
"@",
"Override",
"public",
"DMatrixRMaj",
"getV",
"(",
"DMatrixRMaj",
"V",
",",
"boolean",
"transpose",
",",
"boolean",
"compact",
")",
"{",
"V",
"=",
"handleV",
"(",
"V",
",",
"transpose",
",",
"compact",
",",
"m",
",",
"n",
",",
"min",
")",
";",
"CommonOps_DDRM",
".",
"setIdentity",
"(",
"V",
")",
";",
"// UBV.print();",
"// todo the very first multiplication can be avoided by setting to the rank1update output",
"for",
"(",
"int",
"j",
"=",
"min",
"-",
"1",
";",
"j",
">=",
"0",
";",
"j",
"--",
")",
"{",
"u",
"[",
"j",
"+",
"1",
"]",
"=",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"j",
"+",
"2",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"u",
"[",
"i",
"]",
"=",
"UBV",
".",
"get",
"(",
"j",
",",
"i",
")",
";",
"}",
"if",
"(",
"transpose",
")",
"QrHelperFunctions_DDRM",
".",
"rank1UpdateMultL",
"(",
"V",
",",
"u",
",",
"gammasV",
"[",
"j",
"]",
",",
"j",
"+",
"1",
",",
"j",
"+",
"1",
",",
"n",
")",
";",
"else",
"QrHelperFunctions_DDRM",
".",
"rank1UpdateMultR",
"(",
"V",
",",
"u",
",",
"gammasV",
"[",
"j",
"]",
",",
"j",
"+",
"1",
",",
"j",
"+",
"1",
",",
"n",
",",
"this",
".",
"b",
")",
";",
"}",
"return",
"V",
";",
"}"
] |
Returns the orthogonal V matrix.
@param V If not null then the results will be stored here. Otherwise a new matrix will be created.
@return The extracted Q matrix.
|
[
"Returns",
"the",
"orthogonal",
"V",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/bidiagonal/BidiagonalDecompositionRow_DDRM.java#L234-L254
|
162,426 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/UtilEjml.java
|
UtilEjml.safe
|
public static <S extends Matrix, D extends Matrix> LinearSolver<S,D> safe(LinearSolver<S,D> solver ) {
if( solver.modifiesA() || solver.modifiesB() ) {
if( solver instanceof LinearSolverDense ) {
return new LinearSolverSafe((LinearSolverDense)solver);
} else if( solver instanceof LinearSolverSparse ) {
return new LinearSolverSparseSafe((LinearSolverSparse)solver);
} else {
throw new IllegalArgumentException("Unknown solver type");
}
} else {
return solver;
}
}
|
java
|
public static <S extends Matrix, D extends Matrix> LinearSolver<S,D> safe(LinearSolver<S,D> solver ) {
if( solver.modifiesA() || solver.modifiesB() ) {
if( solver instanceof LinearSolverDense ) {
return new LinearSolverSafe((LinearSolverDense)solver);
} else if( solver instanceof LinearSolverSparse ) {
return new LinearSolverSparseSafe((LinearSolverSparse)solver);
} else {
throw new IllegalArgumentException("Unknown solver type");
}
} else {
return solver;
}
}
|
[
"public",
"static",
"<",
"S",
"extends",
"Matrix",
",",
"D",
"extends",
"Matrix",
">",
"LinearSolver",
"<",
"S",
",",
"D",
">",
"safe",
"(",
"LinearSolver",
"<",
"S",
",",
"D",
">",
"solver",
")",
"{",
"if",
"(",
"solver",
".",
"modifiesA",
"(",
")",
"||",
"solver",
".",
"modifiesB",
"(",
")",
")",
"{",
"if",
"(",
"solver",
"instanceof",
"LinearSolverDense",
")",
"{",
"return",
"new",
"LinearSolverSafe",
"(",
"(",
"LinearSolverDense",
")",
"solver",
")",
";",
"}",
"else",
"if",
"(",
"solver",
"instanceof",
"LinearSolverSparse",
")",
"{",
"return",
"new",
"LinearSolverSparseSafe",
"(",
"(",
"LinearSolverSparse",
")",
"solver",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown solver type\"",
")",
";",
"}",
"}",
"else",
"{",
"return",
"solver",
";",
"}",
"}"
] |
Wraps a linear solver of any type with a safe solver the ensures inputs are not modified
|
[
"Wraps",
"a",
"linear",
"solver",
"of",
"any",
"type",
"with",
"a",
"safe",
"solver",
"the",
"ensures",
"inputs",
"are",
"not",
"modified"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/UtilEjml.java#L64-L76
|
162,427 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/UtilEjml.java
|
UtilEjml.fancyStringF
|
public static String fancyStringF(double value, DecimalFormat format, int length, int significant) {
String formatted = fancyString(value, format, length, significant);
int n = length-formatted.length();
if( n > 0 ) {
StringBuilder builder = new StringBuilder(n);
for (int i = 0; i < n; i++) {
builder.append(' ');
}
return formatted + builder.toString();
} else {
return formatted;
}
}
|
java
|
public static String fancyStringF(double value, DecimalFormat format, int length, int significant) {
String formatted = fancyString(value, format, length, significant);
int n = length-formatted.length();
if( n > 0 ) {
StringBuilder builder = new StringBuilder(n);
for (int i = 0; i < n; i++) {
builder.append(' ');
}
return formatted + builder.toString();
} else {
return formatted;
}
}
|
[
"public",
"static",
"String",
"fancyStringF",
"(",
"double",
"value",
",",
"DecimalFormat",
"format",
",",
"int",
"length",
",",
"int",
"significant",
")",
"{",
"String",
"formatted",
"=",
"fancyString",
"(",
"value",
",",
"format",
",",
"length",
",",
"significant",
")",
";",
"int",
"n",
"=",
"length",
"-",
"formatted",
".",
"length",
"(",
")",
";",
"if",
"(",
"n",
">",
"0",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
"n",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"builder",
".",
"append",
"(",
"'",
"'",
")",
";",
"}",
"return",
"formatted",
"+",
"builder",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"return",
"formatted",
";",
"}",
"}"
] |
Fixed length fancy formatting for doubles. If possible decimal notation is used. If all the significant digits
can't be shown then it will switch to exponential notation. If not all the space is needed then it will
be filled in to ensure it has the specified length.
@param value value being formatted
@param format default format before exponential
@param length Maximum number of characters it can take.
@param significant Number of significant decimal digits to show at a minimum.
@return formatted string
|
[
"Fixed",
"length",
"fancy",
"formatting",
"for",
"doubles",
".",
"If",
"possible",
"decimal",
"notation",
"is",
"used",
".",
"If",
"all",
"the",
"significant",
"digits",
"can",
"t",
"be",
"shown",
"then",
"it",
"will",
"switch",
"to",
"exponential",
"notation",
".",
"If",
"not",
"all",
"the",
"space",
"is",
"needed",
"then",
"it",
"will",
"be",
"filled",
"in",
"to",
"ensure",
"it",
"has",
"the",
"specified",
"length",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/UtilEjml.java#L336-L350
|
162,428 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.performDynamicStep
|
private void performDynamicStep() {
// initially look for singular values of zero
if( findingZeros ) {
if( steps > 6 ) {
findingZeros = false;
} else {
double scale = computeBulgeScale();
performImplicitSingleStep(scale,0,false);
}
} else {
// For very large and very small numbers the only way to prevent overflow/underflow
// is to have a common scale between the wilkinson shift and the implicit single step
// What happens if you don't is that when the wilkinson shift returns the value it
// computed it multiplies it by the scale twice, which will cause an overflow
double scale = computeBulgeScale();
// use the wilkinson shift to perform a step
double lambda = selectWilkinsonShift(scale);
performImplicitSingleStep(scale,lambda,false);
}
}
|
java
|
private void performDynamicStep() {
// initially look for singular values of zero
if( findingZeros ) {
if( steps > 6 ) {
findingZeros = false;
} else {
double scale = computeBulgeScale();
performImplicitSingleStep(scale,0,false);
}
} else {
// For very large and very small numbers the only way to prevent overflow/underflow
// is to have a common scale between the wilkinson shift and the implicit single step
// What happens if you don't is that when the wilkinson shift returns the value it
// computed it multiplies it by the scale twice, which will cause an overflow
double scale = computeBulgeScale();
// use the wilkinson shift to perform a step
double lambda = selectWilkinsonShift(scale);
performImplicitSingleStep(scale,lambda,false);
}
}
|
[
"private",
"void",
"performDynamicStep",
"(",
")",
"{",
"// initially look for singular values of zero",
"if",
"(",
"findingZeros",
")",
"{",
"if",
"(",
"steps",
">",
"6",
")",
"{",
"findingZeros",
"=",
"false",
";",
"}",
"else",
"{",
"double",
"scale",
"=",
"computeBulgeScale",
"(",
")",
";",
"performImplicitSingleStep",
"(",
"scale",
",",
"0",
",",
"false",
")",
";",
"}",
"}",
"else",
"{",
"// For very large and very small numbers the only way to prevent overflow/underflow",
"// is to have a common scale between the wilkinson shift and the implicit single step",
"// What happens if you don't is that when the wilkinson shift returns the value it",
"// computed it multiplies it by the scale twice, which will cause an overflow",
"double",
"scale",
"=",
"computeBulgeScale",
"(",
")",
";",
"// use the wilkinson shift to perform a step",
"double",
"lambda",
"=",
"selectWilkinsonShift",
"(",
"scale",
")",
";",
"performImplicitSingleStep",
"(",
"scale",
",",
"lambda",
",",
"false",
")",
";",
"}",
"}"
] |
Here the lambda in the implicit step is determined dynamically. At first
it selects zeros to quickly reveal singular values that are zero or close to zero.
Then it computes it using a Wilkinson shift.
|
[
"Here",
"the",
"lambda",
"in",
"the",
"implicit",
"step",
"is",
"determined",
"dynamically",
".",
"At",
"first",
"it",
"selects",
"zeros",
"to",
"quickly",
"reveal",
"singular",
"values",
"that",
"are",
"zero",
"or",
"close",
"to",
"zero",
".",
"Then",
"it",
"computes",
"it",
"using",
"a",
"Wilkinson",
"shift",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L270-L290
|
162,429 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.performScriptedStep
|
private void performScriptedStep() {
double scale = computeBulgeScale();
if( steps > giveUpOnKnown ) {
// give up on the script
followScript = false;
} else {
// use previous singular value to step
double s = values[x2]/scale;
performImplicitSingleStep(scale,s*s,false);
}
}
|
java
|
private void performScriptedStep() {
double scale = computeBulgeScale();
if( steps > giveUpOnKnown ) {
// give up on the script
followScript = false;
} else {
// use previous singular value to step
double s = values[x2]/scale;
performImplicitSingleStep(scale,s*s,false);
}
}
|
[
"private",
"void",
"performScriptedStep",
"(",
")",
"{",
"double",
"scale",
"=",
"computeBulgeScale",
"(",
")",
";",
"if",
"(",
"steps",
">",
"giveUpOnKnown",
")",
"{",
"// give up on the script",
"followScript",
"=",
"false",
";",
"}",
"else",
"{",
"// use previous singular value to step",
"double",
"s",
"=",
"values",
"[",
"x2",
"]",
"/",
"scale",
";",
"performImplicitSingleStep",
"(",
"scale",
",",
"s",
"*",
"s",
",",
"false",
")",
";",
"}",
"}"
] |
Shifts are performed based upon singular values computed previously. If it does not converge
using one of those singular values it uses a Wilkinson shift instead.
|
[
"Shifts",
"are",
"performed",
"based",
"upon",
"singular",
"values",
"computed",
"previously",
".",
"If",
"it",
"does",
"not",
"converge",
"using",
"one",
"of",
"those",
"singular",
"values",
"it",
"uses",
"a",
"Wilkinson",
"shift",
"instead",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L296-L306
|
162,430 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.nextSplit
|
public boolean nextSplit() {
if( numSplits == 0 )
return false;
x2 = splits[--numSplits];
if( numSplits > 0 )
x1 = splits[numSplits-1]+1;
else
x1 = 0;
return true;
}
|
java
|
public boolean nextSplit() {
if( numSplits == 0 )
return false;
x2 = splits[--numSplits];
if( numSplits > 0 )
x1 = splits[numSplits-1]+1;
else
x1 = 0;
return true;
}
|
[
"public",
"boolean",
"nextSplit",
"(",
")",
"{",
"if",
"(",
"numSplits",
"==",
"0",
")",
"return",
"false",
";",
"x2",
"=",
"splits",
"[",
"--",
"numSplits",
"]",
";",
"if",
"(",
"numSplits",
">",
"0",
")",
"x1",
"=",
"splits",
"[",
"numSplits",
"-",
"1",
"]",
"+",
"1",
";",
"else",
"x1",
"=",
"0",
";",
"return",
"true",
";",
"}"
] |
Tells it to process the submatrix at the next split. Should be called after the
current submatrix has been processed.
|
[
"Tells",
"it",
"to",
"process",
"the",
"submatrix",
"at",
"the",
"next",
"split",
".",
"Should",
"be",
"called",
"after",
"the",
"current",
"submatrix",
"has",
"been",
"processed",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L337-L347
|
162,431 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.performImplicitSingleStep
|
public void performImplicitSingleStep(double scale , double lambda , boolean byAngle) {
createBulge(x1,lambda,scale,byAngle);
for( int i = x1; i < x2-1 && bulge != 0.0; i++ ) {
removeBulgeLeft(i,true);
if( bulge == 0 )
break;
removeBulgeRight(i);
}
if( bulge != 0 )
removeBulgeLeft(x2-1,false);
incrementSteps();
}
|
java
|
public void performImplicitSingleStep(double scale , double lambda , boolean byAngle) {
createBulge(x1,lambda,scale,byAngle);
for( int i = x1; i < x2-1 && bulge != 0.0; i++ ) {
removeBulgeLeft(i,true);
if( bulge == 0 )
break;
removeBulgeRight(i);
}
if( bulge != 0 )
removeBulgeLeft(x2-1,false);
incrementSteps();
}
|
[
"public",
"void",
"performImplicitSingleStep",
"(",
"double",
"scale",
",",
"double",
"lambda",
",",
"boolean",
"byAngle",
")",
"{",
"createBulge",
"(",
"x1",
",",
"lambda",
",",
"scale",
",",
"byAngle",
")",
";",
"for",
"(",
"int",
"i",
"=",
"x1",
";",
"i",
"<",
"x2",
"-",
"1",
"&&",
"bulge",
"!=",
"0.0",
";",
"i",
"++",
")",
"{",
"removeBulgeLeft",
"(",
"i",
",",
"true",
")",
";",
"if",
"(",
"bulge",
"==",
"0",
")",
"break",
";",
"removeBulgeRight",
"(",
"i",
")",
";",
"}",
"if",
"(",
"bulge",
"!=",
"0",
")",
"removeBulgeLeft",
"(",
"x2",
"-",
"1",
",",
"false",
")",
";",
"incrementSteps",
"(",
")",
";",
"}"
] |
Given the lambda value perform an implicit QR step on the matrix.
B^T*B-lambda*I
@param lambda Stepping factor.
|
[
"Given",
"the",
"lambda",
"value",
"perform",
"an",
"implicit",
"QR",
"step",
"on",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L356-L370
|
162,432 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.updateRotator
|
protected void updateRotator(DMatrixRMaj Q , int m, int n, double c, double s) {
int rowA = m*Q.numCols;
int rowB = n*Q.numCols;
// for( int i = 0; i < Q.numCols; i++ ) {
// double a = Q.get(rowA+i);
// double b = Q.get(rowB+i);
// Q.set( rowA+i, c*a + s*b);
// Q.set( rowB+i, -s*a + c*b);
// }
// System.out.println("------ AFter Update Rotator "+m+" "+n);
// Q.print();
// System.out.println();
int endA = rowA + Q.numCols;
for( ; rowA != endA; rowA++ , rowB++ ) {
double a = Q.get(rowA);
double b = Q.get(rowB);
Q.set(rowA, c*a + s*b);
Q.set(rowB, -s*a + c*b);
}
}
|
java
|
protected void updateRotator(DMatrixRMaj Q , int m, int n, double c, double s) {
int rowA = m*Q.numCols;
int rowB = n*Q.numCols;
// for( int i = 0; i < Q.numCols; i++ ) {
// double a = Q.get(rowA+i);
// double b = Q.get(rowB+i);
// Q.set( rowA+i, c*a + s*b);
// Q.set( rowB+i, -s*a + c*b);
// }
// System.out.println("------ AFter Update Rotator "+m+" "+n);
// Q.print();
// System.out.println();
int endA = rowA + Q.numCols;
for( ; rowA != endA; rowA++ , rowB++ ) {
double a = Q.get(rowA);
double b = Q.get(rowB);
Q.set(rowA, c*a + s*b);
Q.set(rowB, -s*a + c*b);
}
}
|
[
"protected",
"void",
"updateRotator",
"(",
"DMatrixRMaj",
"Q",
",",
"int",
"m",
",",
"int",
"n",
",",
"double",
"c",
",",
"double",
"s",
")",
"{",
"int",
"rowA",
"=",
"m",
"*",
"Q",
".",
"numCols",
";",
"int",
"rowB",
"=",
"n",
"*",
"Q",
".",
"numCols",
";",
"// for( int i = 0; i < Q.numCols; i++ ) {",
"// double a = Q.get(rowA+i);",
"// double b = Q.get(rowB+i);",
"// Q.set( rowA+i, c*a + s*b);",
"// Q.set( rowB+i, -s*a + c*b);",
"// }",
"// System.out.println(\"------ AFter Update Rotator \"+m+\" \"+n);",
"// Q.print();",
"// System.out.println();",
"int",
"endA",
"=",
"rowA",
"+",
"Q",
".",
"numCols",
";",
"for",
"(",
";",
"rowA",
"!=",
"endA",
";",
"rowA",
"++",
",",
"rowB",
"++",
")",
"{",
"double",
"a",
"=",
"Q",
".",
"get",
"(",
"rowA",
")",
";",
"double",
"b",
"=",
"Q",
".",
"get",
"(",
"rowB",
")",
";",
"Q",
".",
"set",
"(",
"rowA",
",",
"c",
"*",
"a",
"+",
"s",
"*",
"b",
")",
";",
"Q",
".",
"set",
"(",
"rowB",
",",
"-",
"s",
"*",
"a",
"+",
"c",
"*",
"b",
")",
";",
"}",
"}"
] |
Multiplied a transpose orthogonal matrix Q by the specified rotator. This is used
to update the U and V matrices. Updating the transpose of the matrix is faster
since it only modifies the rows.
@param Q Orthogonal matrix
@param m Coordinate of rotator.
@param n Coordinate of rotator.
@param c cosine of rotator.
@param s sine of rotator.
|
[
"Multiplied",
"a",
"transpose",
"orthogonal",
"matrix",
"Q",
"by",
"the",
"specified",
"rotator",
".",
"This",
"is",
"used",
"to",
"update",
"the",
"U",
"and",
"V",
"matrices",
".",
"Updating",
"the",
"transpose",
"of",
"the",
"matrix",
"is",
"faster",
"since",
"it",
"only",
"modifies",
"the",
"rows",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L384-L404
|
162,433 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.checkForAndHandleZeros
|
protected boolean checkForAndHandleZeros() {
// check for zeros along off diagonal
for( int i = x2-1; i >= x1; i-- ) {
if( isOffZero(i) ) {
// System.out.println("steps at split = "+steps);
resetSteps();
splits[numSplits++] = i;
x1 = i+1;
return true;
}
}
// check for zeros along diagonal
for( int i = x2-1; i >= x1; i-- ) {
if( isDiagonalZero(i)) {
// System.out.println("steps at split = "+steps);
pushRight(i);
resetSteps();
splits[numSplits++] = i;
x1 = i+1;
return true;
}
}
return false;
}
|
java
|
protected boolean checkForAndHandleZeros() {
// check for zeros along off diagonal
for( int i = x2-1; i >= x1; i-- ) {
if( isOffZero(i) ) {
// System.out.println("steps at split = "+steps);
resetSteps();
splits[numSplits++] = i;
x1 = i+1;
return true;
}
}
// check for zeros along diagonal
for( int i = x2-1; i >= x1; i-- ) {
if( isDiagonalZero(i)) {
// System.out.println("steps at split = "+steps);
pushRight(i);
resetSteps();
splits[numSplits++] = i;
x1 = i+1;
return true;
}
}
return false;
}
|
[
"protected",
"boolean",
"checkForAndHandleZeros",
"(",
")",
"{",
"// check for zeros along off diagonal",
"for",
"(",
"int",
"i",
"=",
"x2",
"-",
"1",
";",
"i",
">=",
"x1",
";",
"i",
"--",
")",
"{",
"if",
"(",
"isOffZero",
"(",
"i",
")",
")",
"{",
"// System.out.println(\"steps at split = \"+steps);",
"resetSteps",
"(",
")",
";",
"splits",
"[",
"numSplits",
"++",
"]",
"=",
"i",
";",
"x1",
"=",
"i",
"+",
"1",
";",
"return",
"true",
";",
"}",
"}",
"// check for zeros along diagonal",
"for",
"(",
"int",
"i",
"=",
"x2",
"-",
"1",
";",
"i",
">=",
"x1",
";",
"i",
"--",
")",
"{",
"if",
"(",
"isDiagonalZero",
"(",
"i",
")",
")",
"{",
"// System.out.println(\"steps at split = \"+steps);",
"pushRight",
"(",
"i",
")",
";",
"resetSteps",
"(",
")",
";",
"splits",
"[",
"numSplits",
"++",
"]",
"=",
"i",
";",
"x1",
"=",
"i",
"+",
"1",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks to see if either the diagonal element or off diagonal element is zero. If one is
then it performs a split or pushes it off the matrix.
@return True if there was a zero.
|
[
"Checks",
"to",
"see",
"if",
"either",
"the",
"diagonal",
"element",
"or",
"off",
"diagonal",
"element",
"is",
"zero",
".",
"If",
"one",
"is",
"then",
"it",
"performs",
"a",
"split",
"or",
"pushes",
"it",
"off",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L643-L667
|
162,434 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.pushRight
|
private void pushRight( int row ) {
if( isOffZero(row))
return;
// B = createB();
// B.print();
rotatorPushRight(row);
int end = N-2-row;
for( int i = 0; i < end && bulge != 0; i++ ) {
rotatorPushRight2(row,i+2);
}
// }
}
|
java
|
private void pushRight( int row ) {
if( isOffZero(row))
return;
// B = createB();
// B.print();
rotatorPushRight(row);
int end = N-2-row;
for( int i = 0; i < end && bulge != 0; i++ ) {
rotatorPushRight2(row,i+2);
}
// }
}
|
[
"private",
"void",
"pushRight",
"(",
"int",
"row",
")",
"{",
"if",
"(",
"isOffZero",
"(",
"row",
")",
")",
"return",
";",
"// B = createB();",
"// B.print();",
"rotatorPushRight",
"(",
"row",
")",
";",
"int",
"end",
"=",
"N",
"-",
"2",
"-",
"row",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"end",
"&&",
"bulge",
"!=",
"0",
";",
"i",
"++",
")",
"{",
"rotatorPushRight2",
"(",
"row",
",",
"i",
"+",
"2",
")",
";",
"}",
"// }",
"}"
] |
If there is a zero on the diagonal element, the off diagonal element needs pushed
off so that all the algorithms assumptions are two and so that it can split the matrix.
|
[
"If",
"there",
"is",
"a",
"zero",
"on",
"the",
"diagonal",
"element",
"the",
"off",
"diagonal",
"element",
"needs",
"pushed",
"off",
"so",
"that",
"all",
"the",
"algorithms",
"assumptions",
"are",
"two",
"and",
"so",
"that",
"it",
"can",
"split",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L673-L685
|
162,435 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.rotatorPushRight
|
private void rotatorPushRight( int m )
{
double b11 = off[m];
double b21 = diag[m+1];
computeRotator(b21,-b11);
// apply rotator on the right
off[m] = 0;
diag[m+1] = b21*c-b11*s;
if( m+2 < N) {
double b22 = off[m+1];
off[m+1] = b22*c;
bulge = b22*s;
} else {
bulge = 0;
}
// SimpleMatrix Q = createQ(m,m+1, c, s, true);
// B=Q.mult(B);
//
// B.print();
// printMatrix();
// System.out.println(" bulge = "+bulge);
// System.out.println();
if( Ut != null ) {
updateRotator(Ut,m,m+1,c,s);
// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();
// printMatrix();
// System.out.println("bulge = "+bulge);
// System.out.println();
}
}
|
java
|
private void rotatorPushRight( int m )
{
double b11 = off[m];
double b21 = diag[m+1];
computeRotator(b21,-b11);
// apply rotator on the right
off[m] = 0;
diag[m+1] = b21*c-b11*s;
if( m+2 < N) {
double b22 = off[m+1];
off[m+1] = b22*c;
bulge = b22*s;
} else {
bulge = 0;
}
// SimpleMatrix Q = createQ(m,m+1, c, s, true);
// B=Q.mult(B);
//
// B.print();
// printMatrix();
// System.out.println(" bulge = "+bulge);
// System.out.println();
if( Ut != null ) {
updateRotator(Ut,m,m+1,c,s);
// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();
// printMatrix();
// System.out.println("bulge = "+bulge);
// System.out.println();
}
}
|
[
"private",
"void",
"rotatorPushRight",
"(",
"int",
"m",
")",
"{",
"double",
"b11",
"=",
"off",
"[",
"m",
"]",
";",
"double",
"b21",
"=",
"diag",
"[",
"m",
"+",
"1",
"]",
";",
"computeRotator",
"(",
"b21",
",",
"-",
"b11",
")",
";",
"// apply rotator on the right",
"off",
"[",
"m",
"]",
"=",
"0",
";",
"diag",
"[",
"m",
"+",
"1",
"]",
"=",
"b21",
"*",
"c",
"-",
"b11",
"*",
"s",
";",
"if",
"(",
"m",
"+",
"2",
"<",
"N",
")",
"{",
"double",
"b22",
"=",
"off",
"[",
"m",
"+",
"1",
"]",
";",
"off",
"[",
"m",
"+",
"1",
"]",
"=",
"b22",
"*",
"c",
";",
"bulge",
"=",
"b22",
"*",
"s",
";",
"}",
"else",
"{",
"bulge",
"=",
"0",
";",
"}",
"// SimpleMatrix Q = createQ(m,m+1, c, s, true);",
"// B=Q.mult(B);",
"//",
"// B.print();",
"// printMatrix();",
"// System.out.println(\" bulge = \"+bulge);",
"// System.out.println();",
"if",
"(",
"Ut",
"!=",
"null",
")",
"{",
"updateRotator",
"(",
"Ut",
",",
"m",
",",
"m",
"+",
"1",
",",
"c",
",",
"s",
")",
";",
"// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();",
"// printMatrix();",
"// System.out.println(\"bulge = \"+bulge);",
"// System.out.println();",
"}",
"}"
] |
Start pushing the element off to the right.
|
[
"Start",
"pushing",
"the",
"element",
"off",
"to",
"the",
"right",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L690-L725
|
162,436 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.rotatorPushRight2
|
private void rotatorPushRight2( int m , int offset)
{
double b11 = bulge;
double b12 = diag[m+offset];
computeRotator(b12,-b11);
diag[m+offset] = b12*c-b11*s;
if( m+offset<N-1) {
double b22 = off[m+offset];
off[m+offset] = b22*c;
bulge = b22*s;
}
// SimpleMatrix Q = createQ(m,m+offset, c, s, true);
// B=Q.mult(B);
//
// B.print();
// printMatrix();
// System.out.println(" bulge = "+bulge);
// System.out.println();
if( Ut != null ) {
updateRotator(Ut,m,m+offset,c,s);
// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();
// printMatrix();
// System.out.println("bulge = "+bulge);
// System.out.println();
}
}
|
java
|
private void rotatorPushRight2( int m , int offset)
{
double b11 = bulge;
double b12 = diag[m+offset];
computeRotator(b12,-b11);
diag[m+offset] = b12*c-b11*s;
if( m+offset<N-1) {
double b22 = off[m+offset];
off[m+offset] = b22*c;
bulge = b22*s;
}
// SimpleMatrix Q = createQ(m,m+offset, c, s, true);
// B=Q.mult(B);
//
// B.print();
// printMatrix();
// System.out.println(" bulge = "+bulge);
// System.out.println();
if( Ut != null ) {
updateRotator(Ut,m,m+offset,c,s);
// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();
// printMatrix();
// System.out.println("bulge = "+bulge);
// System.out.println();
}
}
|
[
"private",
"void",
"rotatorPushRight2",
"(",
"int",
"m",
",",
"int",
"offset",
")",
"{",
"double",
"b11",
"=",
"bulge",
";",
"double",
"b12",
"=",
"diag",
"[",
"m",
"+",
"offset",
"]",
";",
"computeRotator",
"(",
"b12",
",",
"-",
"b11",
")",
";",
"diag",
"[",
"m",
"+",
"offset",
"]",
"=",
"b12",
"*",
"c",
"-",
"b11",
"*",
"s",
";",
"if",
"(",
"m",
"+",
"offset",
"<",
"N",
"-",
"1",
")",
"{",
"double",
"b22",
"=",
"off",
"[",
"m",
"+",
"offset",
"]",
";",
"off",
"[",
"m",
"+",
"offset",
"]",
"=",
"b22",
"*",
"c",
";",
"bulge",
"=",
"b22",
"*",
"s",
";",
"}",
"// SimpleMatrix Q = createQ(m,m+offset, c, s, true);",
"// B=Q.mult(B);",
"//",
"// B.print();",
"// printMatrix();",
"// System.out.println(\" bulge = \"+bulge);",
"// System.out.println();",
"if",
"(",
"Ut",
"!=",
"null",
")",
"{",
"updateRotator",
"(",
"Ut",
",",
"m",
",",
"m",
"+",
"offset",
",",
"c",
",",
"s",
")",
";",
"// SimpleMatrix.wrap(Ut).mult(B).mult(SimpleMatrix.wrap(Vt).transpose()).print();",
"// printMatrix();",
"// System.out.println(\"bulge = \"+bulge);",
"// System.out.println();",
"}",
"}"
] |
Used to finish up pushing the bulge off the matrix.
|
[
"Used",
"to",
"finish",
"up",
"pushing",
"the",
"bulge",
"off",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L730-L761
|
162,437 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java
|
SvdImplicitQrAlgorithm_DDRM.exceptionShift
|
public void exceptionShift() {
numExceptional++;
double mag = 0.05 * numExceptional;
if (mag > 1.0) mag = 1.0;
double angle = 2.0 * UtilEjml.PI * (rand.nextDouble() - 0.5) * mag;
performImplicitSingleStep(0, angle, true);
// allow more convergence time
nextExceptional = steps + exceptionalThresh; // (numExceptional+1)*
}
|
java
|
public void exceptionShift() {
numExceptional++;
double mag = 0.05 * numExceptional;
if (mag > 1.0) mag = 1.0;
double angle = 2.0 * UtilEjml.PI * (rand.nextDouble() - 0.5) * mag;
performImplicitSingleStep(0, angle, true);
// allow more convergence time
nextExceptional = steps + exceptionalThresh; // (numExceptional+1)*
}
|
[
"public",
"void",
"exceptionShift",
"(",
")",
"{",
"numExceptional",
"++",
";",
"double",
"mag",
"=",
"0.05",
"*",
"numExceptional",
";",
"if",
"(",
"mag",
">",
"1.0",
")",
"mag",
"=",
"1.0",
";",
"double",
"angle",
"=",
"2.0",
"*",
"UtilEjml",
".",
"PI",
"*",
"(",
"rand",
".",
"nextDouble",
"(",
")",
"-",
"0.5",
")",
"*",
"mag",
";",
"performImplicitSingleStep",
"(",
"0",
",",
"angle",
",",
"true",
")",
";",
"// allow more convergence time",
"nextExceptional",
"=",
"steps",
"+",
"exceptionalThresh",
";",
"// (numExceptional+1)*",
"}"
] |
It is possible for the QR algorithm to get stuck in a loop because of symmetries. This happens
more often with larger matrices. By taking a random step it can break the symmetry and finish.
|
[
"It",
"is",
"possible",
"for",
"the",
"QR",
"algorithm",
"to",
"get",
"stuck",
"in",
"a",
"loop",
"because",
"of",
"symmetries",
".",
"This",
"happens",
"more",
"often",
"with",
"larger",
"matrices",
".",
"By",
"taking",
"a",
"random",
"step",
"it",
"can",
"break",
"the",
"symmetry",
"and",
"finish",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/implicitqr/SvdImplicitQrAlgorithm_DDRM.java#L767-L777
|
162,438 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/SvdImplicitQrDecompose_DDRM.java
|
SvdImplicitQrDecompose_DDRM.computeUWV
|
private boolean computeUWV() {
bidiag.getDiagonal(diag,off);
qralg.setMatrix(numRowsT,numColsT,diag,off);
// long pointA = System.currentTimeMillis();
// compute U and V matrices
if( computeU )
Ut = bidiag.getU(Ut,true,compact);
if( computeV )
Vt = bidiag.getV(Vt,true,compact);
qralg.setFastValues(false);
if( computeU )
qralg.setUt(Ut);
else
qralg.setUt(null);
if( computeV )
qralg.setVt(Vt);
else
qralg.setVt(null);
// long pointB = System.currentTimeMillis();
boolean ret = !qralg.process();
// long pointC = System.currentTimeMillis();
// System.out.println(" compute UV "+(pointB-pointA)+" QR = "+(pointC-pointB));
return ret;
}
|
java
|
private boolean computeUWV() {
bidiag.getDiagonal(diag,off);
qralg.setMatrix(numRowsT,numColsT,diag,off);
// long pointA = System.currentTimeMillis();
// compute U and V matrices
if( computeU )
Ut = bidiag.getU(Ut,true,compact);
if( computeV )
Vt = bidiag.getV(Vt,true,compact);
qralg.setFastValues(false);
if( computeU )
qralg.setUt(Ut);
else
qralg.setUt(null);
if( computeV )
qralg.setVt(Vt);
else
qralg.setVt(null);
// long pointB = System.currentTimeMillis();
boolean ret = !qralg.process();
// long pointC = System.currentTimeMillis();
// System.out.println(" compute UV "+(pointB-pointA)+" QR = "+(pointC-pointB));
return ret;
}
|
[
"private",
"boolean",
"computeUWV",
"(",
")",
"{",
"bidiag",
".",
"getDiagonal",
"(",
"diag",
",",
"off",
")",
";",
"qralg",
".",
"setMatrix",
"(",
"numRowsT",
",",
"numColsT",
",",
"diag",
",",
"off",
")",
";",
"// long pointA = System.currentTimeMillis();",
"// compute U and V matrices",
"if",
"(",
"computeU",
")",
"Ut",
"=",
"bidiag",
".",
"getU",
"(",
"Ut",
",",
"true",
",",
"compact",
")",
";",
"if",
"(",
"computeV",
")",
"Vt",
"=",
"bidiag",
".",
"getV",
"(",
"Vt",
",",
"true",
",",
"compact",
")",
";",
"qralg",
".",
"setFastValues",
"(",
"false",
")",
";",
"if",
"(",
"computeU",
")",
"qralg",
".",
"setUt",
"(",
"Ut",
")",
";",
"else",
"qralg",
".",
"setUt",
"(",
"null",
")",
";",
"if",
"(",
"computeV",
")",
"qralg",
".",
"setVt",
"(",
"Vt",
")",
";",
"else",
"qralg",
".",
"setVt",
"(",
"null",
")",
";",
"// long pointB = System.currentTimeMillis();",
"boolean",
"ret",
"=",
"!",
"qralg",
".",
"process",
"(",
")",
";",
"// long pointC = System.currentTimeMillis();",
"// System.out.println(\" compute UV \"+(pointB-pointA)+\" QR = \"+(pointC-pointB));",
"return",
"ret",
";",
"}"
] |
Compute singular values and U and V at the same time
|
[
"Compute",
"singular",
"values",
"and",
"U",
"and",
"V",
"at",
"the",
"same",
"time"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/SvdImplicitQrDecompose_DDRM.java#L232-L261
|
162,439 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/SvdImplicitQrDecompose_DDRM.java
|
SvdImplicitQrDecompose_DDRM.makeSingularPositive
|
private void makeSingularPositive() {
numSingular = qralg.getNumberOfSingularValues();
singularValues = qralg.getSingularValues();
for( int i = 0; i < numSingular; i++ ) {
double val = qralg.getSingularValue(i);
if( val < 0 ) {
singularValues[i] = 0.0 - val;
if( computeU ) {
// compute the results of multiplying it by an element of -1 at this location in
// a diagonal matrix.
int start = i* Ut.numCols;
int stop = start+ Ut.numCols;
for( int j = start; j < stop; j++ ) {
Ut.set(j, 0.0 - Ut.get(j));
}
}
} else {
singularValues[i] = val;
}
}
}
|
java
|
private void makeSingularPositive() {
numSingular = qralg.getNumberOfSingularValues();
singularValues = qralg.getSingularValues();
for( int i = 0; i < numSingular; i++ ) {
double val = qralg.getSingularValue(i);
if( val < 0 ) {
singularValues[i] = 0.0 - val;
if( computeU ) {
// compute the results of multiplying it by an element of -1 at this location in
// a diagonal matrix.
int start = i* Ut.numCols;
int stop = start+ Ut.numCols;
for( int j = start; j < stop; j++ ) {
Ut.set(j, 0.0 - Ut.get(j));
}
}
} else {
singularValues[i] = val;
}
}
}
|
[
"private",
"void",
"makeSingularPositive",
"(",
")",
"{",
"numSingular",
"=",
"qralg",
".",
"getNumberOfSingularValues",
"(",
")",
";",
"singularValues",
"=",
"qralg",
".",
"getSingularValues",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numSingular",
";",
"i",
"++",
")",
"{",
"double",
"val",
"=",
"qralg",
".",
"getSingularValue",
"(",
"i",
")",
";",
"if",
"(",
"val",
"<",
"0",
")",
"{",
"singularValues",
"[",
"i",
"]",
"=",
"0.0",
"-",
"val",
";",
"if",
"(",
"computeU",
")",
"{",
"// compute the results of multiplying it by an element of -1 at this location in",
"// a diagonal matrix.",
"int",
"start",
"=",
"i",
"*",
"Ut",
".",
"numCols",
";",
"int",
"stop",
"=",
"start",
"+",
"Ut",
".",
"numCols",
";",
"for",
"(",
"int",
"j",
"=",
"start",
";",
"j",
"<",
"stop",
";",
"j",
"++",
")",
"{",
"Ut",
".",
"set",
"(",
"j",
",",
"0.0",
"-",
"Ut",
".",
"get",
"(",
"j",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"singularValues",
"[",
"i",
"]",
"=",
"val",
";",
"}",
"}",
"}"
] |
With the QR algorithm it is possible for the found singular values to be negative. This
makes them all positive by multiplying it by a diagonal matrix that has
|
[
"With",
"the",
"QR",
"algorithm",
"it",
"is",
"possible",
"for",
"the",
"found",
"singular",
"values",
"to",
"be",
"negative",
".",
"This",
"makes",
"them",
"all",
"positive",
"by",
"multiplying",
"it",
"by",
"a",
"diagonal",
"matrix",
"that",
"has"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/svd/SvdImplicitQrDecompose_DDRM.java#L306-L330
|
162,440 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.checkDuplicateElements
|
public static boolean checkDuplicateElements(DMatrixSparseCSC A ) {
A = A.copy(); // create a copy so that it doesn't modify A
A.sortIndices(null);
return !checkSortedFlag(A);
}
|
java
|
public static boolean checkDuplicateElements(DMatrixSparseCSC A ) {
A = A.copy(); // create a copy so that it doesn't modify A
A.sortIndices(null);
return !checkSortedFlag(A);
}
|
[
"public",
"static",
"boolean",
"checkDuplicateElements",
"(",
"DMatrixSparseCSC",
"A",
")",
"{",
"A",
"=",
"A",
".",
"copy",
"(",
")",
";",
"// create a copy so that it doesn't modify A",
"A",
".",
"sortIndices",
"(",
"null",
")",
";",
"return",
"!",
"checkSortedFlag",
"(",
"A",
")",
";",
"}"
] |
Checks for duplicate elements. A is sorted
@param A Matrix to be tested.
@return true if duplicates or false if false duplicates
|
[
"Checks",
"for",
"duplicate",
"elements",
".",
"A",
"is",
"sorted"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L105-L109
|
162,441 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.changeSign
|
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];
}
}
|
java
|
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];
}
}
|
[
"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.
@param A (Input) Matrix. Not modified.
@param B (Output) Matrix. Modified.
|
[
"B",
"=",
"-",
"A",
".",
"Changes",
"the",
"sign",
"of",
"elements",
"in",
"A",
"and",
"stores",
"it",
"in",
"B",
".",
"A",
"and",
"B",
"can",
"be",
"the",
"same",
"instance",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L442-L450
|
162,442 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.elementMin
|
public static double elementMin( DMatrixSparseCSC A ) {
if( A.nz_length == 0)
return 0;
// if every element is assigned a value then the first element can be a minimum.
// Otherwise zero needs to be considered
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;
}
|
java
|
public static double elementMin( DMatrixSparseCSC A ) {
if( A.nz_length == 0)
return 0;
// if every element is assigned a value then the first element can be a minimum.
// Otherwise zero needs to be considered
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;
}
|
[
"public",
"static",
"double",
"elementMin",
"(",
"DMatrixSparseCSC",
"A",
")",
"{",
"if",
"(",
"A",
".",
"nz_length",
"==",
"0",
")",
"return",
"0",
";",
"// if every element is assigned a value then the first element can be a minimum.",
"// Otherwise zero needs to be considered",
"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
@param A (Input) Matrix. Not modified.
@return scalar
|
[
"Returns",
"the",
"value",
"of",
"the",
"element",
"with",
"the",
"minimum",
"value"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L497-L512
|
162,443 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.elementMax
|
public static double elementMax( DMatrixSparseCSC A ) {
if( A.nz_length == 0)
return 0;
// if every element is assigned a value then the first element can be a max.
// Otherwise zero needs to be considered
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;
}
|
java
|
public static double elementMax( DMatrixSparseCSC A ) {
if( A.nz_length == 0)
return 0;
// if every element is assigned a value then the first element can be a max.
// Otherwise zero needs to be considered
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;
}
|
[
"public",
"static",
"double",
"elementMax",
"(",
"DMatrixSparseCSC",
"A",
")",
"{",
"if",
"(",
"A",
".",
"nz_length",
"==",
"0",
")",
"return",
"0",
";",
"// if every element is assigned a value then the first element can be a max.",
"// Otherwise zero needs to be considered",
"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
@param A (Input) Matrix. Not modified.
@return scalar
|
[
"Returns",
"the",
"value",
"of",
"the",
"element",
"with",
"the",
"largest",
"value"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L519-L534
|
162,444 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.elementSum
|
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;
}
|
java
|
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;
}
|
[
"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
@param A (Input) Matrix. Not modified.
@return scalar
|
[
"Sum",
"of",
"all",
"elements"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L542-L552
|
162,445 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.columnMaxAbs
|
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+1];
double maxabs = 0;
for (int j = idx0; j < idx1; j++) {
double v = Math.abs(A.nz_values[j]);
if( v > maxabs )
maxabs = v;
}
values[i] = maxabs;
}
}
|
java
|
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+1];
double maxabs = 0;
for (int j = idx0; j < idx1; j++) {
double v = Math.abs(A.nz_values[j]);
if( v > maxabs )
maxabs = v;
}
values[i] = maxabs;
}
}
|
[
"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",
"+",
"1",
"]",
";",
"double",
"maxabs",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"idx0",
";",
"j",
"<",
"idx1",
";",
"j",
"++",
")",
"{",
"double",
"v",
"=",
"Math",
".",
"abs",
"(",
"A",
".",
"nz_values",
"[",
"j",
"]",
")",
";",
"if",
"(",
"v",
">",
"maxabs",
")",
"maxabs",
"=",
"v",
";",
"}",
"values",
"[",
"i",
"]",
"=",
"maxabs",
";",
"}",
"}"
] |
Finds the maximum abs in each column of A and stores it into values
@param A (Input) Matrix
@param values (Output) storage for column max abs
|
[
"Finds",
"the",
"maximum",
"abs",
"in",
"each",
"column",
"of",
"A",
"and",
"stores",
"it",
"into",
"values"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L579-L595
|
162,446 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.diag
|
public static DMatrixSparseCSC diag(double... values ) {
int N = values.length;
return diag(new DMatrixSparseCSC(N,N,N),values,0,N);
}
|
java
|
public static DMatrixSparseCSC diag(double... values ) {
int N = values.length;
return diag(new DMatrixSparseCSC(N,N,N),values,0,N);
}
|
[
"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.
@param values values of diagonal elements
@return A diagonal matrix
|
[
"Returns",
"a",
"diagonal",
"matrix",
"with",
"the",
"specified",
"diagonal",
"elements",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L708-L711
|
162,447 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.permutationVector
|
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");
} else if( vector.length < P.numCols ) {
throw new IllegalArgumentException("vector is too short");
}
int M = P.numCols;
for (int i = 0; i < M; i++) {
if( P.col_idx[i+1] != i+1 )
throw new IllegalArgumentException("Unexpected number of elements in a column");
vector[P.nz_rows[i]] = i;
}
}
|
java
|
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");
} else if( vector.length < P.numCols ) {
throw new IllegalArgumentException("vector is too short");
}
int M = P.numCols;
for (int i = 0; i < M; i++) {
if( P.col_idx[i+1] != i+1 )
throw new IllegalArgumentException("Unexpected number of elements in a column");
vector[P.nz_rows[i]] = i;
}
}
|
[
"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\"",
")",
";",
"}",
"else",
"if",
"(",
"vector",
".",
"length",
"<",
"P",
".",
"numCols",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"vector is too short\"",
")",
";",
"}",
"int",
"M",
"=",
"P",
".",
"numCols",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"M",
";",
"i",
"++",
")",
"{",
"if",
"(",
"P",
".",
"col_idx",
"[",
"i",
"+",
"1",
"]",
"!=",
"i",
"+",
"1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected number of elements in a column\"",
")",
";",
"vector",
"[",
"P",
".",
"nz_rows",
"[",
"i",
"]",
"]",
"=",
"i",
";",
"}",
"}"
] |
Converts the permutation matrix into a vector
@param P (Input) Permutation matrix
@param vector (Output) Permutation vector
|
[
"Converts",
"the",
"permutation",
"matrix",
"into",
"a",
"vector"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L842-L859
|
162,448 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.permutationInverse
|
public static void permutationInverse( int []original , int []inverse , int length ) {
for (int i = 0; i < length; i++) {
inverse[original[i]] = i;
}
}
|
java
|
public static void permutationInverse( int []original , int []inverse , int length ) {
for (int i = 0; i < length; i++) {
inverse[original[i]] = i;
}
}
|
[
"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
@param original Original permutation vector
@param inverse It's inverse
|
[
"Computes",
"the",
"inverse",
"permutation",
"vector"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L867-L871
|
162,449 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.zero
|
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 sorted a faster technique could be used
if( row >= row0 && row < row1 ) {
numRemoved++;
} else if( numRemoved > 0 ){
A.nz_rows[i-numRemoved]=row;
A.nz_values[i-numRemoved]=A.nz_values[i];
}
}
if( numRemoved > 0 ) {
// this could be done more intelligently. Each time a column is adjusted all the columns are adjusted
// after it. Maybe accumulate the changes in each column and do it in one pass? Need an array to store
// those results though
for (int i = idx1; i < A.nz_length; i++) {
A.nz_rows[i - numRemoved] = A.nz_rows[i];
A.nz_values[i - numRemoved] = A.nz_values[i];
}
A.nz_length -= numRemoved;
for (int i = col+1; i <= A.numCols; i++) {
A.col_idx[i] -= numRemoved;
}
}
}
}
|
java
|
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 sorted a faster technique could be used
if( row >= row0 && row < row1 ) {
numRemoved++;
} else if( numRemoved > 0 ){
A.nz_rows[i-numRemoved]=row;
A.nz_values[i-numRemoved]=A.nz_values[i];
}
}
if( numRemoved > 0 ) {
// this could be done more intelligently. Each time a column is adjusted all the columns are adjusted
// after it. Maybe accumulate the changes in each column and do it in one pass? Need an array to store
// those results though
for (int i = idx1; i < A.nz_length; i++) {
A.nz_rows[i - numRemoved] = A.nz_rows[i];
A.nz_values[i - numRemoved] = A.nz_values[i];
}
A.nz_length -= numRemoved;
for (int i = col+1; i <= A.numCols; i++) {
A.col_idx[i] -= numRemoved;
}
}
}
}
|
[
"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 sorted a faster technique could be used",
"if",
"(",
"row",
">=",
"row0",
"&&",
"row",
"<",
"row1",
")",
"{",
"numRemoved",
"++",
";",
"}",
"else",
"if",
"(",
"numRemoved",
">",
"0",
")",
"{",
"A",
".",
"nz_rows",
"[",
"i",
"-",
"numRemoved",
"]",
"=",
"row",
";",
"A",
".",
"nz_values",
"[",
"i",
"-",
"numRemoved",
"]",
"=",
"A",
".",
"nz_values",
"[",
"i",
"]",
";",
"}",
"}",
"if",
"(",
"numRemoved",
">",
"0",
")",
"{",
"// this could be done more intelligently. Each time a column is adjusted all the columns are adjusted",
"// after it. Maybe accumulate the changes in each column and do it in one pass? Need an array to store",
"// those results though",
"for",
"(",
"int",
"i",
"=",
"idx1",
";",
"i",
"<",
"A",
".",
"nz_length",
";",
"i",
"++",
")",
"{",
"A",
".",
"nz_rows",
"[",
"i",
"-",
"numRemoved",
"]",
"=",
"A",
".",
"nz_rows",
"[",
"i",
"]",
";",
"A",
".",
"nz_values",
"[",
"i",
"-",
"numRemoved",
"]",
"=",
"A",
".",
"nz_values",
"[",
"i",
"]",
";",
"}",
"A",
".",
"nz_length",
"-=",
"numRemoved",
";",
"for",
"(",
"int",
"i",
"=",
"col",
"+",
"1",
";",
"i",
"<=",
"A",
".",
"numCols",
";",
"i",
"++",
")",
"{",
"A",
".",
"col_idx",
"[",
"i",
"]",
"-=",
"numRemoved",
";",
"}",
"}",
"}",
"}"
] |
Zeros an inner rectangle inside the matrix.
@param A Matrix that is to be modified.
@param row0 Start row.
@param row1 Stop row+1.
@param col0 Start column.
@param col1 Stop column+1.
|
[
"Zeros",
"an",
"inner",
"rectangle",
"inside",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L1529-L1562
|
162,450 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java
|
CommonOps_DSCC.removeZeros
|
public static void removeZeros( DMatrixSparseCSC input , DMatrixSparseCSC output , double tol ) {
ImplCommonOps_DSCC.removeZeros(input,output,tol);
}
|
java
|
public static void removeZeros( DMatrixSparseCSC input , DMatrixSparseCSC output , double tol ) {
ImplCommonOps_DSCC.removeZeros(input,output,tol);
}
|
[
"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 > tol.
@param input (Input) input matrix. Not modified.
@param output (Output) Output matrix. Modified and shaped to match input.
@param tol Tolerance for defining zero
|
[
"Copies",
"all",
"elements",
"from",
"input",
"into",
"output",
"which",
"are",
">",
";",
"tol",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/CommonOps_DSCC.java#L1761-L1763
|
162,451 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
|
DMatrixSparseCSC.growMaxLength
|
public void growMaxLength( int arrayLength , boolean preserveValue ) {
if( arrayLength < 0 )
throw new IllegalArgumentException("Negative array length. Overflow?");
// see if multiplying numRows*numCols will cause an overflow. If it won't then pick the smaller of the two
if( numRows != 0 && numCols <= Integer.MAX_VALUE / numRows ) {
// save the user from themselves
arrayLength = Math.min(numRows*numCols, arrayLength);
}
if( nz_values == null || arrayLength > this.nz_values.length ) {
double[] data = new double[ arrayLength ];
int[] row_idx = new int[ arrayLength ];
if( preserveValue ) {
if( nz_values == null )
throw new IllegalArgumentException("Can't preserve values when uninitialized");
System.arraycopy(this.nz_values, 0, data, 0, this.nz_length);
System.arraycopy(this.nz_rows, 0, row_idx, 0, this.nz_length);
}
this.nz_values = data;
this.nz_rows = row_idx;
}
}
|
java
|
public void growMaxLength( int arrayLength , boolean preserveValue ) {
if( arrayLength < 0 )
throw new IllegalArgumentException("Negative array length. Overflow?");
// see if multiplying numRows*numCols will cause an overflow. If it won't then pick the smaller of the two
if( numRows != 0 && numCols <= Integer.MAX_VALUE / numRows ) {
// save the user from themselves
arrayLength = Math.min(numRows*numCols, arrayLength);
}
if( nz_values == null || arrayLength > this.nz_values.length ) {
double[] data = new double[ arrayLength ];
int[] row_idx = new int[ arrayLength ];
if( preserveValue ) {
if( nz_values == null )
throw new IllegalArgumentException("Can't preserve values when uninitialized");
System.arraycopy(this.nz_values, 0, data, 0, this.nz_length);
System.arraycopy(this.nz_rows, 0, row_idx, 0, this.nz_length);
}
this.nz_values = data;
this.nz_rows = row_idx;
}
}
|
[
"public",
"void",
"growMaxLength",
"(",
"int",
"arrayLength",
",",
"boolean",
"preserveValue",
")",
"{",
"if",
"(",
"arrayLength",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Negative array length. Overflow?\"",
")",
";",
"// see if multiplying numRows*numCols will cause an overflow. If it won't then pick the smaller of the two",
"if",
"(",
"numRows",
"!=",
"0",
"&&",
"numCols",
"<=",
"Integer",
".",
"MAX_VALUE",
"/",
"numRows",
")",
"{",
"// save the user from themselves",
"arrayLength",
"=",
"Math",
".",
"min",
"(",
"numRows",
"*",
"numCols",
",",
"arrayLength",
")",
";",
"}",
"if",
"(",
"nz_values",
"==",
"null",
"||",
"arrayLength",
">",
"this",
".",
"nz_values",
".",
"length",
")",
"{",
"double",
"[",
"]",
"data",
"=",
"new",
"double",
"[",
"arrayLength",
"]",
";",
"int",
"[",
"]",
"row_idx",
"=",
"new",
"int",
"[",
"arrayLength",
"]",
";",
"if",
"(",
"preserveValue",
")",
"{",
"if",
"(",
"nz_values",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Can't preserve values when uninitialized\"",
")",
";",
"System",
".",
"arraycopy",
"(",
"this",
".",
"nz_values",
",",
"0",
",",
"data",
",",
"0",
",",
"this",
".",
"nz_length",
")",
";",
"System",
".",
"arraycopy",
"(",
"this",
".",
"nz_rows",
",",
"0",
",",
"row_idx",
",",
"0",
",",
"this",
".",
"nz_length",
")",
";",
"}",
"this",
".",
"nz_values",
"=",
"data",
";",
"this",
".",
"nz_rows",
"=",
"row_idx",
";",
"}",
"}"
] |
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.
@param arrayLength Desired maximum length of sparse data
@param preserveValue If true the old values will be copied into the new arrays. If false that step will be skipped.
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java#L332-L354
|
162,452 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
|
DMatrixSparseCSC.growMaxColumns
|
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;
}
}
|
java
|
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;
}
}
|
[
"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.
@param desiredColumns Desired number of columns.
@param preserveValue If the array needs to be expanded should it copy the previous values?
|
[
"Increases",
"the",
"maximum",
"number",
"of",
"columns",
"in",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java#L361-L368
|
162,453 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
|
DMatrixSparseCSC.histogramToStructure
|
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");
}
|
java
|
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");
}
|
[
"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.
@param histogram histogram of column values in the sparse matrix. modified, see above.
|
[
"Given",
"the",
"histogram",
"of",
"columns",
"compute",
"the",
"col_idx",
"for",
"the",
"matrix",
".",
"nz_length",
"is",
"automatically",
"set",
"and",
"nz_values",
"will",
"grow",
"if",
"needed",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java#L375-L385
|
162,454 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
|
DMatrixSparseCSC.sortIndices
|
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;
}
|
java
|
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;
}
|
[
"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.
@param sorter (Optional) Used to sort rows. If null a new instance will be declared internally.
|
[
"Sorts",
"the",
"row",
"indices",
"in",
"ascending",
"order",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java#L391-L397
|
162,455 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
|
DMatrixSparseCSC.copyStructure
|
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);
}
|
java
|
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);
}
|
[
"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"
@param orig Matrix who's structure is to be copied
|
[
"Copies",
"the",
"non",
"-",
"zero",
"structure",
"of",
"orig",
"into",
"this"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java#L403-L408
|
162,456 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/block/decomposition/bidiagonal/BidiagonalHelper_DDRB.java
|
BidiagonalHelper_DDRB.bidiagOuterBlocks
|
public static boolean bidiagOuterBlocks( final int blockLength ,
final DSubmatrixD1 A ,
final double gammasU[],
final double gammasV[])
{
// System.out.println("---------- Orig");
// A.original.print();
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( int i = 0; i < min; i++ ) {
//--- Apply reflector to the column
// compute the householder vector
if (!computeHouseHolderCol(blockLength, A, gammasU, i))
return false;
// apply to rest of the columns in the column block
rank1UpdateMultR_Col(blockLength,A,i,gammasU[A.col0+i]);
// apply to the top row block
rank1UpdateMultR_TopRow(blockLength,A,i,gammasU[A.col0+i]);
System.out.println("After column stuff");
A.original.print();
//-- Apply reflector to the row
if(!computeHouseHolderRow(blockLength,A,gammasV,i))
return false;
// apply to rest of the rows in the row block
rank1UpdateMultL_Row(blockLength,A,i,i+1,gammasV[A.row0+i]);
System.out.println("After update row");
A.original.print();
// apply to the left column block
// TODO THIS WON'T WORK!!!!!!!!!!!!!
// Needs the whole matrix to have been updated by the left reflector to compute the correct solution
// rank1UpdateMultL_LeftCol(blockLength,A,i,i+1,gammasV[A.row0+i]);
System.out.println("After row stuff");
A.original.print();
}
return true;
}
|
java
|
public static boolean bidiagOuterBlocks( final int blockLength ,
final DSubmatrixD1 A ,
final double gammasU[],
final double gammasV[])
{
// System.out.println("---------- Orig");
// A.original.print();
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( int i = 0; i < min; i++ ) {
//--- Apply reflector to the column
// compute the householder vector
if (!computeHouseHolderCol(blockLength, A, gammasU, i))
return false;
// apply to rest of the columns in the column block
rank1UpdateMultR_Col(blockLength,A,i,gammasU[A.col0+i]);
// apply to the top row block
rank1UpdateMultR_TopRow(blockLength,A,i,gammasU[A.col0+i]);
System.out.println("After column stuff");
A.original.print();
//-- Apply reflector to the row
if(!computeHouseHolderRow(blockLength,A,gammasV,i))
return false;
// apply to rest of the rows in the row block
rank1UpdateMultL_Row(blockLength,A,i,i+1,gammasV[A.row0+i]);
System.out.println("After update row");
A.original.print();
// apply to the left column block
// TODO THIS WON'T WORK!!!!!!!!!!!!!
// Needs the whole matrix to have been updated by the left reflector to compute the correct solution
// rank1UpdateMultL_LeftCol(blockLength,A,i,i+1,gammasV[A.row0+i]);
System.out.println("After row stuff");
A.original.print();
}
return true;
}
|
[
"public",
"static",
"boolean",
"bidiagOuterBlocks",
"(",
"final",
"int",
"blockLength",
",",
"final",
"DSubmatrixD1",
"A",
",",
"final",
"double",
"gammasU",
"[",
"]",
",",
"final",
"double",
"gammasV",
"[",
"]",
")",
"{",
"// System.out.println(\"---------- Orig\");",
"// A.original.print();",
"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",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"min",
";",
"i",
"++",
")",
"{",
"//--- Apply reflector to the column",
"// compute the householder vector",
"if",
"(",
"!",
"computeHouseHolderCol",
"(",
"blockLength",
",",
"A",
",",
"gammasU",
",",
"i",
")",
")",
"return",
"false",
";",
"// apply to rest of the columns in the column block",
"rank1UpdateMultR_Col",
"(",
"blockLength",
",",
"A",
",",
"i",
",",
"gammasU",
"[",
"A",
".",
"col0",
"+",
"i",
"]",
")",
";",
"// apply to the top row block",
"rank1UpdateMultR_TopRow",
"(",
"blockLength",
",",
"A",
",",
"i",
",",
"gammasU",
"[",
"A",
".",
"col0",
"+",
"i",
"]",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"After column stuff\"",
")",
";",
"A",
".",
"original",
".",
"print",
"(",
")",
";",
"//-- Apply reflector to the row",
"if",
"(",
"!",
"computeHouseHolderRow",
"(",
"blockLength",
",",
"A",
",",
"gammasV",
",",
"i",
")",
")",
"return",
"false",
";",
"// apply to rest of the rows in the row block",
"rank1UpdateMultL_Row",
"(",
"blockLength",
",",
"A",
",",
"i",
",",
"i",
"+",
"1",
",",
"gammasV",
"[",
"A",
".",
"row0",
"+",
"i",
"]",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"After update row\"",
")",
";",
"A",
".",
"original",
".",
"print",
"(",
")",
";",
"// apply to the left column block",
"// TODO THIS WON'T WORK!!!!!!!!!!!!!",
"// Needs the whole matrix to have been updated by the left reflector to compute the correct solution",
"// rank1UpdateMultL_LeftCol(blockLength,A,i,i+1,gammasV[A.row0+i]);",
"System",
".",
"out",
".",
"println",
"(",
"\"After row stuff\"",
")",
";",
"A",
".",
"original",
".",
"print",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Performs a standard bidiagonal decomposition just on the outer blocks of the provided matrix
@param blockLength
@param A
@param gammasU
|
[
"Performs",
"a",
"standard",
"bidiagonal",
"decomposition",
"just",
"on",
"the",
"outer",
"blocks",
"of",
"the",
"provided",
"matrix"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/decomposition/bidiagonal/BidiagonalHelper_DDRB.java#L39-L88
|
162,457 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/block/linsol/chol/CholeskyOuterSolver_DDRB.java
|
CholeskyOuterSolver_DDRB.setA
|
@Override
public boolean setA(DMatrixRBlock A) {
// Extract a lower triangular solution
if( !decomposer.decompose(A) )
return false;
blockLength = A.blockLength;
return true;
}
|
java
|
@Override
public boolean setA(DMatrixRBlock A) {
// Extract a lower triangular solution
if( !decomposer.decompose(A) )
return false;
blockLength = A.blockLength;
return true;
}
|
[
"@",
"Override",
"public",
"boolean",
"setA",
"(",
"DMatrixRBlock",
"A",
")",
"{",
"// Extract a lower triangular solution",
"if",
"(",
"!",
"decomposer",
".",
"decompose",
"(",
"A",
")",
")",
"return",
"false",
";",
"blockLength",
"=",
"A",
".",
"blockLength",
";",
"return",
"true",
";",
"}"
] |
Decomposes and overwrites the input matrix.
@param A Semi-Positive Definite (SPD) system matrix. Modified. Reference saved.
@return If the matrix can be decomposed. Will always return false of not SPD.
|
[
"Decomposes",
"and",
"overwrites",
"the",
"input",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/linsol/chol/CholeskyOuterSolver_DDRB.java#L67-L76
|
162,458 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/block/linsol/chol/CholeskyOuterSolver_DDRB.java
|
CholeskyOuterSolver_DDRB.solve
|
@Override
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 IllegalArgumentException("Unexpected blocklength in X.");
if( X.numRows != L.col1 ) throw new IllegalArgumentException("Not enough rows in X");
}
if( B.numRows != L.col1 ) throw new IllegalArgumentException("Not enough rows in B");
// L * L^T*X = B
// Solve for Y: L*Y = B
TriangularSolver_DDRB.solve(blockLength,false,L,new DSubmatrixD1(B),false);
// L^T * X = Y
TriangularSolver_DDRB.solve(blockLength,false,L,new DSubmatrixD1(B),true);
if( X != null ) {
// copy the solution from B into X
MatrixOps_DDRB.extractAligned(B,X);
}
}
|
java
|
@Override
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 IllegalArgumentException("Unexpected blocklength in X.");
if( X.numRows != L.col1 ) throw new IllegalArgumentException("Not enough rows in X");
}
if( B.numRows != L.col1 ) throw new IllegalArgumentException("Not enough rows in B");
// L * L^T*X = B
// Solve for Y: L*Y = B
TriangularSolver_DDRB.solve(blockLength,false,L,new DSubmatrixD1(B),false);
// L^T * X = Y
TriangularSolver_DDRB.solve(blockLength,false,L,new DSubmatrixD1(B),true);
if( X != null ) {
// copy the solution from B into X
MatrixOps_DDRB.extractAligned(B,X);
}
}
|
[
"@",
"Override",
"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",
"IllegalArgumentException",
"(",
"\"Unexpected blocklength in X.\"",
")",
";",
"if",
"(",
"X",
".",
"numRows",
"!=",
"L",
".",
"col1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Not enough rows in X\"",
")",
";",
"}",
"if",
"(",
"B",
".",
"numRows",
"!=",
"L",
".",
"col1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Not enough rows in B\"",
")",
";",
"// L * L^T*X = B",
"// Solve for Y: L*Y = B",
"TriangularSolver_DDRB",
".",
"solve",
"(",
"blockLength",
",",
"false",
",",
"L",
",",
"new",
"DSubmatrixD1",
"(",
"B",
")",
",",
"false",
")",
";",
"// L^T * X = Y",
"TriangularSolver_DDRB",
".",
"solve",
"(",
"blockLength",
",",
"false",
",",
"L",
",",
"new",
"DSubmatrixD1",
"(",
"B",
")",
",",
"true",
")",
";",
"if",
"(",
"X",
"!=",
"null",
")",
"{",
"// copy the solution from B into X",
"MatrixOps_DDRB",
".",
"extractAligned",
"(",
"B",
",",
"X",
")",
";",
"}",
"}"
] |
If X == null then the solution is written into B. Otherwise the solution is copied
from B into X.
|
[
"If",
"X",
"==",
"null",
"then",
"the",
"solution",
"is",
"written",
"into",
"B",
".",
"Otherwise",
"the",
"solution",
"is",
"copied",
"from",
"B",
"into",
"X",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/linsol/chol/CholeskyOuterSolver_DDRB.java#L87-L115
|
162,459 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/IGrowArray.java
|
IGrowArray.growInternal
|
public void growInternal(int amount ) {
int tmp[] = new int[ data.length + amount ];
System.arraycopy(data,0,tmp,0,data.length);
this.data = tmp;
}
|
java
|
public void growInternal(int amount ) {
int tmp[] = new int[ data.length + amount ];
System.arraycopy(data,0,tmp,0,data.length);
this.data = tmp;
}
|
[
"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.
this.data = new data_type[ data.length + amount ]
@param amount Number of elements added to the internal array's length
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/IGrowArray.java#L60-L65
|
162,460 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/block/decomposition/chol/InnerCholesky_DDRB.java
|
InnerCholesky_DDRB.lower
|
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];
// todo optimize
for( int k = 0; k < i; k++ ) {
sum -= T[ indexT + i*n+k] * T[ indexT + j*n+k];
}
if( i == j ) {
// is it positive-definite?
if( sum <= 0.0 )
return false;
el_ii = Math.sqrt(sum);
T[ indexT + i*n+i] = el_ii;
div_el_ii = 1.0/el_ii;
} else {
T[ indexT + j*n+i] = sum*div_el_ii;
}
}
}
return true;
}
|
java
|
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];
// todo optimize
for( int k = 0; k < i; k++ ) {
sum -= T[ indexT + i*n+k] * T[ indexT + j*n+k];
}
if( i == j ) {
// is it positive-definite?
if( sum <= 0.0 )
return false;
el_ii = Math.sqrt(sum);
T[ indexT + i*n+i] = el_ii;
div_el_ii = 1.0/el_ii;
} else {
T[ indexT + j*n+i] = sum*div_el_ii;
}
}
}
return true;
}
|
[
"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",
"]",
";",
"// todo optimize",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"i",
";",
"k",
"++",
")",
"{",
"sum",
"-=",
"T",
"[",
"indexT",
"+",
"i",
"*",
"n",
"+",
"k",
"]",
"*",
"T",
"[",
"indexT",
"+",
"j",
"*",
"n",
"+",
"k",
"]",
";",
"}",
"if",
"(",
"i",
"==",
"j",
")",
"{",
"// is it positive-definite?",
"if",
"(",
"sum",
"<=",
"0.0",
")",
"return",
"false",
";",
"el_ii",
"=",
"Math",
".",
"sqrt",
"(",
"sum",
")",
";",
"T",
"[",
"indexT",
"+",
"i",
"*",
"n",
"+",
"i",
"]",
"=",
"el_ii",
";",
"div_el_ii",
"=",
"1.0",
"/",
"el_ii",
";",
"}",
"else",
"{",
"T",
"[",
"indexT",
"+",
"j",
"*",
"n",
"+",
"i",
"]",
"=",
"sum",
"*",
"div_el_ii",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
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.
@param T Array containing an inner row-major matrix. Modified.
@param indexT First index of the inner row-major matrix.
@param n Number of rows and columns of the matrix.
@return If the decomposition succeeded.
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/decomposition/chol/InnerCholesky_DDRB.java#L97-L125
|
162,461 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/factory/LinearSolverFactory_DDRM.java
|
LinearSolverFactory_DDRM.general
|
public static LinearSolverDense<DMatrixRMaj> general(int numRows , int numCols ) {
if( numRows == numCols )
return linear(numRows);
else
return leastSquares(numRows,numCols);
}
|
java
|
public static LinearSolverDense<DMatrixRMaj> general(int numRows , int numCols ) {
if( numRows == numCols )
return linear(numRows);
else
return leastSquares(numRows,numCols);
}
|
[
"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.
@param numRows The number of rows that the decomposition is optimized for.
@param numCols The number of columns that the decomposition is optimized for.
|
[
"Creates",
"a",
"general",
"purpose",
"solver",
".",
"Use",
"this",
"if",
"you",
"are",
"not",
"sure",
"what",
"you",
"need",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/factory/LinearSolverFactory_DDRM.java#L77-L82
|
162,462 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/factory/LinearSolverFactory_DDRM.java
|
LinearSolverFactory_DDRM.symmPosDef
|
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 == EjmlParameters.MemoryUsage.FASTER )
return new LinearSolverChol_DDRB();
else {
CholeskyDecompositionCommon_DDRM decomp = new CholeskyDecompositionInner_DDRM(true);
return new LinearSolverChol_DDRM(decomp);
}
}
}
|
java
|
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 == EjmlParameters.MemoryUsage.FASTER )
return new LinearSolverChol_DDRB();
else {
CholeskyDecompositionCommon_DDRM decomp = new CholeskyDecompositionInner_DDRM(true);
return new LinearSolverChol_DDRM(decomp);
}
}
}
|
[
"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",
"==",
"EjmlParameters",
".",
"MemoryUsage",
".",
"FASTER",
")",
"return",
"new",
"LinearSolverChol_DDRB",
"(",
")",
";",
"else",
"{",
"CholeskyDecompositionCommon_DDRM",
"decomp",
"=",
"new",
"CholeskyDecompositionInner_DDRM",
"(",
"true",
")",
";",
"return",
"new",
"LinearSolverChol_DDRM",
"(",
"decomp",
")",
";",
"}",
"}",
"}"
] |
Creates a solver for symmetric positive definite matrices.
@return A new solver for symmetric positive definite matrices.
|
[
"Creates",
"a",
"solver",
"for",
"symmetric",
"positive",
"definite",
"matrices",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/factory/LinearSolverFactory_DDRM.java#L117-L129
|
162,463 |
lessthanoptimal/ejml
|
examples/src/org/ejml/example/LevenbergMarquardt.java
|
LevenbergMarquardt.setConvergence
|
public void setConvergence( int maxIterations , double ftol , double gtol ) {
this.maxIterations = maxIterations;
this.ftol = ftol;
this.gtol = gtol;
}
|
java
|
public void setConvergence( int maxIterations , double ftol , double gtol ) {
this.maxIterations = maxIterations;
this.ftol = ftol;
this.gtol = gtol;
}
|
[
"public",
"void",
"setConvergence",
"(",
"int",
"maxIterations",
",",
"double",
"ftol",
",",
"double",
"gtol",
")",
"{",
"this",
".",
"maxIterations",
"=",
"maxIterations",
";",
"this",
".",
"ftol",
"=",
"ftol",
";",
"this",
".",
"gtol",
"=",
"gtol",
";",
"}"
] |
Specifies convergence criteria
@param maxIterations Maximum number of iterations
@param ftol convergence based on change in function value. try 1e-12
@param gtol convergence based on residual magnitude. Try 1e-12
|
[
"Specifies",
"convergence",
"criteria"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/LevenbergMarquardt.java#L107-L111
|
162,464 |
lessthanoptimal/ejml
|
examples/src/org/ejml/example/LevenbergMarquardt.java
|
LevenbergMarquardt.computeGradientAndHessian
|
private void computeGradientAndHessian(DMatrixRMaj param )
{
// residuals = f(x) - y
function.compute(param, residuals);
computeNumericalJacobian(param,jacobian);
CommonOps_DDRM.multTransA(jacobian, residuals, g);
CommonOps_DDRM.multTransA(jacobian, jacobian, H);
CommonOps_DDRM.extractDiag(H,Hdiag);
}
|
java
|
private void computeGradientAndHessian(DMatrixRMaj param )
{
// residuals = f(x) - y
function.compute(param, residuals);
computeNumericalJacobian(param,jacobian);
CommonOps_DDRM.multTransA(jacobian, residuals, g);
CommonOps_DDRM.multTransA(jacobian, jacobian, H);
CommonOps_DDRM.extractDiag(H,Hdiag);
}
|
[
"private",
"void",
"computeGradientAndHessian",
"(",
"DMatrixRMaj",
"param",
")",
"{",
"// residuals = f(x) - y",
"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.
d = J'*(f(x)-y) <--- that's also the gradient
H = J'*J
|
[
"Computes",
"the",
"d",
"and",
"H",
"parameters",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/LevenbergMarquardt.java#L217-L228
|
162,465 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixRMaj.java
|
DMatrixRMaj.wrap
|
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;
}
|
java
|
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;
}
|
[
"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.
@param numRows Number of rows in the matrix.
@param numCols Number of columns in the matrix.
@param data Data that is being wrapped. Referenced Saved.
@return A matrix which references the provided data internally.
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixRMaj.java#L175-L182
|
162,466 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixRMaj.java
|
DMatrixRMaj.add
|
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;
}
|
java
|
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;
}
|
[
"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
|
[
"todo",
"move",
"to",
"commonops"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixRMaj.java#L238-L244
|
162,467 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixRMaj.java
|
DMatrixRMaj.get
|
@Override
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 ];
}
|
java
|
@Override
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 ];
}
|
[
"@",
"Override",
"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.
@param row The row of the element.
@param col The column of the element.
@return The value of the element.
|
[
"Returns",
"the",
"value",
"of",
"the",
"specified",
"matrix",
"element",
".",
"Performs",
"a",
"bounds",
"check",
"to",
"make",
"sure",
"the",
"requested",
"element",
"is",
"part",
"of",
"the",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixRMaj.java#L254-L261
|
162,468 |
lessthanoptimal/ejml
|
main/ejml-core/src/org/ejml/data/DMatrixRMaj.java
|
DMatrixRMaj.set
|
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(data,0,this.data,0,length);
} else {
int index = 0;
for( int i = 0; i < numRows; i++ ) {
for( int j = 0; j < numCols; j++ ) {
this.data[index++] = data[j*numRows+i];
}
}
}
}
|
java
|
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(data,0,this.data,0,length);
} else {
int index = 0;
for( int i = 0; i < numRows; i++ ) {
for( int j = 0; j < numCols; j++ ) {
this.data[index++] = data[j*numRows+i];
}
}
}
}
|
[
"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",
"(",
"data",
",",
"0",
",",
"this",
".",
"data",
",",
"0",
",",
"length",
")",
";",
"}",
"else",
"{",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numRows",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"numCols",
";",
"j",
"++",
")",
"{",
"this",
".",
"data",
"[",
"index",
"++",
"]",
"=",
"data",
"[",
"j",
"*",
"numRows",
"+",
"i",
"]",
";",
"}",
"}",
"}",
"}"
] |
Sets this matrix equal to the matrix encoded in the array.
@param numRows The number of rows.
@param numCols The number of columns.
@param rowMajor If the array is encoded in a row-major or a column-major format.
@param data The formatted 1D array. Not modified.
|
[
"Sets",
"this",
"matrix",
"equal",
"to",
"the",
"matrix",
"encoded",
"in",
"the",
"array",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/data/DMatrixRMaj.java#L303-L321
|
162,469 |
lessthanoptimal/ejml
|
main/ejml-ddense/src/org/ejml/dense/row/linsol/chol/LinearSolverChol_DDRB.java
|
LinearSolverChol_DDRB.solve
|
@Override
public void solve(DMatrixRMaj B, DMatrixRMaj X) {
blockB.reshape(B.numRows,B.numCols,false);
MatrixOps_DDRB.convert(B,blockB);
// since overwrite B is true X does not need to be passed in
alg.solve(blockB,null);
MatrixOps_DDRB.convert(blockB,X);
}
|
java
|
@Override
public void solve(DMatrixRMaj B, DMatrixRMaj X) {
blockB.reshape(B.numRows,B.numCols,false);
MatrixOps_DDRB.convert(B,blockB);
// since overwrite B is true X does not need to be passed in
alg.solve(blockB,null);
MatrixOps_DDRB.convert(blockB,X);
}
|
[
"@",
"Override",
"public",
"void",
"solve",
"(",
"DMatrixRMaj",
"B",
",",
"DMatrixRMaj",
"X",
")",
"{",
"blockB",
".",
"reshape",
"(",
"B",
".",
"numRows",
",",
"B",
".",
"numCols",
",",
"false",
")",
";",
"MatrixOps_DDRB",
".",
"convert",
"(",
"B",
",",
"blockB",
")",
";",
"// since overwrite B is true X does not need to be passed in",
"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.
@param B A matrix ℜ <sup>m × p</sup>. Not modified.
@param X A matrix ℜ <sup>n × p</sup>, where the solution is written to. Modified.
|
[
"Only",
"converts",
"the",
"B",
"matrix",
"and",
"passes",
"that",
"onto",
"solve",
".",
"Te",
"result",
"is",
"then",
"copied",
"into",
"the",
"input",
"X",
"matrix",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/linsol/chol/LinearSolverChol_DDRB.java#L47-L56
|
162,470 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/simple/SimpleEVD.java
|
SimpleEVD.getEigenvalues
|
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 {
EigenDecomposition_F32 d = (EigenDecomposition_F32)eig;
for (int i = 0; i < eig.getNumberOfEigenvalues(); i++) {
Complex_F32 c = d.getEigenvalue(i);
ret.add(new Complex_F64(c.real, c.imaginary));
}
}
return ret;
}
|
java
|
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 {
EigenDecomposition_F32 d = (EigenDecomposition_F32)eig;
for (int i = 0; i < eig.getNumberOfEigenvalues(); i++) {
Complex_F32 c = d.getEigenvalue(i);
ret.add(new Complex_F64(c.real, c.imaginary));
}
}
return ret;
}
|
[
"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",
"{",
"EigenDecomposition_F32",
"d",
"=",
"(",
"EigenDecomposition_F32",
")",
"eig",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"eig",
".",
"getNumberOfEigenvalues",
"(",
")",
";",
"i",
"++",
")",
"{",
"Complex_F32",
"c",
"=",
"d",
".",
"getEigenvalue",
"(",
"i",
")",
";",
"ret",
".",
"add",
"(",
"new",
"Complex_F64",
"(",
"c",
".",
"real",
",",
"c",
".",
"imaginary",
")",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] |
Returns a list of all the eigenvalues
|
[
"Returns",
"a",
"list",
"of",
"all",
"the",
"eigenvalues"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/simple/SimpleEVD.java#L63-L80
|
162,471 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/simple/SimpleEVD.java
|
SimpleEVD.getIndexMax
|
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;
}
|
java
|
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;
}
|
[
"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.
@return index of the largest magnitude eigen value.
|
[
"Returns",
"the",
"index",
"of",
"the",
"eigenvalue",
"which",
"has",
"the",
"largest",
"magnitude",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/simple/SimpleEVD.java#L166-L180
|
162,472 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/simple/SimpleEVD.java
|
SimpleEVD.getIndexMin
|
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;
}
|
java
|
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;
}
|
[
"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.
@return index of the smallest magnitude eigen value.
|
[
"Returns",
"the",
"index",
"of",
"the",
"eigenvalue",
"which",
"has",
"the",
"smallest",
"magnitude",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/simple/SimpleEVD.java#L187-L201
|
162,473 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java
|
QrStructuralCounts_DSCC.process
|
public boolean process( DMatrixSparseCSC A ) {
init(A);
TriangularSolver_DSCC.eliminationTree(A,true,parent,gwork);
countNonZeroInR(parent);
countNonZeroInV(parent);
// if more columns than rows it's possible that Q*R != A. That's because a householder
// would need to be created that's outside the m by m Q matrix. In reality it has
// a partial solution. Column pivot are needed.
if( m < n ) {
for (int row = 0; row <m; row++) {
if( gwork.data[head+row] < 0 ) {
return false;
}
}
}
return true;
}
|
java
|
public boolean process( DMatrixSparseCSC A ) {
init(A);
TriangularSolver_DSCC.eliminationTree(A,true,parent,gwork);
countNonZeroInR(parent);
countNonZeroInV(parent);
// if more columns than rows it's possible that Q*R != A. That's because a householder
// would need to be created that's outside the m by m Q matrix. In reality it has
// a partial solution. Column pivot are needed.
if( m < n ) {
for (int row = 0; row <m; row++) {
if( gwork.data[head+row] < 0 ) {
return false;
}
}
}
return true;
}
|
[
"public",
"boolean",
"process",
"(",
"DMatrixSparseCSC",
"A",
")",
"{",
"init",
"(",
"A",
")",
";",
"TriangularSolver_DSCC",
".",
"eliminationTree",
"(",
"A",
",",
"true",
",",
"parent",
",",
"gwork",
")",
";",
"countNonZeroInR",
"(",
"parent",
")",
";",
"countNonZeroInV",
"(",
"parent",
")",
";",
"// if more columns than rows it's possible that Q*R != A. That's because a householder",
"// would need to be created that's outside the m by m Q matrix. In reality it has",
"// a partial solution. Column pivot are needed.",
"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
@param A matrix which is to be decomposed
@return true if the solution is valid or false if the decomposition can't be performed (i.e. requires column pivots)
|
[
"Examins",
"the",
"structure",
"of",
"A",
"for",
"QR",
"decomposition"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java#L65-L84
|
162,474 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java
|
QrStructuralCounts_DSCC.init
|
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 = new int[n];
leftmost = new int[m];
}
gwork.reshape(m+3*n);
}
|
java
|
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 = new int[n];
leftmost = new int[m];
}
gwork.reshape(m+3*n);
}
|
[
"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",
"=",
"new",
"int",
"[",
"n",
"]",
";",
"leftmost",
"=",
"new",
"int",
"[",
"m",
"]",
";",
"}",
"gwork",
".",
"reshape",
"(",
"m",
"+",
"3",
"*",
"n",
")",
";",
"}"
] |
Initializes data structures
|
[
"Initializes",
"data",
"structures"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java#L89-L107
|
162,475 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java
|
QrStructuralCounts_DSCC.countNonZeroInR
|
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 overflow in R counts");
}
|
java
|
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 overflow in R counts");
}
|
[
"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 overflow in R counts\"",
")",
";",
"}"
] |
Count the number of non-zero elements in R
|
[
"Count",
"the",
"number",
"of",
"non",
"-",
"zero",
"elements",
"in",
"R"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java#L113-L122
|
162,476 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java
|
QrStructuralCounts_DSCC.countNonZeroInV
|
void countNonZeroInV( int []parent ) {
int []w = gwork.data;
findMinElementIndexInRows(leftmost);
createRowElementLinkedLists(leftmost,w);
countNonZeroUsingLinkedList(parent,w);
}
|
java
|
void countNonZeroInV( int []parent ) {
int []w = gwork.data;
findMinElementIndexInRows(leftmost);
createRowElementLinkedLists(leftmost,w);
countNonZeroUsingLinkedList(parent,w);
}
|
[
"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
|
[
"Count",
"the",
"number",
"of",
"non",
"-",
"zero",
"elements",
"in",
"V"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java#L127-L132
|
162,477 |
lessthanoptimal/ejml
|
main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java
|
QrStructuralCounts_DSCC.countNonZeroUsingLinkedList
|
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]; // remove row i from queue k
nz_in_V++; // count V(k,k) as nonzero
if( i < 0) // add a fictitious row since there are no nz elements
i = m2++;
pinv[i] = k; // associate row i with V(:,k)
if( --ll[nque+k] <= 0 )
continue;
nz_in_V += ll[nque+k];
int pa;
if( (pa = parent[k]) != -1 ) { // move all rows to parent of k
if( ll[nque+pa] == 0)
ll[tail+pa] = ll[tail+k];
ll[next+ll[tail+k]] = ll[head+pa];
ll[head+pa] = ll[next+i];
ll[nque+pa] += ll[nque+k];
}
}
for (int i = 0, k = n; i < m; i++) {
if( pinv[i] < 0 )
pinv[i] = k++;
}
if( nz_in_V < 0)
throw new RuntimeException("Too many elements. Numerical overflow in V counts");
}
|
java
|
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]; // remove row i from queue k
nz_in_V++; // count V(k,k) as nonzero
if( i < 0) // add a fictitious row since there are no nz elements
i = m2++;
pinv[i] = k; // associate row i with V(:,k)
if( --ll[nque+k] <= 0 )
continue;
nz_in_V += ll[nque+k];
int pa;
if( (pa = parent[k]) != -1 ) { // move all rows to parent of k
if( ll[nque+pa] == 0)
ll[tail+pa] = ll[tail+k];
ll[next+ll[tail+k]] = ll[head+pa];
ll[head+pa] = ll[next+i];
ll[nque+pa] += ll[nque+k];
}
}
for (int i = 0, k = n; i < m; i++) {
if( pinv[i] < 0 )
pinv[i] = k++;
}
if( nz_in_V < 0)
throw new RuntimeException("Too many elements. Numerical overflow in V counts");
}
|
[
"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",
"]",
";",
"// remove row i from queue k",
"nz_in_V",
"++",
";",
"// count V(k,k) as nonzero",
"if",
"(",
"i",
"<",
"0",
")",
"// add a fictitious row since there are no nz elements",
"i",
"=",
"m2",
"++",
";",
"pinv",
"[",
"i",
"]",
"=",
"k",
";",
"// associate row i with V(:,k)",
"if",
"(",
"--",
"ll",
"[",
"nque",
"+",
"k",
"]",
"<=",
"0",
")",
"continue",
";",
"nz_in_V",
"+=",
"ll",
"[",
"nque",
"+",
"k",
"]",
";",
"int",
"pa",
";",
"if",
"(",
"(",
"pa",
"=",
"parent",
"[",
"k",
"]",
")",
"!=",
"-",
"1",
")",
"{",
"// move all rows to parent of k",
"if",
"(",
"ll",
"[",
"nque",
"+",
"pa",
"]",
"==",
"0",
")",
"ll",
"[",
"tail",
"+",
"pa",
"]",
"=",
"ll",
"[",
"tail",
"+",
"k",
"]",
";",
"ll",
"[",
"next",
"+",
"ll",
"[",
"tail",
"+",
"k",
"]",
"]",
"=",
"ll",
"[",
"head",
"+",
"pa",
"]",
";",
"ll",
"[",
"head",
"+",
"pa",
"]",
"=",
"ll",
"[",
"next",
"+",
"i",
"]",
";",
"ll",
"[",
"nque",
"+",
"pa",
"]",
"+=",
"ll",
"[",
"nque",
"+",
"k",
"]",
";",
"}",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"k",
"=",
"n",
";",
"i",
"<",
"m",
";",
"i",
"++",
")",
"{",
"if",
"(",
"pinv",
"[",
"i",
"]",
"<",
"0",
")",
"pinv",
"[",
"i",
"]",
"=",
"k",
"++",
";",
"}",
"if",
"(",
"nz_in_V",
"<",
"0",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Too many elements. Numerical overflow in V counts\"",
")",
";",
"}"
] |
Non-zero counts of Householder vectors and computes a permutation
matrix that ensures diagonal entires are all structurally nonzero.
@param parent elimination tree
@param ll linked list for each row that specifies elements that are not zero
|
[
"Non",
"-",
"zero",
"counts",
"of",
"Householder",
"vectors",
"and",
"computes",
"a",
"permutation",
"matrix",
"that",
"ensures",
"diagonal",
"entires",
"are",
"all",
"structurally",
"nonzero",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/decomposition/qr/QrStructuralCounts_DSCC.java#L141-L172
|
162,478 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.alias
|
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));
}else {
old.matrix = variable;
}
}
|
java
|
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));
}else {
old.matrix = variable;
}
}
|
[
"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",
")",
")",
";",
"}",
"else",
"{",
"old",
".",
"matrix",
"=",
"variable",
";",
"}",
"}"
] |
Adds a new Matrix variable. If one already has the same name it is written over.
While more verbose for multiple variables, this function doesn't require new memory be declared
each time it's called.
@param variable Matrix which is to be assigned to name
@param name The name of the variable
|
[
"Adds",
"a",
"new",
"Matrix",
"variable",
".",
"If",
"one",
"already",
"has",
"the",
"same",
"name",
"it",
"is",
"written",
"over",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L288-L297
|
162,479 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.alias
|
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));
}else {
old.value = value;
}
}
|
java
|
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));
}else {
old.value = value;
}
}
|
[
"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",
")",
")",
";",
"}",
"else",
"{",
"old",
".",
"value",
"=",
"value",
";",
"}",
"}"
] |
Adds a new floating point variable. If one already has the same name it is written over.
@param value Value of the number
@param name Name in code
|
[
"Adds",
"a",
"new",
"floating",
"point",
"variable",
".",
"If",
"one",
"already",
"has",
"the",
"same",
"name",
"it",
"is",
"written",
"over",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L320-L330
|
162,480 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.alias
|
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]);
}
}
|
java
|
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]);
}
}
|
[
"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.
|
[
"Creates",
"multiple",
"aliases",
"at",
"once",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L364-L371
|
162,481 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.aliasGeneric
|
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.getClass() == DMatrixRMaj.class ) {
alias((DMatrixRMaj)variable,name);
} else if( variable.getClass() == FMatrixRMaj.class ) {
alias((FMatrixRMaj)variable,name);
} else if( variable.getClass() == DMatrixSparseCSC.class ) {
alias((DMatrixSparseCSC)variable,name);
} else if( variable.getClass() == SimpleMatrix.class ) {
alias((SimpleMatrix) variable, name);
} else if( variable instanceof DMatrixFixed ) {
DMatrixRMaj M = new DMatrixRMaj(1,1);
ConvertDMatrixStruct.convert((DMatrixFixed)variable,M);
alias(M,name);
} else if( variable instanceof FMatrixFixed ) {
FMatrixRMaj M = new FMatrixRMaj(1,1);
ConvertFMatrixStruct.convert((FMatrixFixed)variable,M);
alias(M,name);
} else {
throw new RuntimeException("Unknown value type of "+
(variable.getClass().getSimpleName())+" for variable "+name);
}
}
|
java
|
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.getClass() == DMatrixRMaj.class ) {
alias((DMatrixRMaj)variable,name);
} else if( variable.getClass() == FMatrixRMaj.class ) {
alias((FMatrixRMaj)variable,name);
} else if( variable.getClass() == DMatrixSparseCSC.class ) {
alias((DMatrixSparseCSC)variable,name);
} else if( variable.getClass() == SimpleMatrix.class ) {
alias((SimpleMatrix) variable, name);
} else if( variable instanceof DMatrixFixed ) {
DMatrixRMaj M = new DMatrixRMaj(1,1);
ConvertDMatrixStruct.convert((DMatrixFixed)variable,M);
alias(M,name);
} else if( variable instanceof FMatrixFixed ) {
FMatrixRMaj M = new FMatrixRMaj(1,1);
ConvertFMatrixStruct.convert((FMatrixFixed)variable,M);
alias(M,name);
} else {
throw new RuntimeException("Unknown value type of "+
(variable.getClass().getSimpleName())+" for variable "+name);
}
}
|
[
"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",
".",
"getClass",
"(",
")",
"==",
"DMatrixRMaj",
".",
"class",
")",
"{",
"alias",
"(",
"(",
"DMatrixRMaj",
")",
"variable",
",",
"name",
")",
";",
"}",
"else",
"if",
"(",
"variable",
".",
"getClass",
"(",
")",
"==",
"FMatrixRMaj",
".",
"class",
")",
"{",
"alias",
"(",
"(",
"FMatrixRMaj",
")",
"variable",
",",
"name",
")",
";",
"}",
"else",
"if",
"(",
"variable",
".",
"getClass",
"(",
")",
"==",
"DMatrixSparseCSC",
".",
"class",
")",
"{",
"alias",
"(",
"(",
"DMatrixSparseCSC",
")",
"variable",
",",
"name",
")",
";",
"}",
"else",
"if",
"(",
"variable",
".",
"getClass",
"(",
")",
"==",
"SimpleMatrix",
".",
"class",
")",
"{",
"alias",
"(",
"(",
"SimpleMatrix",
")",
"variable",
",",
"name",
")",
";",
"}",
"else",
"if",
"(",
"variable",
"instanceof",
"DMatrixFixed",
")",
"{",
"DMatrixRMaj",
"M",
"=",
"new",
"DMatrixRMaj",
"(",
"1",
",",
"1",
")",
";",
"ConvertDMatrixStruct",
".",
"convert",
"(",
"(",
"DMatrixFixed",
")",
"variable",
",",
"M",
")",
";",
"alias",
"(",
"M",
",",
"name",
")",
";",
"}",
"else",
"if",
"(",
"variable",
"instanceof",
"FMatrixFixed",
")",
"{",
"FMatrixRMaj",
"M",
"=",
"new",
"FMatrixRMaj",
"(",
"1",
",",
"1",
")",
";",
"ConvertFMatrixStruct",
".",
"convert",
"(",
"(",
"FMatrixFixed",
")",
"variable",
",",
"M",
")",
";",
"alias",
"(",
"M",
",",
"name",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unknown value type of \"",
"+",
"(",
"variable",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
")",
"+",
"\" for variable \"",
"+",
"name",
")",
";",
"}",
"}"
] |
Aliases variables with an unknown type.
@param variable The variable being aliased
@param name Name of the variable
|
[
"Aliases",
"variables",
"with",
"an",
"unknown",
"type",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L378-L403
|
162,482 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.compile
|
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.Token t0 = tokens.getFirst();
if( t0.word != null && t0.word.compareToIgnoreCase("macro") == 0 ) {
parseMacro(tokens,sequence);
} else {
insertFunctionsAndVariables(tokens);
insertMacros(tokens);
if (debug) {
System.out.println("Parsed tokens:\n------------");
tokens.print();
System.out.println();
}
// Get the results variable
if (t0.getType() != Type.VARIABLE && t0.getType() != Type.WORD) {
compileTokens(sequence,tokens);
// If there's no output then this is acceptable, otherwise it's assumed to be a bug
// If there's no output then a configuration was changed
Variable variable = tokens.getFirst().getVariable();
if( variable != null ) {
if( assignment )
throw new IllegalArgumentException("No assignment to an output variable could be found. Found " + t0);
else {
sequence.output = variable; // set this to be the output for print()
}
}
} else {
compileAssignment(sequence, tokens, t0);
}
if (debug) {
System.out.println("Operations:\n------------");
for (int i = 0; i < sequence.operations.size(); i++) {
System.out.println(sequence.operations.get(i).name());
}
}
}
return sequence;
}
|
java
|
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.Token t0 = tokens.getFirst();
if( t0.word != null && t0.word.compareToIgnoreCase("macro") == 0 ) {
parseMacro(tokens,sequence);
} else {
insertFunctionsAndVariables(tokens);
insertMacros(tokens);
if (debug) {
System.out.println("Parsed tokens:\n------------");
tokens.print();
System.out.println();
}
// Get the results variable
if (t0.getType() != Type.VARIABLE && t0.getType() != Type.WORD) {
compileTokens(sequence,tokens);
// If there's no output then this is acceptable, otherwise it's assumed to be a bug
// If there's no output then a configuration was changed
Variable variable = tokens.getFirst().getVariable();
if( variable != null ) {
if( assignment )
throw new IllegalArgumentException("No assignment to an output variable could be found. Found " + t0);
else {
sequence.output = variable; // set this to be the output for print()
}
}
} else {
compileAssignment(sequence, tokens, t0);
}
if (debug) {
System.out.println("Operations:\n------------");
for (int i = 0; i < sequence.operations.size(); i++) {
System.out.println(sequence.operations.get(i).name());
}
}
}
return sequence;
}
|
[
"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",
".",
"Token",
"t0",
"=",
"tokens",
".",
"getFirst",
"(",
")",
";",
"if",
"(",
"t0",
".",
"word",
"!=",
"null",
"&&",
"t0",
".",
"word",
".",
"compareToIgnoreCase",
"(",
"\"macro\"",
")",
"==",
"0",
")",
"{",
"parseMacro",
"(",
"tokens",
",",
"sequence",
")",
";",
"}",
"else",
"{",
"insertFunctionsAndVariables",
"(",
"tokens",
")",
";",
"insertMacros",
"(",
"tokens",
")",
";",
"if",
"(",
"debug",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Parsed tokens:\\n------------\"",
")",
";",
"tokens",
".",
"print",
"(",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
")",
";",
"}",
"// Get the results variable",
"if",
"(",
"t0",
".",
"getType",
"(",
")",
"!=",
"Type",
".",
"VARIABLE",
"&&",
"t0",
".",
"getType",
"(",
")",
"!=",
"Type",
".",
"WORD",
")",
"{",
"compileTokens",
"(",
"sequence",
",",
"tokens",
")",
";",
"// If there's no output then this is acceptable, otherwise it's assumed to be a bug",
"// If there's no output then a configuration was changed",
"Variable",
"variable",
"=",
"tokens",
".",
"getFirst",
"(",
")",
".",
"getVariable",
"(",
")",
";",
"if",
"(",
"variable",
"!=",
"null",
")",
"{",
"if",
"(",
"assignment",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No assignment to an output variable could be found. Found \"",
"+",
"t0",
")",
";",
"else",
"{",
"sequence",
".",
"output",
"=",
"variable",
";",
"// set this to be the output for print()",
"}",
"}",
"}",
"else",
"{",
"compileAssignment",
"(",
"sequence",
",",
"tokens",
",",
"t0",
")",
";",
"}",
"if",
"(",
"debug",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Operations:\\n------------\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"sequence",
".",
"operations",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"sequence",
".",
"operations",
".",
"get",
"(",
"i",
")",
".",
"name",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"sequence",
";",
"}"
] |
Parses the equation and compiles it into a sequence which can be executed later on
@param equation String in simple equation format.
@param assignment if true an assignment is expected and an exception if thrown if there is non
@param debug if true it will print out debugging information
@return Sequence of operations on the variables
|
[
"Parses",
"the",
"equation",
"and",
"compiles",
"it",
"into",
"a",
"sequence",
"which",
"can",
"be",
"executed",
"later",
"on"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L416-L466
|
162,483 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseMacro
|
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 ArrayList<TokenList.Token>();
macro.name = t.word;
t = t.next;
t = parseMacroInput(variableTokens, t);
for( TokenList.Token a : variableTokens ) {
if( a.word == null) throw new ParseError("expected word in macro header");
macro.inputs.add(a.word);
}
t = t.next;
if( t == null || t.getSymbol() != Symbol.ASSIGN)
throw new ParseError("Expected assignment");
t = t.next;
macro.tokens = new TokenList(t,tokens.last);
sequence.addOperation(macro.createOperation(macros));
}
|
java
|
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 ArrayList<TokenList.Token>();
macro.name = t.word;
t = t.next;
t = parseMacroInput(variableTokens, t);
for( TokenList.Token a : variableTokens ) {
if( a.word == null) throw new ParseError("expected word in macro header");
macro.inputs.add(a.word);
}
t = t.next;
if( t == null || t.getSymbol() != Symbol.ASSIGN)
throw new ParseError("Expected assignment");
t = t.next;
macro.tokens = new TokenList(t,tokens.last);
sequence.addOperation(macro.createOperation(macros));
}
|
[
"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",
"ArrayList",
"<",
"TokenList",
".",
"Token",
">",
"(",
")",
";",
"macro",
".",
"name",
"=",
"t",
".",
"word",
";",
"t",
"=",
"t",
".",
"next",
";",
"t",
"=",
"parseMacroInput",
"(",
"variableTokens",
",",
"t",
")",
";",
"for",
"(",
"TokenList",
".",
"Token",
"a",
":",
"variableTokens",
")",
"{",
"if",
"(",
"a",
".",
"word",
"==",
"null",
")",
"throw",
"new",
"ParseError",
"(",
"\"expected word in macro header\"",
")",
";",
"macro",
".",
"inputs",
".",
"add",
"(",
"a",
".",
"word",
")",
";",
"}",
"t",
"=",
"t",
".",
"next",
";",
"if",
"(",
"t",
"==",
"null",
"||",
"t",
".",
"getSymbol",
"(",
")",
"!=",
"Symbol",
".",
"ASSIGN",
")",
"throw",
"new",
"ParseError",
"(",
"\"Expected assignment\"",
")",
";",
"t",
"=",
"t",
".",
"next",
";",
"macro",
".",
"tokens",
"=",
"new",
"TokenList",
"(",
"t",
",",
"tokens",
".",
"last",
")",
";",
"sequence",
".",
"addOperation",
"(",
"macro",
".",
"createOperation",
"(",
"macros",
")",
")",
";",
"}"
] |
Parse a macro defintion.
"macro NAME( var0 , var1 ) = 5+var0+var1'
|
[
"Parse",
"a",
"macro",
"defintion",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L518-L542
|
162,484 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.checkForUnknownVariables
|
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;
}
}
|
java
|
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;
}
}
|
[
"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
|
[
"Examines",
"the",
"list",
"of",
"variables",
"for",
"any",
"unknown",
"variables",
"and",
"throws",
"an",
"exception",
"if",
"one",
"is",
"found"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L571-L578
|
162,485 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.createVariableInferred
|
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 VariableInteger) {
alias(0,t0.getWord());
} else {
alias(1.0,t0.getWord());
}
break;
case INTEGER_SEQUENCE:
alias((IntegerSequence)null,t0.getWord());
break;
default:
throw new RuntimeException("Type not supported for assignment: "+variableRight.getType());
}
result = variables.get(t0.getWord());
} else {
result = t0.getVariable();
}
return result;
}
|
java
|
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 VariableInteger) {
alias(0,t0.getWord());
} else {
alias(1.0,t0.getWord());
}
break;
case INTEGER_SEQUENCE:
alias((IntegerSequence)null,t0.getWord());
break;
default:
throw new RuntimeException("Type not supported for assignment: "+variableRight.getType());
}
result = variables.get(t0.getWord());
} else {
result = t0.getVariable();
}
return result;
}
|
[
"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",
"VariableInteger",
")",
"{",
"alias",
"(",
"0",
",",
"t0",
".",
"getWord",
"(",
")",
")",
";",
"}",
"else",
"{",
"alias",
"(",
"1.0",
",",
"t0",
".",
"getWord",
"(",
")",
")",
";",
"}",
"break",
";",
"case",
"INTEGER_SEQUENCE",
":",
"alias",
"(",
"(",
"IntegerSequence",
")",
"null",
",",
"t0",
".",
"getWord",
"(",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"Type not supported for assignment: \"",
"+",
"variableRight",
".",
"getType",
"(",
")",
")",
";",
"}",
"result",
"=",
"variables",
".",
"get",
"(",
"t0",
".",
"getWord",
"(",
")",
")",
";",
"}",
"else",
"{",
"result",
"=",
"t0",
".",
"getVariable",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
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.
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L584-L614
|
162,486 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseAssignRange
|
private List<Variable> parseAssignRange(Sequence sequence, TokenList tokens, TokenList.Token t0) {
// find assignment symbol
TokenList.Token tokenAssign = t0.next;
while( tokenAssign != null && tokenAssign.symbol != Symbol.ASSIGN ) {
tokenAssign = tokenAssign.next;
}
if( tokenAssign == null )
throw new ParseError("Can't find assignment operator");
// see if it is a sub matrix before
if( tokenAssign.previous.symbol == Symbol.PAREN_RIGHT ) {
TokenList.Token start = t0.next;
if( start.symbol != Symbol.PAREN_LEFT )
throw new ParseError(("Expected left param for assignment"));
TokenList.Token end = tokenAssign.previous;
TokenList subTokens = tokens.extractSubList(start,end);
subTokens.remove(subTokens.getFirst());
subTokens.remove(subTokens.getLast());
handleParentheses(subTokens,sequence);
List<TokenList.Token> inputs = parseParameterCommaBlock(subTokens, sequence);
if (inputs.isEmpty())
throw new ParseError("Empty function input parameters");
List<Variable> range = new ArrayList<>();
addSubMatrixVariables(inputs, range);
if( range.size() != 1 && range.size() != 2 ) {
throw new ParseError("Unexpected number of range variables. 1 or 2 expected");
}
return range;
}
return null;
}
|
java
|
private List<Variable> parseAssignRange(Sequence sequence, TokenList tokens, TokenList.Token t0) {
// find assignment symbol
TokenList.Token tokenAssign = t0.next;
while( tokenAssign != null && tokenAssign.symbol != Symbol.ASSIGN ) {
tokenAssign = tokenAssign.next;
}
if( tokenAssign == null )
throw new ParseError("Can't find assignment operator");
// see if it is a sub matrix before
if( tokenAssign.previous.symbol == Symbol.PAREN_RIGHT ) {
TokenList.Token start = t0.next;
if( start.symbol != Symbol.PAREN_LEFT )
throw new ParseError(("Expected left param for assignment"));
TokenList.Token end = tokenAssign.previous;
TokenList subTokens = tokens.extractSubList(start,end);
subTokens.remove(subTokens.getFirst());
subTokens.remove(subTokens.getLast());
handleParentheses(subTokens,sequence);
List<TokenList.Token> inputs = parseParameterCommaBlock(subTokens, sequence);
if (inputs.isEmpty())
throw new ParseError("Empty function input parameters");
List<Variable> range = new ArrayList<>();
addSubMatrixVariables(inputs, range);
if( range.size() != 1 && range.size() != 2 ) {
throw new ParseError("Unexpected number of range variables. 1 or 2 expected");
}
return range;
}
return null;
}
|
[
"private",
"List",
"<",
"Variable",
">",
"parseAssignRange",
"(",
"Sequence",
"sequence",
",",
"TokenList",
"tokens",
",",
"TokenList",
".",
"Token",
"t0",
")",
"{",
"// find assignment symbol",
"TokenList",
".",
"Token",
"tokenAssign",
"=",
"t0",
".",
"next",
";",
"while",
"(",
"tokenAssign",
"!=",
"null",
"&&",
"tokenAssign",
".",
"symbol",
"!=",
"Symbol",
".",
"ASSIGN",
")",
"{",
"tokenAssign",
"=",
"tokenAssign",
".",
"next",
";",
"}",
"if",
"(",
"tokenAssign",
"==",
"null",
")",
"throw",
"new",
"ParseError",
"(",
"\"Can't find assignment operator\"",
")",
";",
"// see if it is a sub matrix before",
"if",
"(",
"tokenAssign",
".",
"previous",
".",
"symbol",
"==",
"Symbol",
".",
"PAREN_RIGHT",
")",
"{",
"TokenList",
".",
"Token",
"start",
"=",
"t0",
".",
"next",
";",
"if",
"(",
"start",
".",
"symbol",
"!=",
"Symbol",
".",
"PAREN_LEFT",
")",
"throw",
"new",
"ParseError",
"(",
"(",
"\"Expected left param for assignment\"",
")",
")",
";",
"TokenList",
".",
"Token",
"end",
"=",
"tokenAssign",
".",
"previous",
";",
"TokenList",
"subTokens",
"=",
"tokens",
".",
"extractSubList",
"(",
"start",
",",
"end",
")",
";",
"subTokens",
".",
"remove",
"(",
"subTokens",
".",
"getFirst",
"(",
")",
")",
";",
"subTokens",
".",
"remove",
"(",
"subTokens",
".",
"getLast",
"(",
")",
")",
";",
"handleParentheses",
"(",
"subTokens",
",",
"sequence",
")",
";",
"List",
"<",
"TokenList",
".",
"Token",
">",
"inputs",
"=",
"parseParameterCommaBlock",
"(",
"subTokens",
",",
"sequence",
")",
";",
"if",
"(",
"inputs",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"ParseError",
"(",
"\"Empty function input parameters\"",
")",
";",
"List",
"<",
"Variable",
">",
"range",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"addSubMatrixVariables",
"(",
"inputs",
",",
"range",
")",
";",
"if",
"(",
"range",
".",
"size",
"(",
")",
"!=",
"1",
"&&",
"range",
".",
"size",
"(",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Unexpected number of range variables. 1 or 2 expected\"",
")",
";",
"}",
"return",
"range",
";",
"}",
"return",
"null",
";",
"}"
] |
See if a range for assignment is specified. If so return the range, otherwise return null
Example of assign range:
a(0:3,4:5) = blah
a((0+2):3,4:5) = blah
|
[
"See",
"if",
"a",
"range",
"for",
"assignment",
"is",
"specified",
".",
"If",
"so",
"return",
"the",
"range",
"otherwise",
"return",
"null"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L623-L659
|
162,487 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.handleParentheses
|
protected void handleParentheses( TokenList tokens, Sequence sequence ) {
// have a list to handle embedded parentheses, e.g. (((((a)))))
List<TokenList.Token> left = new ArrayList<TokenList.Token>();
// find all of them
TokenList.Token t = tokens.first;
while( t != null ) {
TokenList.Token next = t.next;
if( t.getType() == Type.SYMBOL ) {
if( t.getSymbol() == Symbol.PAREN_LEFT )
left.add(t);
else if( t.getSymbol() == Symbol.PAREN_RIGHT ) {
if( left.isEmpty() )
throw new ParseError(") found with no matching (");
TokenList.Token a = left.remove(left.size()-1);
// remember the element before so the new one can be inserted afterwards
TokenList.Token before = a.previous;
TokenList sublist = tokens.extractSubList(a,t);
// remove parentheses
sublist.remove(sublist.first);
sublist.remove(sublist.last);
// if its a function before () then the () indicates its an input to a function
if( before != null && before.getType() == Type.FUNCTION ) {
List<TokenList.Token> inputs = parseParameterCommaBlock(sublist, sequence);
if (inputs.isEmpty())
throw new ParseError("Empty function input parameters");
else {
createFunction(before, inputs, tokens, sequence);
}
} else if( before != null && before.getType() == Type.VARIABLE &&
before.getVariable().getType() == VariableType.MATRIX ) {
// if it's a variable then that says it's a sub-matrix
TokenList.Token extract = parseSubmatrixToExtract(before,sublist, sequence);
// put in the extract operation
tokens.insert(before,extract);
tokens.remove(before);
} else {
// if null then it was empty inside
TokenList.Token output = parseBlockNoParentheses(sublist,sequence, false);
if (output != null)
tokens.insert(before, output);
}
}
}
t = next;
}
if( !left.isEmpty())
throw new ParseError("Dangling ( parentheses");
}
|
java
|
protected void handleParentheses( TokenList tokens, Sequence sequence ) {
// have a list to handle embedded parentheses, e.g. (((((a)))))
List<TokenList.Token> left = new ArrayList<TokenList.Token>();
// find all of them
TokenList.Token t = tokens.first;
while( t != null ) {
TokenList.Token next = t.next;
if( t.getType() == Type.SYMBOL ) {
if( t.getSymbol() == Symbol.PAREN_LEFT )
left.add(t);
else if( t.getSymbol() == Symbol.PAREN_RIGHT ) {
if( left.isEmpty() )
throw new ParseError(") found with no matching (");
TokenList.Token a = left.remove(left.size()-1);
// remember the element before so the new one can be inserted afterwards
TokenList.Token before = a.previous;
TokenList sublist = tokens.extractSubList(a,t);
// remove parentheses
sublist.remove(sublist.first);
sublist.remove(sublist.last);
// if its a function before () then the () indicates its an input to a function
if( before != null && before.getType() == Type.FUNCTION ) {
List<TokenList.Token> inputs = parseParameterCommaBlock(sublist, sequence);
if (inputs.isEmpty())
throw new ParseError("Empty function input parameters");
else {
createFunction(before, inputs, tokens, sequence);
}
} else if( before != null && before.getType() == Type.VARIABLE &&
before.getVariable().getType() == VariableType.MATRIX ) {
// if it's a variable then that says it's a sub-matrix
TokenList.Token extract = parseSubmatrixToExtract(before,sublist, sequence);
// put in the extract operation
tokens.insert(before,extract);
tokens.remove(before);
} else {
// if null then it was empty inside
TokenList.Token output = parseBlockNoParentheses(sublist,sequence, false);
if (output != null)
tokens.insert(before, output);
}
}
}
t = next;
}
if( !left.isEmpty())
throw new ParseError("Dangling ( parentheses");
}
|
[
"protected",
"void",
"handleParentheses",
"(",
"TokenList",
"tokens",
",",
"Sequence",
"sequence",
")",
"{",
"// have a list to handle embedded parentheses, e.g. (((((a)))))",
"List",
"<",
"TokenList",
".",
"Token",
">",
"left",
"=",
"new",
"ArrayList",
"<",
"TokenList",
".",
"Token",
">",
"(",
")",
";",
"// find all of them",
"TokenList",
".",
"Token",
"t",
"=",
"tokens",
".",
"first",
";",
"while",
"(",
"t",
"!=",
"null",
")",
"{",
"TokenList",
".",
"Token",
"next",
"=",
"t",
".",
"next",
";",
"if",
"(",
"t",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
")",
"{",
"if",
"(",
"t",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"PAREN_LEFT",
")",
"left",
".",
"add",
"(",
"t",
")",
";",
"else",
"if",
"(",
"t",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"PAREN_RIGHT",
")",
"{",
"if",
"(",
"left",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"ParseError",
"(",
"\") found with no matching (\"",
")",
";",
"TokenList",
".",
"Token",
"a",
"=",
"left",
".",
"remove",
"(",
"left",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"// remember the element before so the new one can be inserted afterwards",
"TokenList",
".",
"Token",
"before",
"=",
"a",
".",
"previous",
";",
"TokenList",
"sublist",
"=",
"tokens",
".",
"extractSubList",
"(",
"a",
",",
"t",
")",
";",
"// remove parentheses",
"sublist",
".",
"remove",
"(",
"sublist",
".",
"first",
")",
";",
"sublist",
".",
"remove",
"(",
"sublist",
".",
"last",
")",
";",
"// if its a function before () then the () indicates its an input to a function",
"if",
"(",
"before",
"!=",
"null",
"&&",
"before",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"FUNCTION",
")",
"{",
"List",
"<",
"TokenList",
".",
"Token",
">",
"inputs",
"=",
"parseParameterCommaBlock",
"(",
"sublist",
",",
"sequence",
")",
";",
"if",
"(",
"inputs",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"ParseError",
"(",
"\"Empty function input parameters\"",
")",
";",
"else",
"{",
"createFunction",
"(",
"before",
",",
"inputs",
",",
"tokens",
",",
"sequence",
")",
";",
"}",
"}",
"else",
"if",
"(",
"before",
"!=",
"null",
"&&",
"before",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"VARIABLE",
"&&",
"before",
".",
"getVariable",
"(",
")",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"MATRIX",
")",
"{",
"// if it's a variable then that says it's a sub-matrix",
"TokenList",
".",
"Token",
"extract",
"=",
"parseSubmatrixToExtract",
"(",
"before",
",",
"sublist",
",",
"sequence",
")",
";",
"// put in the extract operation",
"tokens",
".",
"insert",
"(",
"before",
",",
"extract",
")",
";",
"tokens",
".",
"remove",
"(",
"before",
")",
";",
"}",
"else",
"{",
"// if null then it was empty inside",
"TokenList",
".",
"Token",
"output",
"=",
"parseBlockNoParentheses",
"(",
"sublist",
",",
"sequence",
",",
"false",
")",
";",
"if",
"(",
"output",
"!=",
"null",
")",
"tokens",
".",
"insert",
"(",
"before",
",",
"output",
")",
";",
"}",
"}",
"}",
"t",
"=",
"next",
";",
"}",
"if",
"(",
"!",
"left",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"ParseError",
"(",
"\"Dangling ( parentheses\"",
")",
";",
"}"
] |
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.
@param tokens List of parsed tokens
@param sequence Sequence of operators
|
[
"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",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L667-L720
|
162,488 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseParameterCommaBlock
|
protected List<TokenList.Token> parseParameterCommaBlock( TokenList tokens, Sequence sequence ) {
// find all the comma tokens
List<TokenList.Token> commas = new ArrayList<TokenList.Token>();
TokenList.Token token = tokens.first;
int numBracket = 0;
while( token != null ) {
if( token.getType() == Type.SYMBOL ) {
switch( token.getSymbol() ) {
case COMMA:
if( numBracket == 0)
commas.add(token);
break;
case BRACKET_LEFT: numBracket++; break;
case BRACKET_RIGHT: numBracket--; break;
}
}
token = token.next;
}
List<TokenList.Token> output = new ArrayList<TokenList.Token>();
if( commas.isEmpty() ) {
output.add(parseBlockNoParentheses(tokens, sequence, false));
} else {
TokenList.Token before = tokens.first;
for (int i = 0; i < commas.size(); i++) {
TokenList.Token after = commas.get(i);
if( before == after )
throw new ParseError("No empty function inputs allowed!");
TokenList.Token tmp = after.next;
TokenList sublist = tokens.extractSubList(before,after);
sublist.remove(after);// remove the comma
output.add(parseBlockNoParentheses(sublist, sequence, false));
before = tmp;
}
// if the last character is a comma then after.next above will be null and thus before is null
if( before == null )
throw new ParseError("No empty function inputs allowed!");
TokenList.Token after = tokens.last;
TokenList sublist = tokens.extractSubList(before, after);
output.add(parseBlockNoParentheses(sublist, sequence, false));
}
return output;
}
|
java
|
protected List<TokenList.Token> parseParameterCommaBlock( TokenList tokens, Sequence sequence ) {
// find all the comma tokens
List<TokenList.Token> commas = new ArrayList<TokenList.Token>();
TokenList.Token token = tokens.first;
int numBracket = 0;
while( token != null ) {
if( token.getType() == Type.SYMBOL ) {
switch( token.getSymbol() ) {
case COMMA:
if( numBracket == 0)
commas.add(token);
break;
case BRACKET_LEFT: numBracket++; break;
case BRACKET_RIGHT: numBracket--; break;
}
}
token = token.next;
}
List<TokenList.Token> output = new ArrayList<TokenList.Token>();
if( commas.isEmpty() ) {
output.add(parseBlockNoParentheses(tokens, sequence, false));
} else {
TokenList.Token before = tokens.first;
for (int i = 0; i < commas.size(); i++) {
TokenList.Token after = commas.get(i);
if( before == after )
throw new ParseError("No empty function inputs allowed!");
TokenList.Token tmp = after.next;
TokenList sublist = tokens.extractSubList(before,after);
sublist.remove(after);// remove the comma
output.add(parseBlockNoParentheses(sublist, sequence, false));
before = tmp;
}
// if the last character is a comma then after.next above will be null and thus before is null
if( before == null )
throw new ParseError("No empty function inputs allowed!");
TokenList.Token after = tokens.last;
TokenList sublist = tokens.extractSubList(before, after);
output.add(parseBlockNoParentheses(sublist, sequence, false));
}
return output;
}
|
[
"protected",
"List",
"<",
"TokenList",
".",
"Token",
">",
"parseParameterCommaBlock",
"(",
"TokenList",
"tokens",
",",
"Sequence",
"sequence",
")",
"{",
"// find all the comma tokens",
"List",
"<",
"TokenList",
".",
"Token",
">",
"commas",
"=",
"new",
"ArrayList",
"<",
"TokenList",
".",
"Token",
">",
"(",
")",
";",
"TokenList",
".",
"Token",
"token",
"=",
"tokens",
".",
"first",
";",
"int",
"numBracket",
"=",
"0",
";",
"while",
"(",
"token",
"!=",
"null",
")",
"{",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
")",
"{",
"switch",
"(",
"token",
".",
"getSymbol",
"(",
")",
")",
"{",
"case",
"COMMA",
":",
"if",
"(",
"numBracket",
"==",
"0",
")",
"commas",
".",
"add",
"(",
"token",
")",
";",
"break",
";",
"case",
"BRACKET_LEFT",
":",
"numBracket",
"++",
";",
"break",
";",
"case",
"BRACKET_RIGHT",
":",
"numBracket",
"--",
";",
"break",
";",
"}",
"}",
"token",
"=",
"token",
".",
"next",
";",
"}",
"List",
"<",
"TokenList",
".",
"Token",
">",
"output",
"=",
"new",
"ArrayList",
"<",
"TokenList",
".",
"Token",
">",
"(",
")",
";",
"if",
"(",
"commas",
".",
"isEmpty",
"(",
")",
")",
"{",
"output",
".",
"add",
"(",
"parseBlockNoParentheses",
"(",
"tokens",
",",
"sequence",
",",
"false",
")",
")",
";",
"}",
"else",
"{",
"TokenList",
".",
"Token",
"before",
"=",
"tokens",
".",
"first",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"commas",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"TokenList",
".",
"Token",
"after",
"=",
"commas",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"before",
"==",
"after",
")",
"throw",
"new",
"ParseError",
"(",
"\"No empty function inputs allowed!\"",
")",
";",
"TokenList",
".",
"Token",
"tmp",
"=",
"after",
".",
"next",
";",
"TokenList",
"sublist",
"=",
"tokens",
".",
"extractSubList",
"(",
"before",
",",
"after",
")",
";",
"sublist",
".",
"remove",
"(",
"after",
")",
";",
"// remove the comma",
"output",
".",
"add",
"(",
"parseBlockNoParentheses",
"(",
"sublist",
",",
"sequence",
",",
"false",
")",
")",
";",
"before",
"=",
"tmp",
";",
"}",
"// if the last character is a comma then after.next above will be null and thus before is null",
"if",
"(",
"before",
"==",
"null",
")",
"throw",
"new",
"ParseError",
"(",
"\"No empty function inputs allowed!\"",
")",
";",
"TokenList",
".",
"Token",
"after",
"=",
"tokens",
".",
"last",
";",
"TokenList",
"sublist",
"=",
"tokens",
".",
"extractSubList",
"(",
"before",
",",
"after",
")",
";",
"output",
".",
"add",
"(",
"parseBlockNoParentheses",
"(",
"sublist",
",",
"sequence",
",",
"false",
")",
")",
";",
"}",
"return",
"output",
";",
"}"
] |
Searches for commas in the set of tokens. Used for inputs to functions.
Ignore comma's which are inside a [ ] block
@return List of output tokens between the commas
|
[
"Searches",
"for",
"commas",
"in",
"the",
"set",
"of",
"tokens",
".",
"Used",
"for",
"inputs",
"to",
"functions",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L729-L776
|
162,489 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseSubmatrixToExtract
|
protected TokenList.Token parseSubmatrixToExtract(TokenList.Token variableTarget,
TokenList tokens, Sequence sequence) {
List<TokenList.Token> inputs = parseParameterCommaBlock(tokens, sequence);
List<Variable> variables = new ArrayList<Variable>();
// for the operation, the first variable must be the matrix which is being manipulated
variables.add(variableTarget.getVariable());
addSubMatrixVariables(inputs, variables);
if( variables.size() != 2 && variables.size() != 3 ) {
throw new ParseError("Unexpected number of variables. 1 or 2 expected");
}
// first parameter is the matrix it will be extracted from. rest specify range
Operation.Info info;
// only one variable means its referencing elements
// two variables means its referencing a sub matrix
if( inputs.size() == 1 ) {
Variable varA = variables.get(1);
if( varA.getType() == VariableType.SCALAR ) {
info = functions.create("extractScalar", variables);
} else {
info = functions.create("extract", variables);
}
} else if( inputs.size() == 2 ) {
Variable varA = variables.get(1);
Variable varB = variables.get(2);
if( varA.getType() == VariableType.SCALAR && varB.getType() == VariableType.SCALAR) {
info = functions.create("extractScalar", variables);
} else {
info = functions.create("extract", variables);
}
} else {
throw new ParseError("Expected 2 inputs to sub-matrix");
}
sequence.addOperation(info.op);
return new TokenList.Token(info.output);
}
|
java
|
protected TokenList.Token parseSubmatrixToExtract(TokenList.Token variableTarget,
TokenList tokens, Sequence sequence) {
List<TokenList.Token> inputs = parseParameterCommaBlock(tokens, sequence);
List<Variable> variables = new ArrayList<Variable>();
// for the operation, the first variable must be the matrix which is being manipulated
variables.add(variableTarget.getVariable());
addSubMatrixVariables(inputs, variables);
if( variables.size() != 2 && variables.size() != 3 ) {
throw new ParseError("Unexpected number of variables. 1 or 2 expected");
}
// first parameter is the matrix it will be extracted from. rest specify range
Operation.Info info;
// only one variable means its referencing elements
// two variables means its referencing a sub matrix
if( inputs.size() == 1 ) {
Variable varA = variables.get(1);
if( varA.getType() == VariableType.SCALAR ) {
info = functions.create("extractScalar", variables);
} else {
info = functions.create("extract", variables);
}
} else if( inputs.size() == 2 ) {
Variable varA = variables.get(1);
Variable varB = variables.get(2);
if( varA.getType() == VariableType.SCALAR && varB.getType() == VariableType.SCALAR) {
info = functions.create("extractScalar", variables);
} else {
info = functions.create("extract", variables);
}
} else {
throw new ParseError("Expected 2 inputs to sub-matrix");
}
sequence.addOperation(info.op);
return new TokenList.Token(info.output);
}
|
[
"protected",
"TokenList",
".",
"Token",
"parseSubmatrixToExtract",
"(",
"TokenList",
".",
"Token",
"variableTarget",
",",
"TokenList",
"tokens",
",",
"Sequence",
"sequence",
")",
"{",
"List",
"<",
"TokenList",
".",
"Token",
">",
"inputs",
"=",
"parseParameterCommaBlock",
"(",
"tokens",
",",
"sequence",
")",
";",
"List",
"<",
"Variable",
">",
"variables",
"=",
"new",
"ArrayList",
"<",
"Variable",
">",
"(",
")",
";",
"// for the operation, the first variable must be the matrix which is being manipulated",
"variables",
".",
"add",
"(",
"variableTarget",
".",
"getVariable",
"(",
")",
")",
";",
"addSubMatrixVariables",
"(",
"inputs",
",",
"variables",
")",
";",
"if",
"(",
"variables",
".",
"size",
"(",
")",
"!=",
"2",
"&&",
"variables",
".",
"size",
"(",
")",
"!=",
"3",
")",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Unexpected number of variables. 1 or 2 expected\"",
")",
";",
"}",
"// first parameter is the matrix it will be extracted from. rest specify range",
"Operation",
".",
"Info",
"info",
";",
"// only one variable means its referencing elements",
"// two variables means its referencing a sub matrix",
"if",
"(",
"inputs",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"Variable",
"varA",
"=",
"variables",
".",
"get",
"(",
"1",
")",
";",
"if",
"(",
"varA",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"SCALAR",
")",
"{",
"info",
"=",
"functions",
".",
"create",
"(",
"\"extractScalar\"",
",",
"variables",
")",
";",
"}",
"else",
"{",
"info",
"=",
"functions",
".",
"create",
"(",
"\"extract\"",
",",
"variables",
")",
";",
"}",
"}",
"else",
"if",
"(",
"inputs",
".",
"size",
"(",
")",
"==",
"2",
")",
"{",
"Variable",
"varA",
"=",
"variables",
".",
"get",
"(",
"1",
")",
";",
"Variable",
"varB",
"=",
"variables",
".",
"get",
"(",
"2",
")",
";",
"if",
"(",
"varA",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"SCALAR",
"&&",
"varB",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"SCALAR",
")",
"{",
"info",
"=",
"functions",
".",
"create",
"(",
"\"extractScalar\"",
",",
"variables",
")",
";",
"}",
"else",
"{",
"info",
"=",
"functions",
".",
"create",
"(",
"\"extract\"",
",",
"variables",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Expected 2 inputs to sub-matrix\"",
")",
";",
"}",
"sequence",
".",
"addOperation",
"(",
"info",
".",
"op",
")",
";",
"return",
"new",
"TokenList",
".",
"Token",
"(",
"info",
".",
"output",
")",
";",
"}"
] |
Converts a submatrix into an extract matrix operation.
@param variableTarget The variable in which the submatrix is extracted from
|
[
"Converts",
"a",
"submatrix",
"into",
"an",
"extract",
"matrix",
"operation",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L782-L826
|
162,490 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.addSubMatrixVariables
|
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.getType());
Variable v = t.getVariable();
if( v.getType() == VariableType.INTEGER_SEQUENCE || isVariableInteger(t) ) {
variables.add(v);
} else {
throw new ParseError("Expected an integer, integer sequence, or array range to define a submatrix");
}
}
}
|
java
|
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.getType());
Variable v = t.getVariable();
if( v.getType() == VariableType.INTEGER_SEQUENCE || isVariableInteger(t) ) {
variables.add(v);
} else {
throw new ParseError("Expected an integer, integer sequence, or array range to define a submatrix");
}
}
}
|
[
"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",
".",
"getType",
"(",
")",
")",
";",
"Variable",
"v",
"=",
"t",
".",
"getVariable",
"(",
")",
";",
"if",
"(",
"v",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"INTEGER_SEQUENCE",
"||",
"isVariableInteger",
"(",
"t",
")",
")",
"{",
"variables",
".",
"add",
"(",
"v",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Expected an integer, integer sequence, or array range to define a submatrix\"",
")",
";",
"}",
"}",
"}"
] |
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
|
[
"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"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L832-L844
|
162,491 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseBlockNoParentheses
|
protected TokenList.Token parseBlockNoParentheses(TokenList tokens, Sequence sequence, boolean insideMatrixConstructor) {
// search for matrix bracket operations
if( !insideMatrixConstructor ) {
parseBracketCreateMatrix(tokens, sequence);
}
// First create sequences from anything involving a colon
parseSequencesWithColons(tokens, sequence );
// process operators depending on their priority
parseNegOp(tokens, sequence);
parseOperationsL(tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.POWER, Symbol.ELEMENT_POWER}, tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.TIMES, Symbol.RDIVIDE, Symbol.LDIVIDE, Symbol.ELEMENT_TIMES, Symbol.ELEMENT_DIVIDE}, tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.PLUS, Symbol.MINUS}, tokens, sequence);
// Commas are used in integer sequences. Can be used to force to compiler to treat - as negative not
// minus. They can now be removed since they have served their purpose
stripCommas(tokens);
// now construct rest of the lists and combine them together
parseIntegerLists(tokens);
parseCombineIntegerLists(tokens);
if( !insideMatrixConstructor ) {
if (tokens.size() > 1) {
System.err.println("Remaining tokens: "+tokens.size);
TokenList.Token t = tokens.first;
while( t != null ) {
System.err.println(" "+t);
t = t.next;
}
throw new RuntimeException("BUG in parser. There should only be a single token left");
}
return tokens.first;
} else {
return null;
}
}
|
java
|
protected TokenList.Token parseBlockNoParentheses(TokenList tokens, Sequence sequence, boolean insideMatrixConstructor) {
// search for matrix bracket operations
if( !insideMatrixConstructor ) {
parseBracketCreateMatrix(tokens, sequence);
}
// First create sequences from anything involving a colon
parseSequencesWithColons(tokens, sequence );
// process operators depending on their priority
parseNegOp(tokens, sequence);
parseOperationsL(tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.POWER, Symbol.ELEMENT_POWER}, tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.TIMES, Symbol.RDIVIDE, Symbol.LDIVIDE, Symbol.ELEMENT_TIMES, Symbol.ELEMENT_DIVIDE}, tokens, sequence);
parseOperationsLR(new Symbol[]{Symbol.PLUS, Symbol.MINUS}, tokens, sequence);
// Commas are used in integer sequences. Can be used to force to compiler to treat - as negative not
// minus. They can now be removed since they have served their purpose
stripCommas(tokens);
// now construct rest of the lists and combine them together
parseIntegerLists(tokens);
parseCombineIntegerLists(tokens);
if( !insideMatrixConstructor ) {
if (tokens.size() > 1) {
System.err.println("Remaining tokens: "+tokens.size);
TokenList.Token t = tokens.first;
while( t != null ) {
System.err.println(" "+t);
t = t.next;
}
throw new RuntimeException("BUG in parser. There should only be a single token left");
}
return tokens.first;
} else {
return null;
}
}
|
[
"protected",
"TokenList",
".",
"Token",
"parseBlockNoParentheses",
"(",
"TokenList",
"tokens",
",",
"Sequence",
"sequence",
",",
"boolean",
"insideMatrixConstructor",
")",
"{",
"// search for matrix bracket operations",
"if",
"(",
"!",
"insideMatrixConstructor",
")",
"{",
"parseBracketCreateMatrix",
"(",
"tokens",
",",
"sequence",
")",
";",
"}",
"// First create sequences from anything involving a colon",
"parseSequencesWithColons",
"(",
"tokens",
",",
"sequence",
")",
";",
"// process operators depending on their priority",
"parseNegOp",
"(",
"tokens",
",",
"sequence",
")",
";",
"parseOperationsL",
"(",
"tokens",
",",
"sequence",
")",
";",
"parseOperationsLR",
"(",
"new",
"Symbol",
"[",
"]",
"{",
"Symbol",
".",
"POWER",
",",
"Symbol",
".",
"ELEMENT_POWER",
"}",
",",
"tokens",
",",
"sequence",
")",
";",
"parseOperationsLR",
"(",
"new",
"Symbol",
"[",
"]",
"{",
"Symbol",
".",
"TIMES",
",",
"Symbol",
".",
"RDIVIDE",
",",
"Symbol",
".",
"LDIVIDE",
",",
"Symbol",
".",
"ELEMENT_TIMES",
",",
"Symbol",
".",
"ELEMENT_DIVIDE",
"}",
",",
"tokens",
",",
"sequence",
")",
";",
"parseOperationsLR",
"(",
"new",
"Symbol",
"[",
"]",
"{",
"Symbol",
".",
"PLUS",
",",
"Symbol",
".",
"MINUS",
"}",
",",
"tokens",
",",
"sequence",
")",
";",
"// Commas are used in integer sequences. Can be used to force to compiler to treat - as negative not",
"// minus. They can now be removed since they have served their purpose",
"stripCommas",
"(",
"tokens",
")",
";",
"// now construct rest of the lists and combine them together",
"parseIntegerLists",
"(",
"tokens",
")",
";",
"parseCombineIntegerLists",
"(",
"tokens",
")",
";",
"if",
"(",
"!",
"insideMatrixConstructor",
")",
"{",
"if",
"(",
"tokens",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"Remaining tokens: \"",
"+",
"tokens",
".",
"size",
")",
";",
"TokenList",
".",
"Token",
"t",
"=",
"tokens",
".",
"first",
";",
"while",
"(",
"t",
"!=",
"null",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\" \"",
"+",
"t",
")",
";",
"t",
"=",
"t",
".",
"next",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"BUG in parser. There should only be a single token left\"",
")",
";",
"}",
"return",
"tokens",
".",
"first",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Parses a code block with no parentheses and no commas. After it is done there should be a single token left,
which is returned.
|
[
"Parses",
"a",
"code",
"block",
"with",
"no",
"parentheses",
"and",
"no",
"commas",
".",
"After",
"it",
"is",
"done",
"there",
"should",
"be",
"a",
"single",
"token",
"left",
"which",
"is",
"returned",
"."
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L850-L889
|
162,492 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.stripCommas
|
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;
}
}
|
java
|
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;
}
}
|
[
"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
|
[
"Removes",
"all",
"commas",
"from",
"the",
"token",
"list"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L894-L904
|
162,493 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseSequencesWithColons
|
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 == 0 ) {
if( isVariableInteger(t) && (t.next != null && t.next.getSymbol() == Symbol.COLON) ) {
start = t;
state = 1;
t = t.next;
} else if( t != null && t.getSymbol() == Symbol.COLON ) {
// If it starts with a colon then it must be 'all' or a type-o
IntegerSequence range = new IntegerSequence.Range(null,null);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(range);
TokenList.Token n = new TokenList.Token(varSequence);
tokens.insert(t.previous, n);
tokens.remove(t);
t = n;
}
} else if( state == 1 ) {
// var : ?
if (isVariableInteger(t)) {
state = 2;
} else {
// array range
IntegerSequence range = new IntegerSequence.Range(start,null);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(range);
replaceSequence(tokens, varSequence, start, prev);
state = 0;
}
} else if ( state == 2 ) {
// var:var ?
if( t != null && t.getSymbol() == Symbol.COLON ) {
middle = prev;
state = 3;
} else {
// create for sequence with start and stop elements only
IntegerSequence numbers = new IntegerSequence.For(start,null,prev);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
replaceSequence(tokens, varSequence, start, prev );
if( t != null )
t = t.previous;
state = 0;
}
} else if ( state == 3 ) {
// var:var: ?
if( isVariableInteger(t) ) {
// create 'for' sequence with three variables
IntegerSequence numbers = new IntegerSequence.For(start,middle,t);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
t = replaceSequence(tokens, varSequence, start, t);
} else {
// array range with 2 elements
IntegerSequence numbers = new IntegerSequence.Range(start,middle);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
replaceSequence(tokens, varSequence, start, prev);
}
state = 0;
}
if( last ) {
break;
} else if( t.next == null ) {
// handle the case where it is the last token in the sequence
last = true;
}
prev = t;
t = t.next;
}
}
|
java
|
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 == 0 ) {
if( isVariableInteger(t) && (t.next != null && t.next.getSymbol() == Symbol.COLON) ) {
start = t;
state = 1;
t = t.next;
} else if( t != null && t.getSymbol() == Symbol.COLON ) {
// If it starts with a colon then it must be 'all' or a type-o
IntegerSequence range = new IntegerSequence.Range(null,null);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(range);
TokenList.Token n = new TokenList.Token(varSequence);
tokens.insert(t.previous, n);
tokens.remove(t);
t = n;
}
} else if( state == 1 ) {
// var : ?
if (isVariableInteger(t)) {
state = 2;
} else {
// array range
IntegerSequence range = new IntegerSequence.Range(start,null);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(range);
replaceSequence(tokens, varSequence, start, prev);
state = 0;
}
} else if ( state == 2 ) {
// var:var ?
if( t != null && t.getSymbol() == Symbol.COLON ) {
middle = prev;
state = 3;
} else {
// create for sequence with start and stop elements only
IntegerSequence numbers = new IntegerSequence.For(start,null,prev);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
replaceSequence(tokens, varSequence, start, prev );
if( t != null )
t = t.previous;
state = 0;
}
} else if ( state == 3 ) {
// var:var: ?
if( isVariableInteger(t) ) {
// create 'for' sequence with three variables
IntegerSequence numbers = new IntegerSequence.For(start,middle,t);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
t = replaceSequence(tokens, varSequence, start, t);
} else {
// array range with 2 elements
IntegerSequence numbers = new IntegerSequence.Range(start,middle);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(numbers);
replaceSequence(tokens, varSequence, start, prev);
}
state = 0;
}
if( last ) {
break;
} else if( t.next == null ) {
// handle the case where it is the last token in the sequence
last = true;
}
prev = t;
t = t.next;
}
}
|
[
"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",
"==",
"0",
")",
"{",
"if",
"(",
"isVariableInteger",
"(",
"t",
")",
"&&",
"(",
"t",
".",
"next",
"!=",
"null",
"&&",
"t",
".",
"next",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"COLON",
")",
")",
"{",
"start",
"=",
"t",
";",
"state",
"=",
"1",
";",
"t",
"=",
"t",
".",
"next",
";",
"}",
"else",
"if",
"(",
"t",
"!=",
"null",
"&&",
"t",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"COLON",
")",
"{",
"// If it starts with a colon then it must be 'all' or a type-o",
"IntegerSequence",
"range",
"=",
"new",
"IntegerSequence",
".",
"Range",
"(",
"null",
",",
"null",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"range",
")",
";",
"TokenList",
".",
"Token",
"n",
"=",
"new",
"TokenList",
".",
"Token",
"(",
"varSequence",
")",
";",
"tokens",
".",
"insert",
"(",
"t",
".",
"previous",
",",
"n",
")",
";",
"tokens",
".",
"remove",
"(",
"t",
")",
";",
"t",
"=",
"n",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"1",
")",
"{",
"// var : ?",
"if",
"(",
"isVariableInteger",
"(",
"t",
")",
")",
"{",
"state",
"=",
"2",
";",
"}",
"else",
"{",
"// array range",
"IntegerSequence",
"range",
"=",
"new",
"IntegerSequence",
".",
"Range",
"(",
"start",
",",
"null",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"range",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"prev",
")",
";",
"state",
"=",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"2",
")",
"{",
"// var:var ?",
"if",
"(",
"t",
"!=",
"null",
"&&",
"t",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"COLON",
")",
"{",
"middle",
"=",
"prev",
";",
"state",
"=",
"3",
";",
"}",
"else",
"{",
"// create for sequence with start and stop elements only",
"IntegerSequence",
"numbers",
"=",
"new",
"IntegerSequence",
".",
"For",
"(",
"start",
",",
"null",
",",
"prev",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"numbers",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"prev",
")",
";",
"if",
"(",
"t",
"!=",
"null",
")",
"t",
"=",
"t",
".",
"previous",
";",
"state",
"=",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"3",
")",
"{",
"// var:var: ?",
"if",
"(",
"isVariableInteger",
"(",
"t",
")",
")",
"{",
"// create 'for' sequence with three variables",
"IntegerSequence",
"numbers",
"=",
"new",
"IntegerSequence",
".",
"For",
"(",
"start",
",",
"middle",
",",
"t",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"numbers",
")",
";",
"t",
"=",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"t",
")",
";",
"}",
"else",
"{",
"// array range with 2 elements",
"IntegerSequence",
"numbers",
"=",
"new",
"IntegerSequence",
".",
"Range",
"(",
"start",
",",
"middle",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"numbers",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"prev",
")",
";",
"}",
"state",
"=",
"0",
";",
"}",
"if",
"(",
"last",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"t",
".",
"next",
"==",
"null",
")",
"{",
"// handle the case where it is the last token in the sequence",
"last",
"=",
"true",
";",
"}",
"prev",
"=",
"t",
";",
"t",
"=",
"t",
".",
"next",
";",
"}",
"}"
] |
Searches for descriptions of integer sequences and array ranges that have a colon character in them
Examples of integer sequences:
1:6
2:4:20
:
Examples of array range
2:
2:4:
|
[
"Searches",
"for",
"descriptions",
"of",
"integer",
"sequences",
"and",
"array",
"ranges",
"that",
"have",
"a",
"colon",
"character",
"in",
"them"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L918-L996
|
162,494 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseIntegerLists
|
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) ) {
start = t;
state = 1;
}
} else if( state == 1 ) {
// var ?
if( isVariableInteger(t)) { // see if its explicit number sequence
state = 2;
} else { // just scalar integer, skip
state = 0;
}
} else if ( state == 2 ) {
// var var ....
if( !isVariableInteger(t) ) {
// create explicit list sequence
IntegerSequence sequence = new IntegerSequence.Explicit(start,prev);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, prev);
state = 0;
}
}
if( last ) {
break;
} else if( t.next == null ) {
// handle the case where it is the last token in the sequence
last = true;
}
prev = t;
t = t.next;
}
}
|
java
|
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) ) {
start = t;
state = 1;
}
} else if( state == 1 ) {
// var ?
if( isVariableInteger(t)) { // see if its explicit number sequence
state = 2;
} else { // just scalar integer, skip
state = 0;
}
} else if ( state == 2 ) {
// var var ....
if( !isVariableInteger(t) ) {
// create explicit list sequence
IntegerSequence sequence = new IntegerSequence.Explicit(start,prev);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, prev);
state = 0;
}
}
if( last ) {
break;
} else if( t.next == null ) {
// handle the case where it is the last token in the sequence
last = true;
}
prev = t;
t = t.next;
}
}
|
[
"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",
")",
")",
"{",
"start",
"=",
"t",
";",
"state",
"=",
"1",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"1",
")",
"{",
"// var ?",
"if",
"(",
"isVariableInteger",
"(",
"t",
")",
")",
"{",
"// see if its explicit number sequence",
"state",
"=",
"2",
";",
"}",
"else",
"{",
"// just scalar integer, skip",
"state",
"=",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"2",
")",
"{",
"// var var ....",
"if",
"(",
"!",
"isVariableInteger",
"(",
"t",
")",
")",
"{",
"// create explicit list sequence",
"IntegerSequence",
"sequence",
"=",
"new",
"IntegerSequence",
".",
"Explicit",
"(",
"start",
",",
"prev",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"sequence",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"prev",
")",
";",
"state",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"last",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"t",
".",
"next",
"==",
"null",
")",
"{",
"// handle the case where it is the last token in the sequence",
"last",
"=",
"true",
";",
"}",
"prev",
"=",
"t",
";",
"t",
"=",
"t",
".",
"next",
";",
"}",
"}"
] |
Searches for a sequence of integers
example:
1 2 3 4 6 7 -3
|
[
"Searches",
"for",
"a",
"sequence",
"of",
"integers"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1005-L1049
|
162,495 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseCombineIntegerLists
|
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 && (isVariableInteger(t) ||
t.getVariable().getType() == VariableType.INTEGER_SEQUENCE )) {
if( numFound == 0 ) {
numFound = 1;
start = end = t;
} else {
numFound++;
end = t;
}
} else if( numFound > 1 ) {
IntegerSequence sequence = new IntegerSequence.Combined(start,end);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, end);
numFound = 0;
} else {
numFound = 0;
}
t = t.next;
}
if( numFound > 1 ) {
IntegerSequence sequence = new IntegerSequence.Combined(start,end);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, end);
}
}
|
java
|
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 && (isVariableInteger(t) ||
t.getVariable().getType() == VariableType.INTEGER_SEQUENCE )) {
if( numFound == 0 ) {
numFound = 1;
start = end = t;
} else {
numFound++;
end = t;
}
} else if( numFound > 1 ) {
IntegerSequence sequence = new IntegerSequence.Combined(start,end);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, end);
numFound = 0;
} else {
numFound = 0;
}
t = t.next;
}
if( numFound > 1 ) {
IntegerSequence sequence = new IntegerSequence.Combined(start,end);
VariableIntegerSequence varSequence = functions.getManagerTemp().createIntegerSequence(sequence);
replaceSequence(tokens, varSequence, start, end);
}
}
|
[
"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",
"&&",
"(",
"isVariableInteger",
"(",
"t",
")",
"||",
"t",
".",
"getVariable",
"(",
")",
".",
"getType",
"(",
")",
"==",
"VariableType",
".",
"INTEGER_SEQUENCE",
")",
")",
"{",
"if",
"(",
"numFound",
"==",
"0",
")",
"{",
"numFound",
"=",
"1",
";",
"start",
"=",
"end",
"=",
"t",
";",
"}",
"else",
"{",
"numFound",
"++",
";",
"end",
"=",
"t",
";",
"}",
"}",
"else",
"if",
"(",
"numFound",
">",
"1",
")",
"{",
"IntegerSequence",
"sequence",
"=",
"new",
"IntegerSequence",
".",
"Combined",
"(",
"start",
",",
"end",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"sequence",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"end",
")",
";",
"numFound",
"=",
"0",
";",
"}",
"else",
"{",
"numFound",
"=",
"0",
";",
"}",
"t",
"=",
"t",
".",
"next",
";",
"}",
"if",
"(",
"numFound",
">",
"1",
")",
"{",
"IntegerSequence",
"sequence",
"=",
"new",
"IntegerSequence",
".",
"Combined",
"(",
"start",
",",
"end",
")",
";",
"VariableIntegerSequence",
"varSequence",
"=",
"functions",
".",
"getManagerTemp",
"(",
")",
".",
"createIntegerSequence",
"(",
"sequence",
")",
";",
"replaceSequence",
"(",
"tokens",
",",
"varSequence",
",",
"start",
",",
"end",
")",
";",
"}",
"}"
] |
Looks for sequences of integer lists and combine them into one big sequence
|
[
"Looks",
"for",
"sequences",
"of",
"integer",
"lists",
"and",
"combine",
"them",
"into",
"one",
"big",
"sequence"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1054-L1090
|
162,496 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.isVariableInteger
|
private static boolean isVariableInteger(TokenList.Token t) {
if( t == null )
return false;
return t.getScalarType() == VariableScalar.Type.INTEGER;
}
|
java
|
private static boolean isVariableInteger(TokenList.Token t) {
if( t == null )
return false;
return t.getScalarType() == VariableScalar.Type.INTEGER;
}
|
[
"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
@return true if integer or false if not
|
[
"Checks",
"to",
"see",
"if",
"the",
"token",
"is",
"an",
"integer",
"scalar"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1104-L1109
|
162,497 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseBracketCreateMatrix
|
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.add(t);
} else if( t.getSymbol() == Symbol.BRACKET_RIGHT ) {
if( left.isEmpty() )
throw new RuntimeException("No matching left bracket for right");
TokenList.Token start = left.remove(left.size() - 1);
// Compute everything inside the [ ], this will leave a
// series of variables and semi-colons hopefully
TokenList bracketLet = tokens.extractSubList(start.next,t.previous);
parseBlockNoParentheses(bracketLet, sequence, true);
MatrixConstructor constructor = constructMatrix(bracketLet);
// define the matrix op and inject into token list
Operation.Info info = Operation.matrixConstructor(constructor);
sequence.addOperation(info.op);
tokens.insert(start.previous, new TokenList.Token(info.output));
// remove the brackets
tokens.remove(start);
tokens.remove(t);
}
t = next;
}
if( !left.isEmpty() )
throw new RuntimeException("Dangling [");
}
|
java
|
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.add(t);
} else if( t.getSymbol() == Symbol.BRACKET_RIGHT ) {
if( left.isEmpty() )
throw new RuntimeException("No matching left bracket for right");
TokenList.Token start = left.remove(left.size() - 1);
// Compute everything inside the [ ], this will leave a
// series of variables and semi-colons hopefully
TokenList bracketLet = tokens.extractSubList(start.next,t.previous);
parseBlockNoParentheses(bracketLet, sequence, true);
MatrixConstructor constructor = constructMatrix(bracketLet);
// define the matrix op and inject into token list
Operation.Info info = Operation.matrixConstructor(constructor);
sequence.addOperation(info.op);
tokens.insert(start.previous, new TokenList.Token(info.output));
// remove the brackets
tokens.remove(start);
tokens.remove(t);
}
t = next;
}
if( !left.isEmpty() )
throw new RuntimeException("Dangling [");
}
|
[
"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",
".",
"add",
"(",
"t",
")",
";",
"}",
"else",
"if",
"(",
"t",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"BRACKET_RIGHT",
")",
"{",
"if",
"(",
"left",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"No matching left bracket for right\"",
")",
";",
"TokenList",
".",
"Token",
"start",
"=",
"left",
".",
"remove",
"(",
"left",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"// Compute everything inside the [ ], this will leave a",
"// series of variables and semi-colons hopefully",
"TokenList",
"bracketLet",
"=",
"tokens",
".",
"extractSubList",
"(",
"start",
".",
"next",
",",
"t",
".",
"previous",
")",
";",
"parseBlockNoParentheses",
"(",
"bracketLet",
",",
"sequence",
",",
"true",
")",
";",
"MatrixConstructor",
"constructor",
"=",
"constructMatrix",
"(",
"bracketLet",
")",
";",
"// define the matrix op and inject into token list",
"Operation",
".",
"Info",
"info",
"=",
"Operation",
".",
"matrixConstructor",
"(",
"constructor",
")",
";",
"sequence",
".",
"addOperation",
"(",
"info",
".",
"op",
")",
";",
"tokens",
".",
"insert",
"(",
"start",
".",
"previous",
",",
"new",
"TokenList",
".",
"Token",
"(",
"info",
".",
"output",
")",
")",
";",
"// remove the brackets",
"tokens",
".",
"remove",
"(",
"start",
")",
";",
"tokens",
".",
"remove",
"(",
"t",
")",
";",
"}",
"t",
"=",
"next",
";",
"}",
"if",
"(",
"!",
"left",
".",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Dangling [\"",
")",
";",
"}"
] |
Searches for brackets which are only used to construct new matrices by concatenating
1 or more matrices together
|
[
"Searches",
"for",
"brackets",
"which",
"are",
"only",
"used",
"to",
"construct",
"new",
"matrices",
"by",
"concatenating",
"1",
"or",
"more",
"matrices",
"together"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1115-L1152
|
162,498 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseNegOp
|
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.getType() != Type.SYMBOL)
break escape;
if( token.previous != null && token.previous.getType() == Type.SYMBOL &&
(token.previous.symbol == Symbol.TRANSPOSE))
break escape;
if( token.next == null || token.next.getType() == Type.SYMBOL)
break escape;
if( token.next.getType() != Type.VARIABLE )
throw new RuntimeException("Crap bug rethink this function");
// create the operation
Operation.Info info = Operation.neg(token.next.getVariable(),functions.getManagerTemp());
// add the operation to the sequence
sequence.addOperation(info.op);
// update the token list
TokenList.Token t = new TokenList.Token(info.output);
tokens.insert(token.next,t);
tokens.remove(token.next);
tokens.remove(token);
next = t;
}
token = next;
}
}
|
java
|
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.getType() != Type.SYMBOL)
break escape;
if( token.previous != null && token.previous.getType() == Type.SYMBOL &&
(token.previous.symbol == Symbol.TRANSPOSE))
break escape;
if( token.next == null || token.next.getType() == Type.SYMBOL)
break escape;
if( token.next.getType() != Type.VARIABLE )
throw new RuntimeException("Crap bug rethink this function");
// create the operation
Operation.Info info = Operation.neg(token.next.getVariable(),functions.getManagerTemp());
// add the operation to the sequence
sequence.addOperation(info.op);
// update the token list
TokenList.Token t = new TokenList.Token(info.output);
tokens.insert(token.next,t);
tokens.remove(token.next);
tokens.remove(token);
next = t;
}
token = next;
}
}
|
[
"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",
".",
"getType",
"(",
")",
"!=",
"Type",
".",
"SYMBOL",
")",
"break",
"escape",
";",
"if",
"(",
"token",
".",
"previous",
"!=",
"null",
"&&",
"token",
".",
"previous",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
"&&",
"(",
"token",
".",
"previous",
".",
"symbol",
"==",
"Symbol",
".",
"TRANSPOSE",
")",
")",
"break",
"escape",
";",
"if",
"(",
"token",
".",
"next",
"==",
"null",
"||",
"token",
".",
"next",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
")",
"break",
"escape",
";",
"if",
"(",
"token",
".",
"next",
".",
"getType",
"(",
")",
"!=",
"Type",
".",
"VARIABLE",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Crap bug rethink this function\"",
")",
";",
"// create the operation",
"Operation",
".",
"Info",
"info",
"=",
"Operation",
".",
"neg",
"(",
"token",
".",
"next",
".",
"getVariable",
"(",
")",
",",
"functions",
".",
"getManagerTemp",
"(",
")",
")",
";",
"// add the operation to the sequence",
"sequence",
".",
"addOperation",
"(",
"info",
".",
"op",
")",
";",
"// update the token list",
"TokenList",
".",
"Token",
"t",
"=",
"new",
"TokenList",
".",
"Token",
"(",
"info",
".",
"output",
")",
";",
"tokens",
".",
"insert",
"(",
"token",
".",
"next",
",",
"t",
")",
";",
"tokens",
".",
"remove",
"(",
"token",
".",
"next",
")",
";",
"tokens",
".",
"remove",
"(",
"token",
")",
";",
"next",
"=",
"t",
";",
"}",
"token",
"=",
"next",
";",
"}",
"}"
] |
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
Example:
a = - b * c
|
[
"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"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1183-L1217
|
162,499 |
lessthanoptimal/ejml
|
main/ejml-simple/src/org/ejml/equation/Equation.java
|
Equation.parseOperationsL
|
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 ) {
if( token.getType() == Type.FUNCTION ) {
throw new ParseError("Function encountered with no parentheses");
} else if( token.getType() == Type.SYMBOL && token.getSymbol() == Symbol.TRANSPOSE) {
if( token.previous.getType() == Type.VARIABLE )
token = insertTranspose(token.previous,tokens,sequence);
else
throw new ParseError("Expected variable before transpose");
}
token = token.next;
}
}
|
java
|
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 ) {
if( token.getType() == Type.FUNCTION ) {
throw new ParseError("Function encountered with no parentheses");
} else if( token.getType() == Type.SYMBOL && token.getSymbol() == Symbol.TRANSPOSE) {
if( token.previous.getType() == Type.VARIABLE )
token = insertTranspose(token.previous,tokens,sequence);
else
throw new ParseError("Expected variable before transpose");
}
token = token.next;
}
}
|
[
"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",
")",
"{",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"FUNCTION",
")",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Function encountered with no parentheses\"",
")",
";",
"}",
"else",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
"&&",
"token",
".",
"getSymbol",
"(",
")",
"==",
"Symbol",
".",
"TRANSPOSE",
")",
"{",
"if",
"(",
"token",
".",
"previous",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"VARIABLE",
")",
"token",
"=",
"insertTranspose",
"(",
"token",
".",
"previous",
",",
"tokens",
",",
"sequence",
")",
";",
"else",
"throw",
"new",
"ParseError",
"(",
"\"Expected variable before transpose\"",
")",
";",
"}",
"token",
"=",
"token",
".",
"next",
";",
"}",
"}"
] |
Parses operations where the input comes from variables to its left only. Hard coded to only look
for transpose for now
@param tokens List of all the tokens
@param sequence List of operation sequence
|
[
"Parses",
"operations",
"where",
"the",
"input",
"comes",
"from",
"variables",
"to",
"its",
"left",
"only",
".",
"Hard",
"coded",
"to",
"only",
"look",
"for",
"transpose",
"for",
"now"
] |
1444680cc487af5e866730e62f48f5f9636850d9
|
https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1227-L1248
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.