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
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
162,500 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.parseOperationsLR | protected void parseOperationsLR(Symbol ops[], TokenList tokens, Sequence sequence) {
if( tokens.size == 0 )
return;
TokenList.Token token = tokens.first;
if( token.getType() != Type.VARIABLE )
throw new ParseError("The first token in an equation needs to be a variable and not "+token);
boolean hasLeft = false;
while( token != null ) {
if( token.getType() == Type.FUNCTION ) {
throw new ParseError("Function encountered with no parentheses");
} else if( token.getType() == Type.VARIABLE ) {
if( hasLeft ) {
if( isTargetOp(token.previous,ops)) {
token = createOp(token.previous.previous,token.previous,token,tokens,sequence);
}
} else {
hasLeft = true;
}
} else {
if( token.previous.getType() == Type.SYMBOL ) {
throw new ParseError("Two symbols next to each other. "+token.previous+" and "+token);
}
}
token = token.next;
}
} | java | protected void parseOperationsLR(Symbol ops[], TokenList tokens, Sequence sequence) {
if( tokens.size == 0 )
return;
TokenList.Token token = tokens.first;
if( token.getType() != Type.VARIABLE )
throw new ParseError("The first token in an equation needs to be a variable and not "+token);
boolean hasLeft = false;
while( token != null ) {
if( token.getType() == Type.FUNCTION ) {
throw new ParseError("Function encountered with no parentheses");
} else if( token.getType() == Type.VARIABLE ) {
if( hasLeft ) {
if( isTargetOp(token.previous,ops)) {
token = createOp(token.previous.previous,token.previous,token,tokens,sequence);
}
} else {
hasLeft = true;
}
} else {
if( token.previous.getType() == Type.SYMBOL ) {
throw new ParseError("Two symbols next to each other. "+token.previous+" and "+token);
}
}
token = token.next;
}
} | [
"protected",
"void",
"parseOperationsLR",
"(",
"Symbol",
"ops",
"[",
"]",
",",
"TokenList",
"tokens",
",",
"Sequence",
"sequence",
")",
"{",
"if",
"(",
"tokens",
".",
"size",
"==",
"0",
")",
"return",
";",
"TokenList",
".",
"Token",
"token",
"=",
"tokens",
".",
"first",
";",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"!=",
"Type",
".",
"VARIABLE",
")",
"throw",
"new",
"ParseError",
"(",
"\"The first token in an equation needs to be a variable and not \"",
"+",
"token",
")",
";",
"boolean",
"hasLeft",
"=",
"false",
";",
"while",
"(",
"token",
"!=",
"null",
")",
"{",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"FUNCTION",
")",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Function encountered with no parentheses\"",
")",
";",
"}",
"else",
"if",
"(",
"token",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"VARIABLE",
")",
"{",
"if",
"(",
"hasLeft",
")",
"{",
"if",
"(",
"isTargetOp",
"(",
"token",
".",
"previous",
",",
"ops",
")",
")",
"{",
"token",
"=",
"createOp",
"(",
"token",
".",
"previous",
".",
"previous",
",",
"token",
".",
"previous",
",",
"token",
",",
"tokens",
",",
"sequence",
")",
";",
"}",
"}",
"else",
"{",
"hasLeft",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"token",
".",
"previous",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"SYMBOL",
")",
"{",
"throw",
"new",
"ParseError",
"(",
"\"Two symbols next to each other. \"",
"+",
"token",
".",
"previous",
"+",
"\" and \"",
"+",
"token",
")",
";",
"}",
"}",
"token",
"=",
"token",
".",
"next",
";",
"}",
"}"
] | Parses operations where the input comes from variables to its left and right
@param ops List of operations which should be parsed
@param tokens List of all the tokens
@param sequence List of operation sequence | [
"Parses",
"operations",
"where",
"the",
"input",
"comes",
"from",
"variables",
"to",
"its",
"left",
"and",
"right"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1257-L1286 |
162,501 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.lookupVariable | public <T extends Variable> T lookupVariable(String token) {
Variable result = variables.get(token);
return (T)result;
} | java | public <T extends Variable> T lookupVariable(String token) {
Variable result = variables.get(token);
return (T)result;
} | [
"public",
"<",
"T",
"extends",
"Variable",
">",
"T",
"lookupVariable",
"(",
"String",
"token",
")",
"{",
"Variable",
"result",
"=",
"variables",
".",
"get",
"(",
"token",
")",
";",
"return",
"(",
"T",
")",
"result",
";",
"}"
] | Looks up a variable given its name. If none is found then return null. | [
"Looks",
"up",
"a",
"variable",
"given",
"its",
"name",
".",
"If",
"none",
"is",
"found",
"then",
"return",
"null",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1358-L1361 |
162,502 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.insertMacros | void insertMacros(TokenList tokens ) {
TokenList.Token t = tokens.getFirst();
while( t != null ) {
if( t.getType() == Type.WORD ) {
Macro v = lookupMacro(t.word);
if (v != null) {
TokenList.Token before = t.previous;
List<TokenList.Token> inputs = new ArrayList<TokenList.Token>();
t = parseMacroInput(inputs,t.next);
TokenList sniplet = v.execute(inputs);
tokens.extractSubList(before.next,t);
tokens.insertAfter(before,sniplet);
t = sniplet.last;
}
}
t = t.next;
}
} | java | void insertMacros(TokenList tokens ) {
TokenList.Token t = tokens.getFirst();
while( t != null ) {
if( t.getType() == Type.WORD ) {
Macro v = lookupMacro(t.word);
if (v != null) {
TokenList.Token before = t.previous;
List<TokenList.Token> inputs = new ArrayList<TokenList.Token>();
t = parseMacroInput(inputs,t.next);
TokenList sniplet = v.execute(inputs);
tokens.extractSubList(before.next,t);
tokens.insertAfter(before,sniplet);
t = sniplet.last;
}
}
t = t.next;
}
} | [
"void",
"insertMacros",
"(",
"TokenList",
"tokens",
")",
"{",
"TokenList",
".",
"Token",
"t",
"=",
"tokens",
".",
"getFirst",
"(",
")",
";",
"while",
"(",
"t",
"!=",
"null",
")",
"{",
"if",
"(",
"t",
".",
"getType",
"(",
")",
"==",
"Type",
".",
"WORD",
")",
"{",
"Macro",
"v",
"=",
"lookupMacro",
"(",
"t",
".",
"word",
")",
";",
"if",
"(",
"v",
"!=",
"null",
")",
"{",
"TokenList",
".",
"Token",
"before",
"=",
"t",
".",
"previous",
";",
"List",
"<",
"TokenList",
".",
"Token",
">",
"inputs",
"=",
"new",
"ArrayList",
"<",
"TokenList",
".",
"Token",
">",
"(",
")",
";",
"t",
"=",
"parseMacroInput",
"(",
"inputs",
",",
"t",
".",
"next",
")",
";",
"TokenList",
"sniplet",
"=",
"v",
".",
"execute",
"(",
"inputs",
")",
";",
"tokens",
".",
"extractSubList",
"(",
"before",
".",
"next",
",",
"t",
")",
";",
"tokens",
".",
"insertAfter",
"(",
"before",
",",
"sniplet",
")",
";",
"t",
"=",
"sniplet",
".",
"last",
";",
"}",
"}",
"t",
"=",
"t",
".",
"next",
";",
"}",
"}"
] | Checks to see if a WORD matches the name of a macro. if it does it applies the macro at that location | [
"Checks",
"to",
"see",
"if",
"a",
"WORD",
"matches",
"the",
"name",
"of",
"a",
"macro",
".",
"if",
"it",
"does",
"it",
"applies",
"the",
"macro",
"at",
"that",
"location"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1557-L1575 |
162,503 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.isTargetOp | protected static boolean isTargetOp( TokenList.Token token , Symbol[] ops ) {
Symbol c = token.symbol;
for (int i = 0; i < ops.length; i++) {
if( c == ops[i])
return true;
}
return false;
} | java | protected static boolean isTargetOp( TokenList.Token token , Symbol[] ops ) {
Symbol c = token.symbol;
for (int i = 0; i < ops.length; i++) {
if( c == ops[i])
return true;
}
return false;
} | [
"protected",
"static",
"boolean",
"isTargetOp",
"(",
"TokenList",
".",
"Token",
"token",
",",
"Symbol",
"[",
"]",
"ops",
")",
"{",
"Symbol",
"c",
"=",
"token",
".",
"symbol",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"ops",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"c",
"==",
"ops",
"[",
"i",
"]",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks to see if the token is in the list of allowed character operations. Used to apply order of operations
@param token Token being checked
@param ops List of allowed character operations
@return true for it being in the list and false for it not being in the list | [
"Checks",
"to",
"see",
"if",
"the",
"token",
"is",
"in",
"the",
"list",
"of",
"allowed",
"character",
"operations",
".",
"Used",
"to",
"apply",
"order",
"of",
"operations"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1596-L1603 |
162,504 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.isOperatorLR | protected static boolean isOperatorLR( Symbol s ) {
if( s == null )
return false;
switch( s ) {
case ELEMENT_DIVIDE:
case ELEMENT_TIMES:
case ELEMENT_POWER:
case RDIVIDE:
case LDIVIDE:
case TIMES:
case POWER:
case PLUS:
case MINUS:
case ASSIGN:
return true;
}
return false;
} | java | protected static boolean isOperatorLR( Symbol s ) {
if( s == null )
return false;
switch( s ) {
case ELEMENT_DIVIDE:
case ELEMENT_TIMES:
case ELEMENT_POWER:
case RDIVIDE:
case LDIVIDE:
case TIMES:
case POWER:
case PLUS:
case MINUS:
case ASSIGN:
return true;
}
return false;
} | [
"protected",
"static",
"boolean",
"isOperatorLR",
"(",
"Symbol",
"s",
")",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"return",
"false",
";",
"switch",
"(",
"s",
")",
"{",
"case",
"ELEMENT_DIVIDE",
":",
"case",
"ELEMENT_TIMES",
":",
"case",
"ELEMENT_POWER",
":",
"case",
"RDIVIDE",
":",
"case",
"LDIVIDE",
":",
"case",
"TIMES",
":",
"case",
"POWER",
":",
"case",
"PLUS",
":",
"case",
"MINUS",
":",
"case",
"ASSIGN",
":",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Operators which affect the variables to its left and right | [
"Operators",
"which",
"affect",
"the",
"variables",
"to",
"its",
"left",
"and",
"right"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1613-L1631 |
162,505 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.isReserved | protected boolean isReserved( String name ) {
if( functions.isFunctionName(name))
return true;
for (int i = 0; i < name.length(); i++) {
if( !isLetter(name.charAt(i)) )
return true;
}
return false;
} | java | protected boolean isReserved( String name ) {
if( functions.isFunctionName(name))
return true;
for (int i = 0; i < name.length(); i++) {
if( !isLetter(name.charAt(i)) )
return true;
}
return false;
} | [
"protected",
"boolean",
"isReserved",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"functions",
".",
"isFunctionName",
"(",
"name",
")",
")",
"return",
"true",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"name",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isLetter",
"(",
"name",
".",
"charAt",
"(",
"i",
")",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the specified name is NOT allowed. It isn't allowed if it matches a built in operator
or if it contains a restricted character. | [
"Returns",
"true",
"if",
"the",
"specified",
"name",
"is",
"NOT",
"allowed",
".",
"It",
"isn",
"t",
"allowed",
"if",
"it",
"matches",
"a",
"built",
"in",
"operator",
"or",
"if",
"it",
"contains",
"a",
"restricted",
"character",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1644-L1653 |
162,506 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.process | public Equation process( String equation , boolean debug ) {
compile(equation,true,debug).perform();
return this;
} | java | public Equation process( String equation , boolean debug ) {
compile(equation,true,debug).perform();
return this;
} | [
"public",
"Equation",
"process",
"(",
"String",
"equation",
",",
"boolean",
"debug",
")",
"{",
"compile",
"(",
"equation",
",",
"true",
",",
"debug",
")",
".",
"perform",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Compiles and performs the provided equation.
@param equation String in simple equation format | [
"Compiles",
"and",
"performs",
"the",
"provided",
"equation",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1670-L1673 |
162,507 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Equation.java | Equation.print | public void print( String equation ) {
// first assume it's just a variable
Variable v = lookupVariable(equation);
if( v == null ) {
Sequence sequence = compile(equation,false,false);
sequence.perform();
v = sequence.output;
}
if( v instanceof VariableMatrix ) {
((VariableMatrix)v).matrix.print();
} else if(v instanceof VariableScalar ) {
System.out.println("Scalar = "+((VariableScalar)v).getDouble() );
} else {
System.out.println("Add support for "+v.getClass().getSimpleName());
}
} | java | public void print( String equation ) {
// first assume it's just a variable
Variable v = lookupVariable(equation);
if( v == null ) {
Sequence sequence = compile(equation,false,false);
sequence.perform();
v = sequence.output;
}
if( v instanceof VariableMatrix ) {
((VariableMatrix)v).matrix.print();
} else if(v instanceof VariableScalar ) {
System.out.println("Scalar = "+((VariableScalar)v).getDouble() );
} else {
System.out.println("Add support for "+v.getClass().getSimpleName());
}
} | [
"public",
"void",
"print",
"(",
"String",
"equation",
")",
"{",
"// first assume it's just a variable",
"Variable",
"v",
"=",
"lookupVariable",
"(",
"equation",
")",
";",
"if",
"(",
"v",
"==",
"null",
")",
"{",
"Sequence",
"sequence",
"=",
"compile",
"(",
"equation",
",",
"false",
",",
"false",
")",
";",
"sequence",
".",
"perform",
"(",
")",
";",
"v",
"=",
"sequence",
".",
"output",
";",
"}",
"if",
"(",
"v",
"instanceof",
"VariableMatrix",
")",
"{",
"(",
"(",
"VariableMatrix",
")",
"v",
")",
".",
"matrix",
".",
"print",
"(",
")",
";",
"}",
"else",
"if",
"(",
"v",
"instanceof",
"VariableScalar",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Scalar = \"",
"+",
"(",
"(",
"VariableScalar",
")",
"v",
")",
".",
"getDouble",
"(",
")",
")",
";",
"}",
"else",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Add support for \"",
"+",
"v",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
")",
";",
"}",
"}"
] | Prints the results of the equation to standard out. Useful for debugging | [
"Prints",
"the",
"results",
"of",
"the",
"equation",
"to",
"standard",
"out",
".",
"Useful",
"for",
"debugging"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Equation.java#L1678-L1694 |
162,508 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QrHelperFunctions_DDRM.java | QrHelperFunctions_DDRM.computeTauAndDivide | public static double computeTauAndDivide(final int j, final int numRows ,
final double[] u , final double max) {
double tau = 0;
// double div_max = 1.0/max;
// if( Double.isInfinite(div_max)) {
for( int i = j; i < numRows; i++ ) {
double d = u[i] /= max;
tau += d*d;
}
// } else {
// for( int i = j; i < numRows; i++ ) {
// double d = u[i] *= div_max;
// tau += d*d;
// }
// }
tau = Math.sqrt(tau);
if( u[j] < 0 )
tau = -tau;
return tau;
} | java | public static double computeTauAndDivide(final int j, final int numRows ,
final double[] u , final double max) {
double tau = 0;
// double div_max = 1.0/max;
// if( Double.isInfinite(div_max)) {
for( int i = j; i < numRows; i++ ) {
double d = u[i] /= max;
tau += d*d;
}
// } else {
// for( int i = j; i < numRows; i++ ) {
// double d = u[i] *= div_max;
// tau += d*d;
// }
// }
tau = Math.sqrt(tau);
if( u[j] < 0 )
tau = -tau;
return tau;
} | [
"public",
"static",
"double",
"computeTauAndDivide",
"(",
"final",
"int",
"j",
",",
"final",
"int",
"numRows",
",",
"final",
"double",
"[",
"]",
"u",
",",
"final",
"double",
"max",
")",
"{",
"double",
"tau",
"=",
"0",
";",
"// double div_max = 1.0/max;",
"// if( Double.isInfinite(div_max)) {",
"for",
"(",
"int",
"i",
"=",
"j",
";",
"i",
"<",
"numRows",
";",
"i",
"++",
")",
"{",
"double",
"d",
"=",
"u",
"[",
"i",
"]",
"/=",
"max",
";",
"tau",
"+=",
"d",
"*",
"d",
";",
"}",
"// } else {",
"// for( int i = j; i < numRows; i++ ) {",
"// double d = u[i] *= div_max;",
"// tau += d*d;",
"// }",
"// }",
"tau",
"=",
"Math",
".",
"sqrt",
"(",
"tau",
")",
";",
"if",
"(",
"u",
"[",
"j",
"]",
"<",
"0",
")",
"tau",
"=",
"-",
"tau",
";",
"return",
"tau",
";",
"}"
] | Normalizes elements in 'u' by dividing by max and computes the norm2 of the normalized
array u. Adjust the sign of the returned value depending on the size of the first
element in 'u'. Normalization is done to avoid overflow.
<pre>
for i=j:numRows
u[i] = u[i] / max
tau = tau + u[i]*u[i]
end
tau = sqrt(tau)
if( u[j] < 0 )
tau = -tau;
</pre>
@param j Element in 'u' that it starts at.
@param numRows Element in 'u' that it stops at.
@param u Array
@param max Max value in 'u' that is used to normalize it.
@return norm2 of 'u' | [
"Normalizes",
"elements",
"in",
"u",
"by",
"dividing",
"by",
"max",
"and",
"computes",
"the",
"norm2",
"of",
"the",
"normalized",
"array",
"u",
".",
"Adjust",
"the",
"sign",
"of",
"the",
"returned",
"value",
"depending",
"on",
"the",
"size",
"of",
"the",
"first",
"element",
"in",
"u",
".",
"Normalization",
"is",
"done",
"to",
"avoid",
"overflow",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QrHelperFunctions_DDRM.java#L173-L194 |
162,509 | lessthanoptimal/ejml | main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java | MatrixFeatures_DSCC.isSameStructure | public static boolean isSameStructure(DMatrixSparseCSC a , DMatrixSparseCSC b) {
if( a.numRows == b.numRows && a.numCols == b.numCols && a.nz_length == b.nz_length) {
for (int i = 0; i <= a.numCols; i++) {
if( a.col_idx[i] != b.col_idx[i] )
return false;
}
for (int i = 0; i < a.nz_length; i++) {
if( a.nz_rows[i] != b.nz_rows[i] )
return false;
}
return true;
}
return false;
} | java | public static boolean isSameStructure(DMatrixSparseCSC a , DMatrixSparseCSC b) {
if( a.numRows == b.numRows && a.numCols == b.numCols && a.nz_length == b.nz_length) {
for (int i = 0; i <= a.numCols; i++) {
if( a.col_idx[i] != b.col_idx[i] )
return false;
}
for (int i = 0; i < a.nz_length; i++) {
if( a.nz_rows[i] != b.nz_rows[i] )
return false;
}
return true;
}
return false;
} | [
"public",
"static",
"boolean",
"isSameStructure",
"(",
"DMatrixSparseCSC",
"a",
",",
"DMatrixSparseCSC",
"b",
")",
"{",
"if",
"(",
"a",
".",
"numRows",
"==",
"b",
".",
"numRows",
"&&",
"a",
".",
"numCols",
"==",
"b",
".",
"numCols",
"&&",
"a",
".",
"nz_length",
"==",
"b",
".",
"nz_length",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<=",
"a",
".",
"numCols",
";",
"i",
"++",
")",
"{",
"if",
"(",
"a",
".",
"col_idx",
"[",
"i",
"]",
"!=",
"b",
".",
"col_idx",
"[",
"i",
"]",
")",
"return",
"false",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"nz_length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"a",
".",
"nz_rows",
"[",
"i",
"]",
"!=",
"b",
".",
"nz_rows",
"[",
"i",
"]",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks to see if the two matrices have the same shape and same pattern of non-zero elements
@param a Matrix
@param b Matrix
@return true if the structure is the same | [
"Checks",
"to",
"see",
"if",
"the",
"two",
"matrices",
"have",
"the",
"same",
"shape",
"and",
"same",
"pattern",
"of",
"non",
"-",
"zero",
"elements"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java#L97-L110 |
162,510 | lessthanoptimal/ejml | main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java | MatrixFeatures_DSCC.isVector | public static boolean isVector(DMatrixSparseCSC a) {
return (a.numCols == 1 && a.numRows > 1) || (a.numRows == 1 && a.numCols>1);
} | java | public static boolean isVector(DMatrixSparseCSC a) {
return (a.numCols == 1 && a.numRows > 1) || (a.numRows == 1 && a.numCols>1);
} | [
"public",
"static",
"boolean",
"isVector",
"(",
"DMatrixSparseCSC",
"a",
")",
"{",
"return",
"(",
"a",
".",
"numCols",
"==",
"1",
"&&",
"a",
".",
"numRows",
">",
"1",
")",
"||",
"(",
"a",
".",
"numRows",
"==",
"1",
"&&",
"a",
".",
"numCols",
">",
"1",
")",
";",
"}"
] | Returns true if the input is a vector
@param a A matrix or vector
@return true if it's a vector. Column or row. | [
"Returns",
"true",
"if",
"the",
"input",
"is",
"a",
"vector"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java#L219-L221 |
162,511 | lessthanoptimal/ejml | main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java | MatrixFeatures_DSCC.isSymmetric | public static boolean isSymmetric( DMatrixSparseCSC A , double tol ) {
if( A.numRows != A.numCols )
return false;
int N = A.numCols;
for (int i = 0; i < N; i++) {
int idx0 = A.col_idx[i];
int idx1 = A.col_idx[i+1];
for (int index = idx0; index < idx1; index++) {
int j = A.nz_rows[index];
double value_ji = A.nz_values[index];
double value_ij = A.get(i,j);
if( Math.abs(value_ij-value_ji) > tol )
return false;
}
}
return true;
} | java | public static boolean isSymmetric( DMatrixSparseCSC A , double tol ) {
if( A.numRows != A.numCols )
return false;
int N = A.numCols;
for (int i = 0; i < N; i++) {
int idx0 = A.col_idx[i];
int idx1 = A.col_idx[i+1];
for (int index = idx0; index < idx1; index++) {
int j = A.nz_rows[index];
double value_ji = A.nz_values[index];
double value_ij = A.get(i,j);
if( Math.abs(value_ij-value_ji) > tol )
return false;
}
}
return true;
} | [
"public",
"static",
"boolean",
"isSymmetric",
"(",
"DMatrixSparseCSC",
"A",
",",
"double",
"tol",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"!=",
"A",
".",
"numCols",
")",
"return",
"false",
";",
"int",
"N",
"=",
"A",
".",
"numCols",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"int",
"idx0",
"=",
"A",
".",
"col_idx",
"[",
"i",
"]",
";",
"int",
"idx1",
"=",
"A",
".",
"col_idx",
"[",
"i",
"+",
"1",
"]",
";",
"for",
"(",
"int",
"index",
"=",
"idx0",
";",
"index",
"<",
"idx1",
";",
"index",
"++",
")",
"{",
"int",
"j",
"=",
"A",
".",
"nz_rows",
"[",
"index",
"]",
";",
"double",
"value_ji",
"=",
"A",
".",
"nz_values",
"[",
"index",
"]",
";",
"double",
"value_ij",
"=",
"A",
".",
"get",
"(",
"i",
",",
"j",
")",
";",
"if",
"(",
"Math",
".",
"abs",
"(",
"value_ij",
"-",
"value_ji",
")",
">",
"tol",
")",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks to see if the matrix is symmetric to within tolerance.
@param A Matrix being tested. Not modified.
@param tol Tolerance that defines how similar two values must be to be considered identical
@return true if symmetric or false if not | [
"Checks",
"to",
"see",
"if",
"the",
"matrix",
"is",
"symmetric",
"to",
"within",
"tolerance",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/csc/MatrixFeatures_DSCC.java#L230-L251 |
162,512 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/watched/WatchedDoubleStepQREigen_DDRM.java | WatchedDoubleStepQREigen_DDRM.implicitDoubleStep | public void implicitDoubleStep( int x1 , int x2 ) {
if( printHumps )
System.out.println("Performing implicit double step");
// compute the wilkinson shift
double z11 = A.get(x2 - 1, x2 - 1);
double z12 = A.get(x2 - 1, x2);
double z21 = A.get(x2, x2 - 1);
double z22 = A.get(x2, x2);
double a11 = A.get(x1,x1);
double a21 = A.get(x1+1,x1);
double a12 = A.get(x1,x1+1);
double a22 = A.get(x1+1,x1+1);
double a32 = A.get(x1+2,x1+1);
if( normalize ) {
temp[0] = a11;temp[1] = a21;temp[2] = a12;temp[3] = a22;temp[4] = a32;
temp[5] = z11;temp[6] = z22;temp[7] = z12;temp[8] = z21;
double max = Math.abs(temp[0]);
for( int j = 1; j < temp.length; j++ ) {
if( Math.abs(temp[j]) > max )
max = Math.abs(temp[j]);
}
a11 /= max;a21 /= max;a12 /= max;a22 /= max;a32 /= max;
z11 /= max;z22 /= max;z12 /= max;z21 /= max;
}
// these equations are derived when the eigenvalues are extracted from the lower right
// 2 by 2 matrix. See page 388 of Fundamentals of Matrix Computations 2nd ed for details.
double b11,b21,b31;
if( useStandardEq ) {
b11 = ((a11- z11)*(a11- z22)- z21 * z12)/a21 + a12;
b21 = a11 + a22 - z11 - z22;
b31 = a32;
} else {
// this is different from the version in the book and seems in my testing to be more resilient to
// over flow issues
b11 = ((a11- z11)*(a11- z22)- z21 * z12) + a12*a21;
b21 = (a11 + a22 - z11 - z22)*a21;
b31 = a32*a21;
}
performImplicitDoubleStep(x1, x2, b11 , b21 , b31 );
} | java | public void implicitDoubleStep( int x1 , int x2 ) {
if( printHumps )
System.out.println("Performing implicit double step");
// compute the wilkinson shift
double z11 = A.get(x2 - 1, x2 - 1);
double z12 = A.get(x2 - 1, x2);
double z21 = A.get(x2, x2 - 1);
double z22 = A.get(x2, x2);
double a11 = A.get(x1,x1);
double a21 = A.get(x1+1,x1);
double a12 = A.get(x1,x1+1);
double a22 = A.get(x1+1,x1+1);
double a32 = A.get(x1+2,x1+1);
if( normalize ) {
temp[0] = a11;temp[1] = a21;temp[2] = a12;temp[3] = a22;temp[4] = a32;
temp[5] = z11;temp[6] = z22;temp[7] = z12;temp[8] = z21;
double max = Math.abs(temp[0]);
for( int j = 1; j < temp.length; j++ ) {
if( Math.abs(temp[j]) > max )
max = Math.abs(temp[j]);
}
a11 /= max;a21 /= max;a12 /= max;a22 /= max;a32 /= max;
z11 /= max;z22 /= max;z12 /= max;z21 /= max;
}
// these equations are derived when the eigenvalues are extracted from the lower right
// 2 by 2 matrix. See page 388 of Fundamentals of Matrix Computations 2nd ed for details.
double b11,b21,b31;
if( useStandardEq ) {
b11 = ((a11- z11)*(a11- z22)- z21 * z12)/a21 + a12;
b21 = a11 + a22 - z11 - z22;
b31 = a32;
} else {
// this is different from the version in the book and seems in my testing to be more resilient to
// over flow issues
b11 = ((a11- z11)*(a11- z22)- z21 * z12) + a12*a21;
b21 = (a11 + a22 - z11 - z22)*a21;
b31 = a32*a21;
}
performImplicitDoubleStep(x1, x2, b11 , b21 , b31 );
} | [
"public",
"void",
"implicitDoubleStep",
"(",
"int",
"x1",
",",
"int",
"x2",
")",
"{",
"if",
"(",
"printHumps",
")",
"System",
".",
"out",
".",
"println",
"(",
"\"Performing implicit double step\"",
")",
";",
"// compute the wilkinson shift",
"double",
"z11",
"=",
"A",
".",
"get",
"(",
"x2",
"-",
"1",
",",
"x2",
"-",
"1",
")",
";",
"double",
"z12",
"=",
"A",
".",
"get",
"(",
"x2",
"-",
"1",
",",
"x2",
")",
";",
"double",
"z21",
"=",
"A",
".",
"get",
"(",
"x2",
",",
"x2",
"-",
"1",
")",
";",
"double",
"z22",
"=",
"A",
".",
"get",
"(",
"x2",
",",
"x2",
")",
";",
"double",
"a11",
"=",
"A",
".",
"get",
"(",
"x1",
",",
"x1",
")",
";",
"double",
"a21",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"1",
",",
"x1",
")",
";",
"double",
"a12",
"=",
"A",
".",
"get",
"(",
"x1",
",",
"x1",
"+",
"1",
")",
";",
"double",
"a22",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"1",
",",
"x1",
"+",
"1",
")",
";",
"double",
"a32",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"2",
",",
"x1",
"+",
"1",
")",
";",
"if",
"(",
"normalize",
")",
"{",
"temp",
"[",
"0",
"]",
"=",
"a11",
";",
"temp",
"[",
"1",
"]",
"=",
"a21",
";",
"temp",
"[",
"2",
"]",
"=",
"a12",
";",
"temp",
"[",
"3",
"]",
"=",
"a22",
";",
"temp",
"[",
"4",
"]",
"=",
"a32",
";",
"temp",
"[",
"5",
"]",
"=",
"z11",
";",
"temp",
"[",
"6",
"]",
"=",
"z22",
";",
"temp",
"[",
"7",
"]",
"=",
"z12",
";",
"temp",
"[",
"8",
"]",
"=",
"z21",
";",
"double",
"max",
"=",
"Math",
".",
"abs",
"(",
"temp",
"[",
"0",
"]",
")",
";",
"for",
"(",
"int",
"j",
"=",
"1",
";",
"j",
"<",
"temp",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"Math",
".",
"abs",
"(",
"temp",
"[",
"j",
"]",
")",
">",
"max",
")",
"max",
"=",
"Math",
".",
"abs",
"(",
"temp",
"[",
"j",
"]",
")",
";",
"}",
"a11",
"/=",
"max",
";",
"a21",
"/=",
"max",
";",
"a12",
"/=",
"max",
";",
"a22",
"/=",
"max",
";",
"a32",
"/=",
"max",
";",
"z11",
"/=",
"max",
";",
"z22",
"/=",
"max",
";",
"z12",
"/=",
"max",
";",
"z21",
"/=",
"max",
";",
"}",
"// these equations are derived when the eigenvalues are extracted from the lower right",
"// 2 by 2 matrix. See page 388 of Fundamentals of Matrix Computations 2nd ed for details.",
"double",
"b11",
",",
"b21",
",",
"b31",
";",
"if",
"(",
"useStandardEq",
")",
"{",
"b11",
"=",
"(",
"(",
"a11",
"-",
"z11",
")",
"*",
"(",
"a11",
"-",
"z22",
")",
"-",
"z21",
"*",
"z12",
")",
"/",
"a21",
"+",
"a12",
";",
"b21",
"=",
"a11",
"+",
"a22",
"-",
"z11",
"-",
"z22",
";",
"b31",
"=",
"a32",
";",
"}",
"else",
"{",
"// this is different from the version in the book and seems in my testing to be more resilient to",
"// over flow issues",
"b11",
"=",
"(",
"(",
"a11",
"-",
"z11",
")",
"*",
"(",
"a11",
"-",
"z22",
")",
"-",
"z21",
"*",
"z12",
")",
"+",
"a12",
"*",
"a21",
";",
"b21",
"=",
"(",
"a11",
"+",
"a22",
"-",
"z11",
"-",
"z22",
")",
"*",
"a21",
";",
"b31",
"=",
"a32",
"*",
"a21",
";",
"}",
"performImplicitDoubleStep",
"(",
"x1",
",",
"x2",
",",
"b11",
",",
"b21",
",",
"b31",
")",
";",
"}"
] | Performs an implicit double step using the values contained in the lower right hand side
of the submatrix for the estimated eigenvector values.
@param x1
@param x2 | [
"Performs",
"an",
"implicit",
"double",
"step",
"using",
"the",
"values",
"contained",
"in",
"the",
"lower",
"right",
"hand",
"side",
"of",
"the",
"submatrix",
"for",
"the",
"estimated",
"eigenvector",
"values",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/watched/WatchedDoubleStepQREigen_DDRM.java#L195-L240 |
162,513 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/watched/WatchedDoubleStepQREigen_DDRM.java | WatchedDoubleStepQREigen_DDRM.performImplicitDoubleStep | public void performImplicitDoubleStep(int x1, int x2 , double real , double img ) {
double a11 = A.get(x1,x1);
double a21 = A.get(x1+1,x1);
double a12 = A.get(x1,x1+1);
double a22 = A.get(x1+1,x1+1);
double a32 = A.get(x1+2,x1+1);
double p_plus_t = 2.0*real;
double p_times_t = real*real + img*img;
double b11,b21,b31;
if( useStandardEq ) {
b11 = (a11*a11 - p_plus_t*a11+p_times_t)/a21 + a12;
b21 = a11+a22-p_plus_t;
b31 = a32;
} else {
// this is different from the version in the book and seems in my testing to be more resilient to
// over flow issues
b11 = (a11*a11 - p_plus_t*a11+p_times_t) + a12*a21;
b21 = (a11+a22-p_plus_t)*a21;
b31 = a32*a21;
}
performImplicitDoubleStep(x1, x2, b11, b21, b31);
} | java | public void performImplicitDoubleStep(int x1, int x2 , double real , double img ) {
double a11 = A.get(x1,x1);
double a21 = A.get(x1+1,x1);
double a12 = A.get(x1,x1+1);
double a22 = A.get(x1+1,x1+1);
double a32 = A.get(x1+2,x1+1);
double p_plus_t = 2.0*real;
double p_times_t = real*real + img*img;
double b11,b21,b31;
if( useStandardEq ) {
b11 = (a11*a11 - p_plus_t*a11+p_times_t)/a21 + a12;
b21 = a11+a22-p_plus_t;
b31 = a32;
} else {
// this is different from the version in the book and seems in my testing to be more resilient to
// over flow issues
b11 = (a11*a11 - p_plus_t*a11+p_times_t) + a12*a21;
b21 = (a11+a22-p_plus_t)*a21;
b31 = a32*a21;
}
performImplicitDoubleStep(x1, x2, b11, b21, b31);
} | [
"public",
"void",
"performImplicitDoubleStep",
"(",
"int",
"x1",
",",
"int",
"x2",
",",
"double",
"real",
",",
"double",
"img",
")",
"{",
"double",
"a11",
"=",
"A",
".",
"get",
"(",
"x1",
",",
"x1",
")",
";",
"double",
"a21",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"1",
",",
"x1",
")",
";",
"double",
"a12",
"=",
"A",
".",
"get",
"(",
"x1",
",",
"x1",
"+",
"1",
")",
";",
"double",
"a22",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"1",
",",
"x1",
"+",
"1",
")",
";",
"double",
"a32",
"=",
"A",
".",
"get",
"(",
"x1",
"+",
"2",
",",
"x1",
"+",
"1",
")",
";",
"double",
"p_plus_t",
"=",
"2.0",
"*",
"real",
";",
"double",
"p_times_t",
"=",
"real",
"*",
"real",
"+",
"img",
"*",
"img",
";",
"double",
"b11",
",",
"b21",
",",
"b31",
";",
"if",
"(",
"useStandardEq",
")",
"{",
"b11",
"=",
"(",
"a11",
"*",
"a11",
"-",
"p_plus_t",
"*",
"a11",
"+",
"p_times_t",
")",
"/",
"a21",
"+",
"a12",
";",
"b21",
"=",
"a11",
"+",
"a22",
"-",
"p_plus_t",
";",
"b31",
"=",
"a32",
";",
"}",
"else",
"{",
"// this is different from the version in the book and seems in my testing to be more resilient to",
"// over flow issues",
"b11",
"=",
"(",
"a11",
"*",
"a11",
"-",
"p_plus_t",
"*",
"a11",
"+",
"p_times_t",
")",
"+",
"a12",
"*",
"a21",
";",
"b21",
"=",
"(",
"a11",
"+",
"a22",
"-",
"p_plus_t",
")",
"*",
"a21",
";",
"b31",
"=",
"a32",
"*",
"a21",
";",
"}",
"performImplicitDoubleStep",
"(",
"x1",
",",
"x2",
",",
"b11",
",",
"b21",
",",
"b31",
")",
";",
"}"
] | Performs an implicit double step given the set of two imaginary eigenvalues provided.
Since one eigenvalue is the complex conjugate of the other only one set of real and imaginary
numbers is needed.
@param x1 upper index of submatrix.
@param x2 lower index of submatrix.
@param real Real component of each of the eigenvalues.
@param img Imaginary component of one of the eigenvalues. | [
"Performs",
"an",
"implicit",
"double",
"step",
"given",
"the",
"set",
"of",
"two",
"imaginary",
"eigenvalues",
"provided",
".",
"Since",
"one",
"eigenvalue",
"is",
"the",
"complex",
"conjugate",
"of",
"the",
"other",
"only",
"one",
"set",
"of",
"real",
"and",
"imaginary",
"numbers",
"is",
"needed",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/watched/WatchedDoubleStepQREigen_DDRM.java#L252-L276 |
162,514 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/linsol/qr/SolveNullSpaceQRP_DDRM.java | SolveNullSpaceQRP_DDRM.process | public boolean process(DMatrixRMaj A , int numSingularValues, DMatrixRMaj nullspace ) {
decomposition.decompose(A);
if( A.numRows > A.numCols ) {
Q.reshape(A.numCols,Math.min(A.numRows,A.numCols));
decomposition.getQ(Q, true);
} else {
Q.reshape(A.numCols, A.numCols);
decomposition.getQ(Q, false);
}
nullspace.reshape(Q.numRows,numSingularValues);
CommonOps_DDRM.extract(Q,0,Q.numRows,Q.numCols-numSingularValues,Q.numCols,nullspace,0,0);
return true;
} | java | public boolean process(DMatrixRMaj A , int numSingularValues, DMatrixRMaj nullspace ) {
decomposition.decompose(A);
if( A.numRows > A.numCols ) {
Q.reshape(A.numCols,Math.min(A.numRows,A.numCols));
decomposition.getQ(Q, true);
} else {
Q.reshape(A.numCols, A.numCols);
decomposition.getQ(Q, false);
}
nullspace.reshape(Q.numRows,numSingularValues);
CommonOps_DDRM.extract(Q,0,Q.numRows,Q.numCols-numSingularValues,Q.numCols,nullspace,0,0);
return true;
} | [
"public",
"boolean",
"process",
"(",
"DMatrixRMaj",
"A",
",",
"int",
"numSingularValues",
",",
"DMatrixRMaj",
"nullspace",
")",
"{",
"decomposition",
".",
"decompose",
"(",
"A",
")",
";",
"if",
"(",
"A",
".",
"numRows",
">",
"A",
".",
"numCols",
")",
"{",
"Q",
".",
"reshape",
"(",
"A",
".",
"numCols",
",",
"Math",
".",
"min",
"(",
"A",
".",
"numRows",
",",
"A",
".",
"numCols",
")",
")",
";",
"decomposition",
".",
"getQ",
"(",
"Q",
",",
"true",
")",
";",
"}",
"else",
"{",
"Q",
".",
"reshape",
"(",
"A",
".",
"numCols",
",",
"A",
".",
"numCols",
")",
";",
"decomposition",
".",
"getQ",
"(",
"Q",
",",
"false",
")",
";",
"}",
"nullspace",
".",
"reshape",
"(",
"Q",
".",
"numRows",
",",
"numSingularValues",
")",
";",
"CommonOps_DDRM",
".",
"extract",
"(",
"Q",
",",
"0",
",",
"Q",
".",
"numRows",
",",
"Q",
".",
"numCols",
"-",
"numSingularValues",
",",
"Q",
".",
"numCols",
",",
"nullspace",
",",
"0",
",",
"0",
")",
";",
"return",
"true",
";",
"}"
] | Finds the null space of A
@param A (Input) Matrix. Modified
@param numSingularValues Number of singular values
@param nullspace Storage for null-space
@return true if successful or false if it failed | [
"Finds",
"the",
"null",
"space",
"of",
"A"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/linsol/qr/SolveNullSpaceQRP_DDRM.java#L48-L63 |
162,515 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.isInverse | public static boolean isInverse(DMatrixRMaj a , DMatrixRMaj b , double tol ) {
if( a.numRows != b.numRows || a.numCols != b.numCols ) {
return false;
}
int numRows = a.numRows;
int numCols = a.numCols;
for( int i = 0; i < numRows; i++ ) {
for( int j = 0; j < numCols; j++ ) {
double total = 0;
for( int k = 0; k < numCols; k++ ) {
total += a.get(i,k)*b.get(k,j);
}
if( i == j ) {
if( !(Math.abs(total-1) <= tol) )
return false;
} else if( !(Math.abs(total) <= tol) )
return false;
}
}
return true;
} | java | public static boolean isInverse(DMatrixRMaj a , DMatrixRMaj b , double tol ) {
if( a.numRows != b.numRows || a.numCols != b.numCols ) {
return false;
}
int numRows = a.numRows;
int numCols = a.numCols;
for( int i = 0; i < numRows; i++ ) {
for( int j = 0; j < numCols; j++ ) {
double total = 0;
for( int k = 0; k < numCols; k++ ) {
total += a.get(i,k)*b.get(k,j);
}
if( i == j ) {
if( !(Math.abs(total-1) <= tol) )
return false;
} else if( !(Math.abs(total) <= tol) )
return false;
}
}
return true;
} | [
"public",
"static",
"boolean",
"isInverse",
"(",
"DMatrixRMaj",
"a",
",",
"DMatrixRMaj",
"b",
",",
"double",
"tol",
")",
"{",
"if",
"(",
"a",
".",
"numRows",
"!=",
"b",
".",
"numRows",
"||",
"a",
".",
"numCols",
"!=",
"b",
".",
"numCols",
")",
"{",
"return",
"false",
";",
"}",
"int",
"numRows",
"=",
"a",
".",
"numRows",
";",
"int",
"numCols",
"=",
"a",
".",
"numCols",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numRows",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"numCols",
";",
"j",
"++",
")",
"{",
"double",
"total",
"=",
"0",
";",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"numCols",
";",
"k",
"++",
")",
"{",
"total",
"+=",
"a",
".",
"get",
"(",
"i",
",",
"k",
")",
"*",
"b",
".",
"get",
"(",
"k",
",",
"j",
")",
";",
"}",
"if",
"(",
"i",
"==",
"j",
")",
"{",
"if",
"(",
"!",
"(",
"Math",
".",
"abs",
"(",
"total",
"-",
"1",
")",
"<=",
"tol",
")",
")",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"Math",
".",
"abs",
"(",
"total",
")",
"<=",
"tol",
")",
")",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks to see if the two matrices are inverses of each other.
@param a A matrix. Not modified.
@param b A matrix. Not modified. | [
"Checks",
"to",
"see",
"if",
"the",
"two",
"matrices",
"are",
"inverses",
"of",
"each",
"other",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L265-L289 |
162,516 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.isRowsLinearIndependent | public static boolean isRowsLinearIndependent( DMatrixRMaj A )
{
// LU decomposition
LUDecomposition<DMatrixRMaj> lu = DecompositionFactory_DDRM.lu(A.numRows,A.numCols);
if( lu.inputModified() )
A = A.copy();
if( !lu.decompose(A))
throw new RuntimeException("Decompositon failed?");
// if they are linearly independent it should not be singular
return !lu.isSingular();
} | java | public static boolean isRowsLinearIndependent( DMatrixRMaj A )
{
// LU decomposition
LUDecomposition<DMatrixRMaj> lu = DecompositionFactory_DDRM.lu(A.numRows,A.numCols);
if( lu.inputModified() )
A = A.copy();
if( !lu.decompose(A))
throw new RuntimeException("Decompositon failed?");
// if they are linearly independent it should not be singular
return !lu.isSingular();
} | [
"public",
"static",
"boolean",
"isRowsLinearIndependent",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"// LU decomposition",
"LUDecomposition",
"<",
"DMatrixRMaj",
">",
"lu",
"=",
"DecompositionFactory_DDRM",
".",
"lu",
"(",
"A",
".",
"numRows",
",",
"A",
".",
"numCols",
")",
";",
"if",
"(",
"lu",
".",
"inputModified",
"(",
")",
")",
"A",
"=",
"A",
".",
"copy",
"(",
")",
";",
"if",
"(",
"!",
"lu",
".",
"decompose",
"(",
"A",
")",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Decompositon failed?\"",
")",
";",
"// if they are linearly independent it should not be singular",
"return",
"!",
"lu",
".",
"isSingular",
"(",
")",
";",
"}"
] | Checks to see if the rows of the provided matrix are linearly independent.
@param A Matrix whose rows are being tested for linear independence.
@return true if linearly independent and false otherwise. | [
"Checks",
"to",
"see",
"if",
"the",
"rows",
"of",
"the",
"provided",
"matrix",
"are",
"linearly",
"independent",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L504-L516 |
162,517 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.isConstantVal | public static boolean isConstantVal(DMatrixRMaj mat , double val , double tol )
{
// see if the result is an identity matrix
int index = 0;
for( int i = 0; i < mat.numRows; i++ ) {
for( int j = 0; j < mat.numCols; j++ ) {
if( !(Math.abs(mat.get(index++)-val) <= tol) )
return false;
}
}
return true;
} | java | public static boolean isConstantVal(DMatrixRMaj mat , double val , double tol )
{
// see if the result is an identity matrix
int index = 0;
for( int i = 0; i < mat.numRows; i++ ) {
for( int j = 0; j < mat.numCols; j++ ) {
if( !(Math.abs(mat.get(index++)-val) <= tol) )
return false;
}
}
return true;
} | [
"public",
"static",
"boolean",
"isConstantVal",
"(",
"DMatrixRMaj",
"mat",
",",
"double",
"val",
",",
"double",
"tol",
")",
"{",
"// see if the result is an identity matrix",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mat",
".",
"numRows",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"mat",
".",
"numCols",
";",
"j",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"Math",
".",
"abs",
"(",
"mat",
".",
"get",
"(",
"index",
"++",
")",
"-",
"val",
")",
"<=",
"tol",
")",
")",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks to see if every value in the matrix is the specified value.
@param mat The matrix being tested. Not modified.
@param val Checks to see if every element in the matrix has this value.
@param tol True if all the elements are within this tolerance.
@return true if the test passes. | [
"Checks",
"to",
"see",
"if",
"every",
"value",
"in",
"the",
"matrix",
"is",
"the",
"specified",
"value",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L552-L565 |
162,518 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.isDiagonalPositive | public static boolean isDiagonalPositive( DMatrixRMaj a ) {
for( int i = 0; i < a.numRows; i++ ) {
if( !(a.get(i,i) >= 0) )
return false;
}
return true;
} | java | public static boolean isDiagonalPositive( DMatrixRMaj a ) {
for( int i = 0; i < a.numRows; i++ ) {
if( !(a.get(i,i) >= 0) )
return false;
}
return true;
} | [
"public",
"static",
"boolean",
"isDiagonalPositive",
"(",
"DMatrixRMaj",
"a",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"numRows",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"a",
".",
"get",
"(",
"i",
",",
"i",
")",
">=",
"0",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks to see if all the diagonal elements in the matrix are positive.
@param a A matrix. Not modified.
@return true if all the diagonal elements are positive, false otherwise. | [
"Checks",
"to",
"see",
"if",
"all",
"the",
"diagonal",
"elements",
"in",
"the",
"matrix",
"are",
"positive",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L573-L579 |
162,519 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.rank | public static int rank(DMatrixRMaj A , double threshold ) {
SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,false,true);
if( svd.inputModified() )
A = A.copy();
if( !svd.decompose(A) )
throw new RuntimeException("Decomposition failed");
return SingularOps_DDRM.rank(svd, threshold);
} | java | public static int rank(DMatrixRMaj A , double threshold ) {
SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,false,true);
if( svd.inputModified() )
A = A.copy();
if( !svd.decompose(A) )
throw new RuntimeException("Decomposition failed");
return SingularOps_DDRM.rank(svd, threshold);
} | [
"public",
"static",
"int",
"rank",
"(",
"DMatrixRMaj",
"A",
",",
"double",
"threshold",
")",
"{",
"SingularValueDecomposition_F64",
"<",
"DMatrixRMaj",
">",
"svd",
"=",
"DecompositionFactory_DDRM",
".",
"svd",
"(",
"A",
".",
"numRows",
",",
"A",
".",
"numCols",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"if",
"(",
"svd",
".",
"inputModified",
"(",
")",
")",
"A",
"=",
"A",
".",
"copy",
"(",
")",
";",
"if",
"(",
"!",
"svd",
".",
"decompose",
"(",
"A",
")",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Decomposition failed\"",
")",
";",
"return",
"SingularOps_DDRM",
".",
"rank",
"(",
"svd",
",",
"threshold",
")",
";",
"}"
] | Computes the rank of a matrix using the specified tolerance.
@param A Matrix whose rank is to be calculated. Not modified.
@param threshold The numerical threshold used to determine a singular value.
@return The matrix's rank. | [
"Computes",
"the",
"rank",
"of",
"a",
"matrix",
"using",
"the",
"specified",
"tolerance",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L680-L690 |
162,520 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java | MatrixFeatures_DDRM.countNonZero | public static int countNonZero(DMatrixRMaj A){
int total = 0;
for (int row = 0, index=0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++,index++) {
if( A.data[index] != 0 ) {
total++;
}
}
}
return total;
} | java | public static int countNonZero(DMatrixRMaj A){
int total = 0;
for (int row = 0, index=0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++,index++) {
if( A.data[index] != 0 ) {
total++;
}
}
}
return total;
} | [
"public",
"static",
"int",
"countNonZero",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"int",
"total",
"=",
"0",
";",
"for",
"(",
"int",
"row",
"=",
"0",
",",
"index",
"=",
"0",
";",
"row",
"<",
"A",
".",
"numRows",
";",
"row",
"++",
")",
"{",
"for",
"(",
"int",
"col",
"=",
"0",
";",
"col",
"<",
"A",
".",
"numCols",
";",
"col",
"++",
",",
"index",
"++",
")",
"{",
"if",
"(",
"A",
".",
"data",
"[",
"index",
"]",
"!=",
"0",
")",
"{",
"total",
"++",
";",
"}",
"}",
"}",
"return",
"total",
";",
"}"
] | Counts the number of elements in A which are not zero.
@param A A matrix
@return number of non-zero elements | [
"Counts",
"the",
"number",
"of",
"elements",
"in",
"A",
"which",
"are",
"not",
"zero",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/MatrixFeatures_DDRM.java#L726-L736 |
162,521 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.invertSPD | public static boolean invertSPD(DMatrixRMaj mat, DMatrixRMaj result ) {
if( mat.numRows != mat.numCols )
throw new IllegalArgumentException("Must be a square matrix");
result.reshape(mat.numRows,mat.numRows);
if( mat.numRows <= UnrolledCholesky_DDRM.MAX ) {
// L*L' = A
if( !UnrolledCholesky_DDRM.lower(mat,result) )
return false;
// L = inv(L)
TriangularSolver_DDRM.invertLower(result.data,result.numCols);
// inv(A) = inv(L')*inv(L)
SpecializedOps_DDRM.multLowerTranA(result);
} else {
LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.chol(mat.numCols);
if( solver.modifiesA() )
mat = mat.copy();
if( !solver.setA(mat))
return false;
solver.invert(result);
}
return true;
} | java | public static boolean invertSPD(DMatrixRMaj mat, DMatrixRMaj result ) {
if( mat.numRows != mat.numCols )
throw new IllegalArgumentException("Must be a square matrix");
result.reshape(mat.numRows,mat.numRows);
if( mat.numRows <= UnrolledCholesky_DDRM.MAX ) {
// L*L' = A
if( !UnrolledCholesky_DDRM.lower(mat,result) )
return false;
// L = inv(L)
TriangularSolver_DDRM.invertLower(result.data,result.numCols);
// inv(A) = inv(L')*inv(L)
SpecializedOps_DDRM.multLowerTranA(result);
} else {
LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.chol(mat.numCols);
if( solver.modifiesA() )
mat = mat.copy();
if( !solver.setA(mat))
return false;
solver.invert(result);
}
return true;
} | [
"public",
"static",
"boolean",
"invertSPD",
"(",
"DMatrixRMaj",
"mat",
",",
"DMatrixRMaj",
"result",
")",
"{",
"if",
"(",
"mat",
".",
"numRows",
"!=",
"mat",
".",
"numCols",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Must be a square matrix\"",
")",
";",
"result",
".",
"reshape",
"(",
"mat",
".",
"numRows",
",",
"mat",
".",
"numRows",
")",
";",
"if",
"(",
"mat",
".",
"numRows",
"<=",
"UnrolledCholesky_DDRM",
".",
"MAX",
")",
"{",
"// L*L' = A",
"if",
"(",
"!",
"UnrolledCholesky_DDRM",
".",
"lower",
"(",
"mat",
",",
"result",
")",
")",
"return",
"false",
";",
"// L = inv(L)",
"TriangularSolver_DDRM",
".",
"invertLower",
"(",
"result",
".",
"data",
",",
"result",
".",
"numCols",
")",
";",
"// inv(A) = inv(L')*inv(L)",
"SpecializedOps_DDRM",
".",
"multLowerTranA",
"(",
"result",
")",
";",
"}",
"else",
"{",
"LinearSolverDense",
"<",
"DMatrixRMaj",
">",
"solver",
"=",
"LinearSolverFactory_DDRM",
".",
"chol",
"(",
"mat",
".",
"numCols",
")",
";",
"if",
"(",
"solver",
".",
"modifiesA",
"(",
")",
")",
"mat",
"=",
"mat",
".",
"copy",
"(",
")",
";",
"if",
"(",
"!",
"solver",
".",
"setA",
"(",
"mat",
")",
")",
"return",
"false",
";",
"solver",
".",
"invert",
"(",
"result",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Matrix inverse for symmetric positive definite matrices. For small matrices an unrolled
cholesky is used. Otherwise a standard decomposition.
@see UnrolledCholesky_DDRM
@see LinearSolverFactory_DDRM#chol(int)
@param mat (Input) SPD matrix
@param result (Output) Inverted matrix.
@return true if it could invert the matrix false if it could not. | [
"Matrix",
"inverse",
"for",
"symmetric",
"positive",
"definite",
"matrices",
".",
"For",
"small",
"matrices",
"an",
"unrolled",
"cholesky",
"is",
"used",
".",
"Otherwise",
"a",
"standard",
"decomposition",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L818-L842 |
162,522 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.identity | public static DMatrixRMaj identity(int numRows , int numCols )
{
DMatrixRMaj ret = new DMatrixRMaj(numRows,numCols);
int small = numRows < numCols ? numRows : numCols;
for( int i = 0; i < small; i++ ) {
ret.set(i,i,1.0);
}
return ret;
} | java | public static DMatrixRMaj identity(int numRows , int numCols )
{
DMatrixRMaj ret = new DMatrixRMaj(numRows,numCols);
int small = numRows < numCols ? numRows : numCols;
for( int i = 0; i < small; i++ ) {
ret.set(i,i,1.0);
}
return ret;
} | [
"public",
"static",
"DMatrixRMaj",
"identity",
"(",
"int",
"numRows",
",",
"int",
"numCols",
")",
"{",
"DMatrixRMaj",
"ret",
"=",
"new",
"DMatrixRMaj",
"(",
"numRows",
",",
"numCols",
")",
";",
"int",
"small",
"=",
"numRows",
"<",
"numCols",
"?",
"numRows",
":",
"numCols",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"small",
";",
"i",
"++",
")",
"{",
"ret",
".",
"set",
"(",
"i",
",",
"i",
",",
"1.0",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Creates a rectangular matrix which is zero except along the diagonals.
@param numRows Number of rows in the matrix.
@param numCols NUmber of columns in the matrix.
@return A matrix with diagonal elements equal to one. | [
"Creates",
"a",
"rectangular",
"matrix",
"which",
"is",
"zero",
"except",
"along",
"the",
"diagonals",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L987-L998 |
162,523 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.extract | public static void extract( DMatrix src,
int srcY0, int srcY1,
int srcX0, int srcX1,
DMatrix dst ) {
((ReshapeMatrix)dst).reshape(srcY1-srcY0,srcX1-srcX0);
extract(src,srcY0,srcY1,srcX0,srcX1,dst,0,0);
} | java | public static void extract( DMatrix src,
int srcY0, int srcY1,
int srcX0, int srcX1,
DMatrix dst ) {
((ReshapeMatrix)dst).reshape(srcY1-srcY0,srcX1-srcX0);
extract(src,srcY0,srcY1,srcX0,srcX1,dst,0,0);
} | [
"public",
"static",
"void",
"extract",
"(",
"DMatrix",
"src",
",",
"int",
"srcY0",
",",
"int",
"srcY1",
",",
"int",
"srcX0",
",",
"int",
"srcX1",
",",
"DMatrix",
"dst",
")",
"{",
"(",
"(",
"ReshapeMatrix",
")",
"dst",
")",
".",
"reshape",
"(",
"srcY1",
"-",
"srcY0",
",",
"srcX1",
"-",
"srcX0",
")",
";",
"extract",
"(",
"src",
",",
"srcY0",
",",
"srcY1",
",",
"srcX0",
",",
"srcX1",
",",
"dst",
",",
"0",
",",
"0",
")",
";",
"}"
] | Extract where the destination is reshaped to match the extracted region
@param src The original matrix which is to be copied. Not modified.
@param srcX0 Start column.
@param srcX1 Stop column+1.
@param srcY0 Start row.
@param srcY1 Stop row+1.
@param dst Where the submatrix are stored. Modified. | [
"Extract",
"where",
"the",
"destination",
"is",
"reshaped",
"to",
"match",
"the",
"extracted",
"region"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1163-L1169 |
162,524 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.extract | public static void extract( DMatrixRMaj src,
int rows[] , int rowsSize ,
int cols[] , int colsSize , DMatrixRMaj dst ) {
if( rowsSize != dst.numRows || colsSize != dst.numCols )
throw new MatrixDimensionException("Unexpected number of rows and/or columns in dst matrix");
int indexDst = 0;
for (int i = 0; i < rowsSize; i++) {
int indexSrcRow = src.numCols*rows[i];
for (int j = 0; j < colsSize; j++) {
dst.data[indexDst++] = src.data[indexSrcRow + cols[j]];
}
}
} | java | public static void extract( DMatrixRMaj src,
int rows[] , int rowsSize ,
int cols[] , int colsSize , DMatrixRMaj dst ) {
if( rowsSize != dst.numRows || colsSize != dst.numCols )
throw new MatrixDimensionException("Unexpected number of rows and/or columns in dst matrix");
int indexDst = 0;
for (int i = 0; i < rowsSize; i++) {
int indexSrcRow = src.numCols*rows[i];
for (int j = 0; j < colsSize; j++) {
dst.data[indexDst++] = src.data[indexSrcRow + cols[j]];
}
}
} | [
"public",
"static",
"void",
"extract",
"(",
"DMatrixRMaj",
"src",
",",
"int",
"rows",
"[",
"]",
",",
"int",
"rowsSize",
",",
"int",
"cols",
"[",
"]",
",",
"int",
"colsSize",
",",
"DMatrixRMaj",
"dst",
")",
"{",
"if",
"(",
"rowsSize",
"!=",
"dst",
".",
"numRows",
"||",
"colsSize",
"!=",
"dst",
".",
"numCols",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Unexpected number of rows and/or columns in dst matrix\"",
")",
";",
"int",
"indexDst",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"rowsSize",
";",
"i",
"++",
")",
"{",
"int",
"indexSrcRow",
"=",
"src",
".",
"numCols",
"*",
"rows",
"[",
"i",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"colsSize",
";",
"j",
"++",
")",
"{",
"dst",
".",
"data",
"[",
"indexDst",
"++",
"]",
"=",
"src",
".",
"data",
"[",
"indexSrcRow",
"+",
"cols",
"[",
"j",
"]",
"]",
";",
"}",
"}",
"}"
] | Extracts out a matrix from source given a sub matrix with arbitrary rows and columns specified in
two array lists
@param src Source matrix. Not modified.
@param rows array of row indexes
@param rowsSize maximum element in row array
@param cols array of column indexes
@param colsSize maximum element in column array
@param dst output matrix. Must be correct shape. | [
"Extracts",
"out",
"a",
"matrix",
"from",
"source",
"given",
"a",
"sub",
"matrix",
"with",
"arbitrary",
"rows",
"and",
"columns",
"specified",
"in",
"two",
"array",
"lists"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1236-L1249 |
162,525 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.extract | public static void extract(DMatrixRMaj src, int indexes[] , int length , DMatrixRMaj dst ) {
if( !MatrixFeatures_DDRM.isVector(dst))
throw new MatrixDimensionException("Dst must be a vector");
if( length != dst.getNumElements())
throw new MatrixDimensionException("Unexpected number of elements in dst vector");
for (int i = 0; i < length; i++) {
dst.data[i] = src.data[indexes[i]];
}
} | java | public static void extract(DMatrixRMaj src, int indexes[] , int length , DMatrixRMaj dst ) {
if( !MatrixFeatures_DDRM.isVector(dst))
throw new MatrixDimensionException("Dst must be a vector");
if( length != dst.getNumElements())
throw new MatrixDimensionException("Unexpected number of elements in dst vector");
for (int i = 0; i < length; i++) {
dst.data[i] = src.data[indexes[i]];
}
} | [
"public",
"static",
"void",
"extract",
"(",
"DMatrixRMaj",
"src",
",",
"int",
"indexes",
"[",
"]",
",",
"int",
"length",
",",
"DMatrixRMaj",
"dst",
")",
"{",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isVector",
"(",
"dst",
")",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Dst must be a vector\"",
")",
";",
"if",
"(",
"length",
"!=",
"dst",
".",
"getNumElements",
"(",
")",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Unexpected number of elements in dst vector\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"dst",
".",
"data",
"[",
"i",
"]",
"=",
"src",
".",
"data",
"[",
"indexes",
"[",
"i",
"]",
"]",
";",
"}",
"}"
] | Extracts the elements from the source matrix by their 1D index.
@param src Source matrix. Not modified.
@param indexes array of row indexes
@param length maximum element in row array
@param dst output matrix. Must be a vector of the correct length. | [
"Extracts",
"the",
"elements",
"from",
"the",
"source",
"matrix",
"by",
"their",
"1D",
"index",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1259-L1268 |
162,526 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.extractRow | public static DMatrixRMaj extractRow(DMatrixRMaj a , int row , DMatrixRMaj out ) {
if( out == null)
out = new DMatrixRMaj(1,a.numCols);
else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numCols )
throw new MatrixDimensionException("Output must be a vector of length "+a.numCols);
System.arraycopy(a.data,a.getIndex(row,0),out.data,0,a.numCols);
return out;
} | java | public static DMatrixRMaj extractRow(DMatrixRMaj a , int row , DMatrixRMaj out ) {
if( out == null)
out = new DMatrixRMaj(1,a.numCols);
else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numCols )
throw new MatrixDimensionException("Output must be a vector of length "+a.numCols);
System.arraycopy(a.data,a.getIndex(row,0),out.data,0,a.numCols);
return out;
} | [
"public",
"static",
"DMatrixRMaj",
"extractRow",
"(",
"DMatrixRMaj",
"a",
",",
"int",
"row",
",",
"DMatrixRMaj",
"out",
")",
"{",
"if",
"(",
"out",
"==",
"null",
")",
"out",
"=",
"new",
"DMatrixRMaj",
"(",
"1",
",",
"a",
".",
"numCols",
")",
";",
"else",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isVector",
"(",
"out",
")",
"||",
"out",
".",
"getNumElements",
"(",
")",
"!=",
"a",
".",
"numCols",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Output must be a vector of length \"",
"+",
"a",
".",
"numCols",
")",
";",
"System",
".",
"arraycopy",
"(",
"a",
".",
"data",
",",
"a",
".",
"getIndex",
"(",
"row",
",",
"0",
")",
",",
"out",
".",
"data",
",",
"0",
",",
"a",
".",
"numCols",
")",
";",
"return",
"out",
";",
"}"
] | Extracts the row from a matrix.
@param a Input matrix
@param row Which row is to be extracted
@param out output. Storage for the extracted row. If null then a new vector will be returned.
@return The extracted row. | [
"Extracts",
"the",
"row",
"from",
"a",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1330-L1339 |
162,527 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.extractColumn | public static DMatrixRMaj extractColumn(DMatrixRMaj a , int column , DMatrixRMaj out ) {
if( out == null)
out = new DMatrixRMaj(a.numRows,1);
else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numRows )
throw new MatrixDimensionException("Output must be a vector of length "+a.numRows);
int index = column;
for (int i = 0; i < a.numRows; i++, index += a.numCols ) {
out.data[i] = a.data[index];
}
return out;
} | java | public static DMatrixRMaj extractColumn(DMatrixRMaj a , int column , DMatrixRMaj out ) {
if( out == null)
out = new DMatrixRMaj(a.numRows,1);
else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numRows )
throw new MatrixDimensionException("Output must be a vector of length "+a.numRows);
int index = column;
for (int i = 0; i < a.numRows; i++, index += a.numCols ) {
out.data[i] = a.data[index];
}
return out;
} | [
"public",
"static",
"DMatrixRMaj",
"extractColumn",
"(",
"DMatrixRMaj",
"a",
",",
"int",
"column",
",",
"DMatrixRMaj",
"out",
")",
"{",
"if",
"(",
"out",
"==",
"null",
")",
"out",
"=",
"new",
"DMatrixRMaj",
"(",
"a",
".",
"numRows",
",",
"1",
")",
";",
"else",
"if",
"(",
"!",
"MatrixFeatures_DDRM",
".",
"isVector",
"(",
"out",
")",
"||",
"out",
".",
"getNumElements",
"(",
")",
"!=",
"a",
".",
"numRows",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Output must be a vector of length \"",
"+",
"a",
".",
"numRows",
")",
";",
"int",
"index",
"=",
"column",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"numRows",
";",
"i",
"++",
",",
"index",
"+=",
"a",
".",
"numCols",
")",
"{",
"out",
".",
"data",
"[",
"i",
"]",
"=",
"a",
".",
"data",
"[",
"index",
"]",
";",
"}",
"return",
"out",
";",
"}"
] | Extracts the column from a matrix.
@param a Input matrix
@param column Which column is to be extracted
@param out output. Storage for the extracted column. If null then a new vector will be returned.
@return The extracted column. | [
"Extracts",
"the",
"column",
"from",
"a",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1348-L1359 |
162,528 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.removeColumns | public static void removeColumns( DMatrixRMaj A , int col0 , int col1 )
{
if( col1 < col0 ) {
throw new IllegalArgumentException("col1 must be >= col0");
} else if( col0 >= A.numCols || col1 >= A.numCols ) {
throw new IllegalArgumentException("Columns which are to be removed must be in bounds");
}
int step = col1-col0+1;
int offset = 0;
for (int row = 0, idx=0; row < A.numRows; row++) {
for (int i = 0; i < col0; i++,idx++) {
A.data[idx] = A.data[idx+offset];
}
offset += step;
for (int i = col1+1; i < A.numCols; i++,idx++) {
A.data[idx] = A.data[idx+offset];
}
}
A.numCols -= step;
} | java | public static void removeColumns( DMatrixRMaj A , int col0 , int col1 )
{
if( col1 < col0 ) {
throw new IllegalArgumentException("col1 must be >= col0");
} else if( col0 >= A.numCols || col1 >= A.numCols ) {
throw new IllegalArgumentException("Columns which are to be removed must be in bounds");
}
int step = col1-col0+1;
int offset = 0;
for (int row = 0, idx=0; row < A.numRows; row++) {
for (int i = 0; i < col0; i++,idx++) {
A.data[idx] = A.data[idx+offset];
}
offset += step;
for (int i = col1+1; i < A.numCols; i++,idx++) {
A.data[idx] = A.data[idx+offset];
}
}
A.numCols -= step;
} | [
"public",
"static",
"void",
"removeColumns",
"(",
"DMatrixRMaj",
"A",
",",
"int",
"col0",
",",
"int",
"col1",
")",
"{",
"if",
"(",
"col1",
"<",
"col0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"col1 must be >= col0\"",
")",
";",
"}",
"else",
"if",
"(",
"col0",
">=",
"A",
".",
"numCols",
"||",
"col1",
">=",
"A",
".",
"numCols",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Columns which are to be removed must be in bounds\"",
")",
";",
"}",
"int",
"step",
"=",
"col1",
"-",
"col0",
"+",
"1",
";",
"int",
"offset",
"=",
"0",
";",
"for",
"(",
"int",
"row",
"=",
"0",
",",
"idx",
"=",
"0",
";",
"row",
"<",
"A",
".",
"numRows",
";",
"row",
"++",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"col0",
";",
"i",
"++",
",",
"idx",
"++",
")",
"{",
"A",
".",
"data",
"[",
"idx",
"]",
"=",
"A",
".",
"data",
"[",
"idx",
"+",
"offset",
"]",
";",
"}",
"offset",
"+=",
"step",
";",
"for",
"(",
"int",
"i",
"=",
"col1",
"+",
"1",
";",
"i",
"<",
"A",
".",
"numCols",
";",
"i",
"++",
",",
"idx",
"++",
")",
"{",
"A",
".",
"data",
"[",
"idx",
"]",
"=",
"A",
".",
"data",
"[",
"idx",
"+",
"offset",
"]",
";",
"}",
"}",
"A",
".",
"numCols",
"-=",
"step",
";",
"}"
] | Removes columns from the matrix.
@param A Matrix. Modified
@param col0 First column
@param col1 Last column, inclusive. | [
"Removes",
"columns",
"from",
"the",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L1368-L1388 |
162,529 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.scaleRow | public static void scaleRow( double alpha , DMatrixRMaj A , int row ) {
int idx = row*A.numCols;
for (int col = 0; col < A.numCols; col++) {
A.data[idx++] *= alpha;
}
} | java | public static void scaleRow( double alpha , DMatrixRMaj A , int row ) {
int idx = row*A.numCols;
for (int col = 0; col < A.numCols; col++) {
A.data[idx++] *= alpha;
}
} | [
"public",
"static",
"void",
"scaleRow",
"(",
"double",
"alpha",
",",
"DMatrixRMaj",
"A",
",",
"int",
"row",
")",
"{",
"int",
"idx",
"=",
"row",
"*",
"A",
".",
"numCols",
";",
"for",
"(",
"int",
"col",
"=",
"0",
";",
"col",
"<",
"A",
".",
"numCols",
";",
"col",
"++",
")",
"{",
"A",
".",
"data",
"[",
"idx",
"++",
"]",
"*=",
"alpha",
";",
"}",
"}"
] | In-place scaling of a row in A
@param alpha scale factor
@param A matrix
@param row which row in A | [
"In",
"-",
"place",
"scaling",
"of",
"a",
"row",
"in",
"A"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2398-L2403 |
162,530 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.scaleCol | public static void scaleCol( double alpha , DMatrixRMaj A , int col ) {
int idx = col;
for (int row = 0; row < A.numRows; row++, idx += A.numCols) {
A.data[idx] *= alpha;
}
} | java | public static void scaleCol( double alpha , DMatrixRMaj A , int col ) {
int idx = col;
for (int row = 0; row < A.numRows; row++, idx += A.numCols) {
A.data[idx] *= alpha;
}
} | [
"public",
"static",
"void",
"scaleCol",
"(",
"double",
"alpha",
",",
"DMatrixRMaj",
"A",
",",
"int",
"col",
")",
"{",
"int",
"idx",
"=",
"col",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<",
"A",
".",
"numRows",
";",
"row",
"++",
",",
"idx",
"+=",
"A",
".",
"numCols",
")",
"{",
"A",
".",
"data",
"[",
"idx",
"]",
"*=",
"alpha",
";",
"}",
"}"
] | In-place scaling of a column in A
@param alpha scale factor
@param A matrix
@param col which row in A | [
"In",
"-",
"place",
"scaling",
"of",
"a",
"column",
"in",
"A"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2412-L2417 |
162,531 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.elementLessThan | public static BMatrixRMaj elementLessThan(DMatrixRMaj A , double value , BMatrixRMaj output )
{
if( output == null ) {
output = new BMatrixRMaj(A.numRows,A.numCols);
}
output.reshape(A.numRows, A.numCols);
int N = A.getNumElements();
for (int i = 0; i < N; i++) {
output.data[i] = A.data[i] < value;
}
return output;
} | java | public static BMatrixRMaj elementLessThan(DMatrixRMaj A , double value , BMatrixRMaj output )
{
if( output == null ) {
output = new BMatrixRMaj(A.numRows,A.numCols);
}
output.reshape(A.numRows, A.numCols);
int N = A.getNumElements();
for (int i = 0; i < N; i++) {
output.data[i] = A.data[i] < value;
}
return output;
} | [
"public",
"static",
"BMatrixRMaj",
"elementLessThan",
"(",
"DMatrixRMaj",
"A",
",",
"double",
"value",
",",
"BMatrixRMaj",
"output",
")",
"{",
"if",
"(",
"output",
"==",
"null",
")",
"{",
"output",
"=",
"new",
"BMatrixRMaj",
"(",
"A",
".",
"numRows",
",",
"A",
".",
"numCols",
")",
";",
"}",
"output",
".",
"reshape",
"(",
"A",
".",
"numRows",
",",
"A",
".",
"numCols",
")",
";",
"int",
"N",
"=",
"A",
".",
"getNumElements",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"output",
".",
"data",
"[",
"i",
"]",
"=",
"A",
".",
"data",
"[",
"i",
"]",
"<",
"value",
";",
"}",
"return",
"output",
";",
"}"
] | Applies the > operator to each element in A. Results are stored in a boolean matrix.
@param A Input matrx
@param value value each element is compared against
@param output (Optional) Storage for results. Can be null. Is reshaped.
@return Boolean matrix with results | [
"Applies",
"the",
">",
";",
"operator",
"to",
"each",
"element",
"in",
"A",
".",
"Results",
"are",
"stored",
"in",
"a",
"boolean",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2604-L2619 |
162,532 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.elements | public static DMatrixRMaj elements(DMatrixRMaj A , BMatrixRMaj marked , DMatrixRMaj output ) {
if( A.numRows != marked.numRows || A.numCols != marked.numCols )
throw new MatrixDimensionException("Input matrices must have the same shape");
if( output == null )
output = new DMatrixRMaj(1,1);
output.reshape(countTrue(marked),1);
int N = A.getNumElements();
int index = 0;
for (int i = 0; i < N; i++) {
if( marked.data[i] ) {
output.data[index++] = A.data[i];
}
}
return output;
} | java | public static DMatrixRMaj elements(DMatrixRMaj A , BMatrixRMaj marked , DMatrixRMaj output ) {
if( A.numRows != marked.numRows || A.numCols != marked.numCols )
throw new MatrixDimensionException("Input matrices must have the same shape");
if( output == null )
output = new DMatrixRMaj(1,1);
output.reshape(countTrue(marked),1);
int N = A.getNumElements();
int index = 0;
for (int i = 0; i < N; i++) {
if( marked.data[i] ) {
output.data[index++] = A.data[i];
}
}
return output;
} | [
"public",
"static",
"DMatrixRMaj",
"elements",
"(",
"DMatrixRMaj",
"A",
",",
"BMatrixRMaj",
"marked",
",",
"DMatrixRMaj",
"output",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"!=",
"marked",
".",
"numRows",
"||",
"A",
".",
"numCols",
"!=",
"marked",
".",
"numCols",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Input matrices must have the same shape\"",
")",
";",
"if",
"(",
"output",
"==",
"null",
")",
"output",
"=",
"new",
"DMatrixRMaj",
"(",
"1",
",",
"1",
")",
";",
"output",
".",
"reshape",
"(",
"countTrue",
"(",
"marked",
")",
",",
"1",
")",
";",
"int",
"N",
"=",
"A",
".",
"getNumElements",
"(",
")",
";",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"if",
"(",
"marked",
".",
"data",
"[",
"i",
"]",
")",
"{",
"output",
".",
"data",
"[",
"index",
"++",
"]",
"=",
"A",
".",
"data",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"output",
";",
"}"
] | Returns a row matrix which contains all the elements in A which are flagged as true in 'marked'
@param A Input matrix
@param marked Input matrix marking elements in A
@param output Storage for output row vector. Can be null. Will be reshaped.
@return Row vector with marked elements | [
"Returns",
"a",
"row",
"matrix",
"which",
"contains",
"all",
"the",
"elements",
"in",
"A",
"which",
"are",
"flagged",
"as",
"true",
"in",
"marked"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2754-L2772 |
162,533 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.countTrue | public static int countTrue(BMatrixRMaj A) {
int total = 0;
int N = A.getNumElements();
for (int i = 0; i < N; i++) {
if( A.data[i] )
total++;
}
return total;
} | java | public static int countTrue(BMatrixRMaj A) {
int total = 0;
int N = A.getNumElements();
for (int i = 0; i < N; i++) {
if( A.data[i] )
total++;
}
return total;
} | [
"public",
"static",
"int",
"countTrue",
"(",
"BMatrixRMaj",
"A",
")",
"{",
"int",
"total",
"=",
"0",
";",
"int",
"N",
"=",
"A",
".",
"getNumElements",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"if",
"(",
"A",
".",
"data",
"[",
"i",
"]",
")",
"total",
"++",
";",
"}",
"return",
"total",
";",
"}"
] | Counts the number of elements in A which are true
@param A input matrix
@return number of true elements | [
"Counts",
"the",
"number",
"of",
"elements",
"in",
"A",
"which",
"are",
"true"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2779-L2790 |
162,534 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java | CommonOps_DDRM.symmLowerToFull | public static void symmLowerToFull( DMatrixRMaj A )
{
if( A.numRows != A.numCols )
throw new MatrixDimensionException("Must be a square matrix");
final int cols = A.numCols;
for (int row = 0; row < A.numRows; row++) {
for (int col = row+1; col < cols; col++) {
A.data[row*cols+col] = A.data[col*cols+row];
}
}
} | java | public static void symmLowerToFull( DMatrixRMaj A )
{
if( A.numRows != A.numCols )
throw new MatrixDimensionException("Must be a square matrix");
final int cols = A.numCols;
for (int row = 0; row < A.numRows; row++) {
for (int col = row+1; col < cols; col++) {
A.data[row*cols+col] = A.data[col*cols+row];
}
}
} | [
"public",
"static",
"void",
"symmLowerToFull",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"!=",
"A",
".",
"numCols",
")",
"throw",
"new",
"MatrixDimensionException",
"(",
"\"Must be a square matrix\"",
")",
";",
"final",
"int",
"cols",
"=",
"A",
".",
"numCols",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<",
"A",
".",
"numRows",
";",
"row",
"++",
")",
"{",
"for",
"(",
"int",
"col",
"=",
"row",
"+",
"1",
";",
"col",
"<",
"cols",
";",
"col",
"++",
")",
"{",
"A",
".",
"data",
"[",
"row",
"*",
"cols",
"+",
"col",
"]",
"=",
"A",
".",
"data",
"[",
"col",
"*",
"cols",
"+",
"row",
"]",
";",
"}",
"}",
"}"
] | Given a symmetric matrix which is represented by a lower triangular matrix convert it back into
a full symmetric matrix.
@param A (Input) Lower triangular matrix (Output) symmetric matrix | [
"Given",
"a",
"symmetric",
"matrix",
"which",
"is",
"represented",
"by",
"a",
"lower",
"triangular",
"matrix",
"convert",
"it",
"back",
"into",
"a",
"full",
"symmetric",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CommonOps_DDRM.java#L2942-L2954 |
162,535 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/hessenberg/TridiagonalDecompositionHouseholderOrig_DDRM.java | TridiagonalDecompositionHouseholderOrig_DDRM.init | public void init( DMatrixRMaj A ) {
if( A.numRows != A.numCols)
throw new IllegalArgumentException("Must be square");
if( A.numCols != N ) {
N = A.numCols;
QT.reshape(N,N, false);
if( w.length < N ) {
w = new double[ N ];
gammas = new double[N];
b = new double[N];
}
}
// just copy the top right triangle
QT.set(A);
} | java | public void init( DMatrixRMaj A ) {
if( A.numRows != A.numCols)
throw new IllegalArgumentException("Must be square");
if( A.numCols != N ) {
N = A.numCols;
QT.reshape(N,N, false);
if( w.length < N ) {
w = new double[ N ];
gammas = new double[N];
b = new double[N];
}
}
// just copy the top right triangle
QT.set(A);
} | [
"public",
"void",
"init",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"!=",
"A",
".",
"numCols",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Must be square\"",
")",
";",
"if",
"(",
"A",
".",
"numCols",
"!=",
"N",
")",
"{",
"N",
"=",
"A",
".",
"numCols",
";",
"QT",
".",
"reshape",
"(",
"N",
",",
"N",
",",
"false",
")",
";",
"if",
"(",
"w",
".",
"length",
"<",
"N",
")",
"{",
"w",
"=",
"new",
"double",
"[",
"N",
"]",
";",
"gammas",
"=",
"new",
"double",
"[",
"N",
"]",
";",
"b",
"=",
"new",
"double",
"[",
"N",
"]",
";",
"}",
"}",
"// just copy the top right triangle",
"QT",
".",
"set",
"(",
"A",
")",
";",
"}"
] | If needed declares and sets up internal data structures.
@param A Matrix being decomposed. | [
"If",
"needed",
"declares",
"and",
"sets",
"up",
"internal",
"data",
"structures",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/hessenberg/TridiagonalDecompositionHouseholderOrig_DDRM.java#L240-L257 |
162,536 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/mult/MatrixMultProduct_DDRM.java | MatrixMultProduct_DDRM.inner_reorder_lower | public static void inner_reorder_lower(DMatrix1Row A , DMatrix1Row B )
{
final int cols = A.numCols;
B.reshape(cols,cols);
Arrays.fill(B.data,0);
for (int i = 0; i <cols; i++) {
for (int j = 0; j <=i; j++) {
B.data[i*cols+j] += A.data[i]*A.data[j];
}
for (int k = 1; k < A.numRows; k++) {
int indexRow = k*cols;
double valI = A.data[i+indexRow];
int indexB = i*cols;
for (int j = 0; j <= i; j++) {
B.data[indexB++] += valI*A.data[indexRow++];
}
}
}
} | java | public static void inner_reorder_lower(DMatrix1Row A , DMatrix1Row B )
{
final int cols = A.numCols;
B.reshape(cols,cols);
Arrays.fill(B.data,0);
for (int i = 0; i <cols; i++) {
for (int j = 0; j <=i; j++) {
B.data[i*cols+j] += A.data[i]*A.data[j];
}
for (int k = 1; k < A.numRows; k++) {
int indexRow = k*cols;
double valI = A.data[i+indexRow];
int indexB = i*cols;
for (int j = 0; j <= i; j++) {
B.data[indexB++] += valI*A.data[indexRow++];
}
}
}
} | [
"public",
"static",
"void",
"inner_reorder_lower",
"(",
"DMatrix1Row",
"A",
",",
"DMatrix1Row",
"B",
")",
"{",
"final",
"int",
"cols",
"=",
"A",
".",
"numCols",
";",
"B",
".",
"reshape",
"(",
"cols",
",",
"cols",
")",
";",
"Arrays",
".",
"fill",
"(",
"B",
".",
"data",
",",
"0",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"cols",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<=",
"i",
";",
"j",
"++",
")",
"{",
"B",
".",
"data",
"[",
"i",
"*",
"cols",
"+",
"j",
"]",
"+=",
"A",
".",
"data",
"[",
"i",
"]",
"*",
"A",
".",
"data",
"[",
"j",
"]",
";",
"}",
"for",
"(",
"int",
"k",
"=",
"1",
";",
"k",
"<",
"A",
".",
"numRows",
";",
"k",
"++",
")",
"{",
"int",
"indexRow",
"=",
"k",
"*",
"cols",
";",
"double",
"valI",
"=",
"A",
".",
"data",
"[",
"i",
"+",
"indexRow",
"]",
";",
"int",
"indexB",
"=",
"i",
"*",
"cols",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<=",
"i",
";",
"j",
"++",
")",
"{",
"B",
".",
"data",
"[",
"indexB",
"++",
"]",
"+=",
"valI",
"*",
"A",
".",
"data",
"[",
"indexRow",
"++",
"]",
";",
"}",
"}",
"}",
"}"
] | Computes the inner product of A times A and stores the results in B. The inner product is symmetric and this
function will only store the lower triangle. The value of the upper triangular matrix is undefined.
<p>B = A<sup>T</sup>*A</sup>
@param A (Input) Matrix
@param B (Output) Storage for output. | [
"Computes",
"the",
"inner",
"product",
"of",
"A",
"times",
"A",
"and",
"stores",
"the",
"results",
"in",
"B",
".",
"The",
"inner",
"product",
"is",
"symmetric",
"and",
"this",
"function",
"will",
"only",
"store",
"the",
"lower",
"triangle",
".",
"The",
"value",
"of",
"the",
"upper",
"triangular",
"matrix",
"is",
"undefined",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/mult/MatrixMultProduct_DDRM.java#L162-L182 |
162,537 | lessthanoptimal/ejml | main/ejml-core/src/org/ejml/ops/ComplexMath_F64.java | ComplexMath_F64.pow | public static void pow(ComplexPolar_F64 a , int N , ComplexPolar_F64 result )
{
result.r = Math.pow(a.r,N);
result.theta = N*a.theta;
} | java | public static void pow(ComplexPolar_F64 a , int N , ComplexPolar_F64 result )
{
result.r = Math.pow(a.r,N);
result.theta = N*a.theta;
} | [
"public",
"static",
"void",
"pow",
"(",
"ComplexPolar_F64",
"a",
",",
"int",
"N",
",",
"ComplexPolar_F64",
"result",
")",
"{",
"result",
".",
"r",
"=",
"Math",
".",
"pow",
"(",
"a",
".",
"r",
",",
"N",
")",
";",
"result",
".",
"theta",
"=",
"N",
"*",
"a",
".",
"theta",
";",
"}"
] | Computes the power of a complex number in polar notation
@param a Complex number
@param N Power it is to be multiplied by
@param result Result | [
"Computes",
"the",
"power",
"of",
"a",
"complex",
"number",
"in",
"polar",
"notation"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/ops/ComplexMath_F64.java#L159-L163 |
162,538 | lessthanoptimal/ejml | main/ejml-core/src/org/ejml/ops/ComplexMath_F64.java | ComplexMath_F64.sqrt | public static void sqrt(Complex_F64 input, Complex_F64 root)
{
double r = input.getMagnitude();
double a = input.real;
root.real = Math.sqrt((r+a)/2.0);
root.imaginary = Math.sqrt((r-a)/2.0);
if( input.imaginary < 0 )
root.imaginary = -root.imaginary;
} | java | public static void sqrt(Complex_F64 input, Complex_F64 root)
{
double r = input.getMagnitude();
double a = input.real;
root.real = Math.sqrt((r+a)/2.0);
root.imaginary = Math.sqrt((r-a)/2.0);
if( input.imaginary < 0 )
root.imaginary = -root.imaginary;
} | [
"public",
"static",
"void",
"sqrt",
"(",
"Complex_F64",
"input",
",",
"Complex_F64",
"root",
")",
"{",
"double",
"r",
"=",
"input",
".",
"getMagnitude",
"(",
")",
";",
"double",
"a",
"=",
"input",
".",
"real",
";",
"root",
".",
"real",
"=",
"Math",
".",
"sqrt",
"(",
"(",
"r",
"+",
"a",
")",
"/",
"2.0",
")",
";",
"root",
".",
"imaginary",
"=",
"Math",
".",
"sqrt",
"(",
"(",
"r",
"-",
"a",
")",
"/",
"2.0",
")",
";",
"if",
"(",
"input",
".",
"imaginary",
"<",
"0",
")",
"root",
".",
"imaginary",
"=",
"-",
"root",
".",
"imaginary",
";",
"}"
] | Computes the square root of the complex number.
@param input Input complex number.
@param root Output. The square root of the input | [
"Computes",
"the",
"square",
"root",
"of",
"the",
"complex",
"number",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/ops/ComplexMath_F64.java#L207-L216 |
162,539 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/EigenPowerMethod_DDRM.java | EigenPowerMethod_DDRM.computeDirect | public boolean computeDirect( DMatrixRMaj A ) {
initPower(A);
boolean converged = false;
for( int i = 0; i < maxIterations && !converged; i++ ) {
// q0.print();
CommonOps_DDRM.mult(A,q0,q1);
double s = NormOps_DDRM.normPInf(q1);
CommonOps_DDRM.divide(q1,s,q2);
converged = checkConverged(A);
}
return converged;
} | java | public boolean computeDirect( DMatrixRMaj A ) {
initPower(A);
boolean converged = false;
for( int i = 0; i < maxIterations && !converged; i++ ) {
// q0.print();
CommonOps_DDRM.mult(A,q0,q1);
double s = NormOps_DDRM.normPInf(q1);
CommonOps_DDRM.divide(q1,s,q2);
converged = checkConverged(A);
}
return converged;
} | [
"public",
"boolean",
"computeDirect",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"initPower",
"(",
"A",
")",
";",
"boolean",
"converged",
"=",
"false",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"maxIterations",
"&&",
"!",
"converged",
";",
"i",
"++",
")",
"{",
"// q0.print();",
"CommonOps_DDRM",
".",
"mult",
"(",
"A",
",",
"q0",
",",
"q1",
")",
";",
"double",
"s",
"=",
"NormOps_DDRM",
".",
"normPInf",
"(",
"q1",
")",
";",
"CommonOps_DDRM",
".",
"divide",
"(",
"q1",
",",
"s",
",",
"q2",
")",
";",
"converged",
"=",
"checkConverged",
"(",
"A",
")",
";",
"}",
"return",
"converged",
";",
"}"
] | This method computes the eigen vector with the largest eigen value by using the
direct power method. This technique is the easiest to implement, but the slowest to converge.
Works only if all the eigenvalues are real.
@param A The matrix. Not modified.
@return If it converged or not. | [
"This",
"method",
"computes",
"the",
"eigen",
"vector",
"with",
"the",
"largest",
"eigen",
"value",
"by",
"using",
"the",
"direct",
"power",
"method",
".",
"This",
"technique",
"is",
"the",
"easiest",
"to",
"implement",
"but",
"the",
"slowest",
"to",
"converge",
".",
"Works",
"only",
"if",
"all",
"the",
"eigenvalues",
"are",
"real",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/EigenPowerMethod_DDRM.java#L107-L124 |
162,540 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/EigenPowerMethod_DDRM.java | EigenPowerMethod_DDRM.checkConverged | private boolean checkConverged(DMatrixRMaj A) {
double worst = 0;
double worst2 = 0;
for( int j = 0; j < A.numRows; j++ ) {
double val = Math.abs(q2.data[j] - q0.data[j]);
if( val > worst ) worst = val;
val = Math.abs(q2.data[j] + q0.data[j]);
if( val > worst2 ) worst2 = val;
}
// swap vectors
DMatrixRMaj temp = q0;
q0 = q2;
q2 = temp;
if( worst < tol )
return true;
else if( worst2 < tol )
return true;
else
return false;
} | java | private boolean checkConverged(DMatrixRMaj A) {
double worst = 0;
double worst2 = 0;
for( int j = 0; j < A.numRows; j++ ) {
double val = Math.abs(q2.data[j] - q0.data[j]);
if( val > worst ) worst = val;
val = Math.abs(q2.data[j] + q0.data[j]);
if( val > worst2 ) worst2 = val;
}
// swap vectors
DMatrixRMaj temp = q0;
q0 = q2;
q2 = temp;
if( worst < tol )
return true;
else if( worst2 < tol )
return true;
else
return false;
} | [
"private",
"boolean",
"checkConverged",
"(",
"DMatrixRMaj",
"A",
")",
"{",
"double",
"worst",
"=",
"0",
";",
"double",
"worst2",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"A",
".",
"numRows",
";",
"j",
"++",
")",
"{",
"double",
"val",
"=",
"Math",
".",
"abs",
"(",
"q2",
".",
"data",
"[",
"j",
"]",
"-",
"q0",
".",
"data",
"[",
"j",
"]",
")",
";",
"if",
"(",
"val",
">",
"worst",
")",
"worst",
"=",
"val",
";",
"val",
"=",
"Math",
".",
"abs",
"(",
"q2",
".",
"data",
"[",
"j",
"]",
"+",
"q0",
".",
"data",
"[",
"j",
"]",
")",
";",
"if",
"(",
"val",
">",
"worst2",
")",
"worst2",
"=",
"val",
";",
"}",
"// swap vectors",
"DMatrixRMaj",
"temp",
"=",
"q0",
";",
"q0",
"=",
"q2",
";",
"q2",
"=",
"temp",
";",
"if",
"(",
"worst",
"<",
"tol",
")",
"return",
"true",
";",
"else",
"if",
"(",
"worst2",
"<",
"tol",
")",
"return",
"true",
";",
"else",
"return",
"false",
";",
"}"
] | Test for convergence by seeing if the element with the largest change
is smaller than the tolerance. In some test cases it alternated between
the + and - values of the eigen vector. When this happens it seems to have "converged"
to a non-dominant eigen vector. At least in the case I looked at. I haven't devoted
a lot of time into this issue... | [
"Test",
"for",
"convergence",
"by",
"seeing",
"if",
"the",
"element",
"with",
"the",
"largest",
"change",
"is",
"smaller",
"than",
"the",
"tolerance",
".",
"In",
"some",
"test",
"cases",
"it",
"alternated",
"between",
"the",
"+",
"and",
"-",
"values",
"of",
"the",
"eigen",
"vector",
".",
"When",
"this",
"happens",
"it",
"seems",
"to",
"have",
"converged",
"to",
"a",
"non",
"-",
"dominant",
"eigen",
"vector",
".",
"At",
"least",
"in",
"the",
"case",
"I",
"looked",
"at",
".",
"I",
"haven",
"t",
"devoted",
"a",
"lot",
"of",
"time",
"into",
"this",
"issue",
"..."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/EigenPowerMethod_DDRM.java#L147-L168 |
162,541 | lessthanoptimal/ejml | examples/src/org/ejml/example/PrincipalComponentAnalysis.java | PrincipalComponentAnalysis.setup | public void setup( int numSamples , int sampleSize ) {
mean = new double[ sampleSize ];
A.reshape(numSamples,sampleSize,false);
sampleIndex = 0;
numComponents = -1;
} | java | public void setup( int numSamples , int sampleSize ) {
mean = new double[ sampleSize ];
A.reshape(numSamples,sampleSize,false);
sampleIndex = 0;
numComponents = -1;
} | [
"public",
"void",
"setup",
"(",
"int",
"numSamples",
",",
"int",
"sampleSize",
")",
"{",
"mean",
"=",
"new",
"double",
"[",
"sampleSize",
"]",
";",
"A",
".",
"reshape",
"(",
"numSamples",
",",
"sampleSize",
",",
"false",
")",
";",
"sampleIndex",
"=",
"0",
";",
"numComponents",
"=",
"-",
"1",
";",
"}"
] | Must be called before any other functions. Declares and sets up internal data structures.
@param numSamples Number of samples that will be processed.
@param sampleSize Number of elements in each sample. | [
"Must",
"be",
"called",
"before",
"any",
"other",
"functions",
".",
"Declares",
"and",
"sets",
"up",
"internal",
"data",
"structures",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/PrincipalComponentAnalysis.java#L80-L85 |
162,542 | lessthanoptimal/ejml | examples/src/org/ejml/example/PrincipalComponentAnalysis.java | PrincipalComponentAnalysis.getBasisVector | public double[] getBasisVector( int which ) {
if( which < 0 || which >= numComponents )
throw new IllegalArgumentException("Invalid component");
DMatrixRMaj v = new DMatrixRMaj(1,A.numCols);
CommonOps_DDRM.extract(V_t,which,which+1,0,A.numCols,v,0,0);
return v.data;
} | java | public double[] getBasisVector( int which ) {
if( which < 0 || which >= numComponents )
throw new IllegalArgumentException("Invalid component");
DMatrixRMaj v = new DMatrixRMaj(1,A.numCols);
CommonOps_DDRM.extract(V_t,which,which+1,0,A.numCols,v,0,0);
return v.data;
} | [
"public",
"double",
"[",
"]",
"getBasisVector",
"(",
"int",
"which",
")",
"{",
"if",
"(",
"which",
"<",
"0",
"||",
"which",
">=",
"numComponents",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid component\"",
")",
";",
"DMatrixRMaj",
"v",
"=",
"new",
"DMatrixRMaj",
"(",
"1",
",",
"A",
".",
"numCols",
")",
";",
"CommonOps_DDRM",
".",
"extract",
"(",
"V_t",
",",
"which",
",",
"which",
"+",
"1",
",",
"0",
",",
"A",
".",
"numCols",
",",
"v",
",",
"0",
",",
"0",
")",
";",
"return",
"v",
".",
"data",
";",
"}"
] | Returns a vector from the PCA's basis.
@param which Which component's vector is to be returned.
@return Vector from the PCA basis. | [
"Returns",
"a",
"vector",
"from",
"the",
"PCA",
"s",
"basis",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/PrincipalComponentAnalysis.java#L160-L168 |
162,543 | lessthanoptimal/ejml | examples/src/org/ejml/example/PrincipalComponentAnalysis.java | PrincipalComponentAnalysis.sampleToEigenSpace | public double[] sampleToEigenSpace( double[] sampleData ) {
if( sampleData.length != A.getNumCols() )
throw new IllegalArgumentException("Unexpected sample length");
DMatrixRMaj mean = DMatrixRMaj.wrap(A.getNumCols(),1,this.mean);
DMatrixRMaj s = new DMatrixRMaj(A.getNumCols(),1,true,sampleData);
DMatrixRMaj r = new DMatrixRMaj(numComponents,1);
CommonOps_DDRM.subtract(s, mean, s);
CommonOps_DDRM.mult(V_t,s,r);
return r.data;
} | java | public double[] sampleToEigenSpace( double[] sampleData ) {
if( sampleData.length != A.getNumCols() )
throw new IllegalArgumentException("Unexpected sample length");
DMatrixRMaj mean = DMatrixRMaj.wrap(A.getNumCols(),1,this.mean);
DMatrixRMaj s = new DMatrixRMaj(A.getNumCols(),1,true,sampleData);
DMatrixRMaj r = new DMatrixRMaj(numComponents,1);
CommonOps_DDRM.subtract(s, mean, s);
CommonOps_DDRM.mult(V_t,s,r);
return r.data;
} | [
"public",
"double",
"[",
"]",
"sampleToEigenSpace",
"(",
"double",
"[",
"]",
"sampleData",
")",
"{",
"if",
"(",
"sampleData",
".",
"length",
"!=",
"A",
".",
"getNumCols",
"(",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected sample length\"",
")",
";",
"DMatrixRMaj",
"mean",
"=",
"DMatrixRMaj",
".",
"wrap",
"(",
"A",
".",
"getNumCols",
"(",
")",
",",
"1",
",",
"this",
".",
"mean",
")",
";",
"DMatrixRMaj",
"s",
"=",
"new",
"DMatrixRMaj",
"(",
"A",
".",
"getNumCols",
"(",
")",
",",
"1",
",",
"true",
",",
"sampleData",
")",
";",
"DMatrixRMaj",
"r",
"=",
"new",
"DMatrixRMaj",
"(",
"numComponents",
",",
"1",
")",
";",
"CommonOps_DDRM",
".",
"subtract",
"(",
"s",
",",
"mean",
",",
"s",
")",
";",
"CommonOps_DDRM",
".",
"mult",
"(",
"V_t",
",",
"s",
",",
"r",
")",
";",
"return",
"r",
".",
"data",
";",
"}"
] | Converts a vector from sample space into eigen space.
@param sampleData Sample space data.
@return Eigen space projection. | [
"Converts",
"a",
"vector",
"from",
"sample",
"space",
"into",
"eigen",
"space",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/PrincipalComponentAnalysis.java#L176-L189 |
162,544 | lessthanoptimal/ejml | examples/src/org/ejml/example/PrincipalComponentAnalysis.java | PrincipalComponentAnalysis.eigenToSampleSpace | public double[] eigenToSampleSpace( double[] eigenData ) {
if( eigenData.length != numComponents )
throw new IllegalArgumentException("Unexpected sample length");
DMatrixRMaj s = new DMatrixRMaj(A.getNumCols(),1);
DMatrixRMaj r = DMatrixRMaj.wrap(numComponents,1,eigenData);
CommonOps_DDRM.multTransA(V_t,r,s);
DMatrixRMaj mean = DMatrixRMaj.wrap(A.getNumCols(),1,this.mean);
CommonOps_DDRM.add(s,mean,s);
return s.data;
} | java | public double[] eigenToSampleSpace( double[] eigenData ) {
if( eigenData.length != numComponents )
throw new IllegalArgumentException("Unexpected sample length");
DMatrixRMaj s = new DMatrixRMaj(A.getNumCols(),1);
DMatrixRMaj r = DMatrixRMaj.wrap(numComponents,1,eigenData);
CommonOps_DDRM.multTransA(V_t,r,s);
DMatrixRMaj mean = DMatrixRMaj.wrap(A.getNumCols(),1,this.mean);
CommonOps_DDRM.add(s,mean,s);
return s.data;
} | [
"public",
"double",
"[",
"]",
"eigenToSampleSpace",
"(",
"double",
"[",
"]",
"eigenData",
")",
"{",
"if",
"(",
"eigenData",
".",
"length",
"!=",
"numComponents",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected sample length\"",
")",
";",
"DMatrixRMaj",
"s",
"=",
"new",
"DMatrixRMaj",
"(",
"A",
".",
"getNumCols",
"(",
")",
",",
"1",
")",
";",
"DMatrixRMaj",
"r",
"=",
"DMatrixRMaj",
".",
"wrap",
"(",
"numComponents",
",",
"1",
",",
"eigenData",
")",
";",
"CommonOps_DDRM",
".",
"multTransA",
"(",
"V_t",
",",
"r",
",",
"s",
")",
";",
"DMatrixRMaj",
"mean",
"=",
"DMatrixRMaj",
".",
"wrap",
"(",
"A",
".",
"getNumCols",
"(",
")",
",",
"1",
",",
"this",
".",
"mean",
")",
";",
"CommonOps_DDRM",
".",
"add",
"(",
"s",
",",
"mean",
",",
"s",
")",
";",
"return",
"s",
".",
"data",
";",
"}"
] | Converts a vector from eigen space into sample space.
@param eigenData Eigen space data.
@return Sample space projection. | [
"Converts",
"a",
"vector",
"from",
"eigen",
"space",
"into",
"sample",
"space",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/PrincipalComponentAnalysis.java#L197-L210 |
162,545 | lessthanoptimal/ejml | examples/src/org/ejml/example/PrincipalComponentAnalysis.java | PrincipalComponentAnalysis.response | public double response( double[] sample ) {
if( sample.length != A.numCols )
throw new IllegalArgumentException("Expected input vector to be in sample space");
DMatrixRMaj dots = new DMatrixRMaj(numComponents,1);
DMatrixRMaj s = DMatrixRMaj.wrap(A.numCols,1,sample);
CommonOps_DDRM.mult(V_t,s,dots);
return NormOps_DDRM.normF(dots);
} | java | public double response( double[] sample ) {
if( sample.length != A.numCols )
throw new IllegalArgumentException("Expected input vector to be in sample space");
DMatrixRMaj dots = new DMatrixRMaj(numComponents,1);
DMatrixRMaj s = DMatrixRMaj.wrap(A.numCols,1,sample);
CommonOps_DDRM.mult(V_t,s,dots);
return NormOps_DDRM.normF(dots);
} | [
"public",
"double",
"response",
"(",
"double",
"[",
"]",
"sample",
")",
"{",
"if",
"(",
"sample",
".",
"length",
"!=",
"A",
".",
"numCols",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Expected input vector to be in sample space\"",
")",
";",
"DMatrixRMaj",
"dots",
"=",
"new",
"DMatrixRMaj",
"(",
"numComponents",
",",
"1",
")",
";",
"DMatrixRMaj",
"s",
"=",
"DMatrixRMaj",
".",
"wrap",
"(",
"A",
".",
"numCols",
",",
"1",
",",
"sample",
")",
";",
"CommonOps_DDRM",
".",
"mult",
"(",
"V_t",
",",
"s",
",",
"dots",
")",
";",
"return",
"NormOps_DDRM",
".",
"normF",
"(",
"dots",
")",
";",
"}"
] | Computes the dot product of each basis vector against the sample. Can be used as a measure
for membership in the training sample set. High values correspond to a better fit.
@param sample Sample of original data.
@return Higher value indicates it is more likely to be a member of input dataset. | [
"Computes",
"the",
"dot",
"product",
"of",
"each",
"basis",
"vector",
"against",
"the",
"sample",
".",
"Can",
"be",
"used",
"as",
"a",
"measure",
"for",
"membership",
"in",
"the",
"training",
"sample",
"set",
".",
"High",
"values",
"correspond",
"to",
"a",
"better",
"fit",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/PrincipalComponentAnalysis.java#L247-L257 |
162,546 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/factory/DecompositionFactory_DDRM.java | DecompositionFactory_DDRM.decomposeSafe | public static <T extends DMatrix> boolean decomposeSafe(DecompositionInterface<T> decomp, T M ) {
if( decomp.inputModified() ) {
return decomp.decompose(M.<T>copy());
} else {
return decomp.decompose(M);
}
} | java | public static <T extends DMatrix> boolean decomposeSafe(DecompositionInterface<T> decomp, T M ) {
if( decomp.inputModified() ) {
return decomp.decompose(M.<T>copy());
} else {
return decomp.decompose(M);
}
} | [
"public",
"static",
"<",
"T",
"extends",
"DMatrix",
">",
"boolean",
"decomposeSafe",
"(",
"DecompositionInterface",
"<",
"T",
">",
"decomp",
",",
"T",
"M",
")",
"{",
"if",
"(",
"decomp",
".",
"inputModified",
"(",
")",
")",
"{",
"return",
"decomp",
".",
"decompose",
"(",
"M",
".",
"<",
"T",
">",
"copy",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"decomp",
".",
"decompose",
"(",
"M",
")",
";",
"}",
"}"
] | A simple convinience function that decomposes the matrix but automatically checks the input ti make
sure is not being modified.
@param decomp Decomposition which is being wrapped
@param M THe matrix being decomposed.
@param <T> Matrix type.
@return If the decomposition was successful or not. | [
"A",
"simple",
"convinience",
"function",
"that",
"decomposes",
"the",
"matrix",
"but",
"automatically",
"checks",
"the",
"input",
"ti",
"make",
"sure",
"is",
"not",
"being",
"modified",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/factory/DecompositionFactory_DDRM.java#L331-L337 |
162,547 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/fixed/CommonOps_DDF2.java | CommonOps_DDF2.extractColumn | public static DMatrix2 extractColumn( DMatrix2x2 a , int column , DMatrix2 out ) {
if( out == null) out = new DMatrix2();
switch( column ) {
case 0:
out.a1 = a.a11;
out.a2 = a.a21;
break;
case 1:
out.a1 = a.a12;
out.a2 = a.a22;
break;
default:
throw new IllegalArgumentException("Out of bounds column. column = "+column);
}
return out;
} | java | public static DMatrix2 extractColumn( DMatrix2x2 a , int column , DMatrix2 out ) {
if( out == null) out = new DMatrix2();
switch( column ) {
case 0:
out.a1 = a.a11;
out.a2 = a.a21;
break;
case 1:
out.a1 = a.a12;
out.a2 = a.a22;
break;
default:
throw new IllegalArgumentException("Out of bounds column. column = "+column);
}
return out;
} | [
"public",
"static",
"DMatrix2",
"extractColumn",
"(",
"DMatrix2x2",
"a",
",",
"int",
"column",
",",
"DMatrix2",
"out",
")",
"{",
"if",
"(",
"out",
"==",
"null",
")",
"out",
"=",
"new",
"DMatrix2",
"(",
")",
";",
"switch",
"(",
"column",
")",
"{",
"case",
"0",
":",
"out",
".",
"a1",
"=",
"a",
".",
"a11",
";",
"out",
".",
"a2",
"=",
"a",
".",
"a21",
";",
"break",
";",
"case",
"1",
":",
"out",
".",
"a1",
"=",
"a",
".",
"a12",
";",
"out",
".",
"a2",
"=",
"a",
".",
"a22",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Out of bounds column. column = \"",
"+",
"column",
")",
";",
"}",
"return",
"out",
";",
"}"
] | Extracts the column from the matrix a.
@param a Input matrix
@param column Which column is to be extracted
@param out output. Storage for the extracted column. If null then a new vector will be returned.
@return The extracted column. | [
"Extracts",
"the",
"column",
"from",
"the",
"matrix",
"a",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/fixed/CommonOps_DDF2.java#L1181-L1196 |
162,548 | lessthanoptimal/ejml | main/ejml-zdense/src/org/ejml/dense/row/factory/DecompositionFactory_ZDRM.java | DecompositionFactory_ZDRM.decomposeSafe | public static boolean decomposeSafe(DecompositionInterface<ZMatrixRMaj> decomposition, ZMatrixRMaj a) {
if( decomposition.inputModified() ) {
a = a.copy();
}
return decomposition.decompose(a);
} | java | public static boolean decomposeSafe(DecompositionInterface<ZMatrixRMaj> decomposition, ZMatrixRMaj a) {
if( decomposition.inputModified() ) {
a = a.copy();
}
return decomposition.decompose(a);
} | [
"public",
"static",
"boolean",
"decomposeSafe",
"(",
"DecompositionInterface",
"<",
"ZMatrixRMaj",
">",
"decomposition",
",",
"ZMatrixRMaj",
"a",
")",
"{",
"if",
"(",
"decomposition",
".",
"inputModified",
"(",
")",
")",
"{",
"a",
"=",
"a",
".",
"copy",
"(",
")",
";",
"}",
"return",
"decomposition",
".",
"decompose",
"(",
"a",
")",
";",
"}"
] | Decomposes the input matrix 'a' and makes sure it isn't modified. | [
"Decomposes",
"the",
"input",
"matrix",
"a",
"and",
"makes",
"sure",
"it",
"isn",
"t",
"modified",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-zdense/src/org/ejml/dense/row/factory/DecompositionFactory_ZDRM.java#L83-L89 |
162,549 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/TriangularSolver_DDRB.java | TriangularSolver_DDRB.invert | public static void invert( final int blockLength ,
final boolean upper ,
final DSubmatrixD1 T ,
final DSubmatrixD1 T_inv ,
final double temp[] )
{
if( upper )
throw new IllegalArgumentException("Upper triangular matrices not supported yet");
if( temp.length < blockLength*blockLength )
throw new IllegalArgumentException("Temp must be at least blockLength*blockLength long.");
if( T.row0 != T_inv.row0 || T.row1 != T_inv.row1 || T.col0 != T_inv.col0 || T.col1 != T_inv.col1)
throw new IllegalArgumentException("T and T_inv must be at the same elements in the matrix");
final int M = T.row1-T.row0;
final double dataT[] = T.original.data;
final double dataX[] = T_inv.original.data;
final int offsetT = T.row0*T.original.numCols+M*T.col0;
for( int i = 0; i < M; i += blockLength ) {
int heightT = Math.min(T.row1-(i+T.row0),blockLength);
int indexII = offsetT + T.original.numCols*(i+T.row0) + heightT*(i+T.col0);
for( int j = 0; j < i; j += blockLength ) {
int widthX = Math.min(T.col1-(j+T.col0),blockLength);
for( int w = 0; w < temp.length; w++ ) {
temp[w] = 0;
}
for( int k = j; k < i; k += blockLength ) {
int widthT = Math.min(T.col1-(k+T.col0),blockLength);
int indexL = offsetT + T.original.numCols*(i+T.row0) + heightT*(k+T.col0);
int indexX = offsetT + T.original.numCols*(k+T.row0) + widthT*(j+T.col0);
blockMultMinus(dataT,dataX,temp,indexL,indexX,0,heightT,widthT,widthX);
}
int indexX = offsetT + T.original.numCols*(i+T.row0) + heightT*(j+T.col0);
InnerTriangularSolver_DDRB.solveL(dataT,temp,heightT,widthX,heightT,indexII,0);
System.arraycopy(temp,0,dataX,indexX,widthX*heightT);
}
InnerTriangularSolver_DDRB.invertLower(dataT,dataX,heightT,indexII,indexII);
}
} | java | public static void invert( final int blockLength ,
final boolean upper ,
final DSubmatrixD1 T ,
final DSubmatrixD1 T_inv ,
final double temp[] )
{
if( upper )
throw new IllegalArgumentException("Upper triangular matrices not supported yet");
if( temp.length < blockLength*blockLength )
throw new IllegalArgumentException("Temp must be at least blockLength*blockLength long.");
if( T.row0 != T_inv.row0 || T.row1 != T_inv.row1 || T.col0 != T_inv.col0 || T.col1 != T_inv.col1)
throw new IllegalArgumentException("T and T_inv must be at the same elements in the matrix");
final int M = T.row1-T.row0;
final double dataT[] = T.original.data;
final double dataX[] = T_inv.original.data;
final int offsetT = T.row0*T.original.numCols+M*T.col0;
for( int i = 0; i < M; i += blockLength ) {
int heightT = Math.min(T.row1-(i+T.row0),blockLength);
int indexII = offsetT + T.original.numCols*(i+T.row0) + heightT*(i+T.col0);
for( int j = 0; j < i; j += blockLength ) {
int widthX = Math.min(T.col1-(j+T.col0),blockLength);
for( int w = 0; w < temp.length; w++ ) {
temp[w] = 0;
}
for( int k = j; k < i; k += blockLength ) {
int widthT = Math.min(T.col1-(k+T.col0),blockLength);
int indexL = offsetT + T.original.numCols*(i+T.row0) + heightT*(k+T.col0);
int indexX = offsetT + T.original.numCols*(k+T.row0) + widthT*(j+T.col0);
blockMultMinus(dataT,dataX,temp,indexL,indexX,0,heightT,widthT,widthX);
}
int indexX = offsetT + T.original.numCols*(i+T.row0) + heightT*(j+T.col0);
InnerTriangularSolver_DDRB.solveL(dataT,temp,heightT,widthX,heightT,indexII,0);
System.arraycopy(temp,0,dataX,indexX,widthX*heightT);
}
InnerTriangularSolver_DDRB.invertLower(dataT,dataX,heightT,indexII,indexII);
}
} | [
"public",
"static",
"void",
"invert",
"(",
"final",
"int",
"blockLength",
",",
"final",
"boolean",
"upper",
",",
"final",
"DSubmatrixD1",
"T",
",",
"final",
"DSubmatrixD1",
"T_inv",
",",
"final",
"double",
"temp",
"[",
"]",
")",
"{",
"if",
"(",
"upper",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Upper triangular matrices not supported yet\"",
")",
";",
"if",
"(",
"temp",
".",
"length",
"<",
"blockLength",
"*",
"blockLength",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Temp must be at least blockLength*blockLength long.\"",
")",
";",
"if",
"(",
"T",
".",
"row0",
"!=",
"T_inv",
".",
"row0",
"||",
"T",
".",
"row1",
"!=",
"T_inv",
".",
"row1",
"||",
"T",
".",
"col0",
"!=",
"T_inv",
".",
"col0",
"||",
"T",
".",
"col1",
"!=",
"T_inv",
".",
"col1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"T and T_inv must be at the same elements in the matrix\"",
")",
";",
"final",
"int",
"M",
"=",
"T",
".",
"row1",
"-",
"T",
".",
"row0",
";",
"final",
"double",
"dataT",
"[",
"]",
"=",
"T",
".",
"original",
".",
"data",
";",
"final",
"double",
"dataX",
"[",
"]",
"=",
"T_inv",
".",
"original",
".",
"data",
";",
"final",
"int",
"offsetT",
"=",
"T",
".",
"row0",
"*",
"T",
".",
"original",
".",
"numCols",
"+",
"M",
"*",
"T",
".",
"col0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"M",
";",
"i",
"+=",
"blockLength",
")",
"{",
"int",
"heightT",
"=",
"Math",
".",
"min",
"(",
"T",
".",
"row1",
"-",
"(",
"i",
"+",
"T",
".",
"row0",
")",
",",
"blockLength",
")",
";",
"int",
"indexII",
"=",
"offsetT",
"+",
"T",
".",
"original",
".",
"numCols",
"*",
"(",
"i",
"+",
"T",
".",
"row0",
")",
"+",
"heightT",
"*",
"(",
"i",
"+",
"T",
".",
"col0",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"i",
";",
"j",
"+=",
"blockLength",
")",
"{",
"int",
"widthX",
"=",
"Math",
".",
"min",
"(",
"T",
".",
"col1",
"-",
"(",
"j",
"+",
"T",
".",
"col0",
")",
",",
"blockLength",
")",
";",
"for",
"(",
"int",
"w",
"=",
"0",
";",
"w",
"<",
"temp",
".",
"length",
";",
"w",
"++",
")",
"{",
"temp",
"[",
"w",
"]",
"=",
"0",
";",
"}",
"for",
"(",
"int",
"k",
"=",
"j",
";",
"k",
"<",
"i",
";",
"k",
"+=",
"blockLength",
")",
"{",
"int",
"widthT",
"=",
"Math",
".",
"min",
"(",
"T",
".",
"col1",
"-",
"(",
"k",
"+",
"T",
".",
"col0",
")",
",",
"blockLength",
")",
";",
"int",
"indexL",
"=",
"offsetT",
"+",
"T",
".",
"original",
".",
"numCols",
"*",
"(",
"i",
"+",
"T",
".",
"row0",
")",
"+",
"heightT",
"*",
"(",
"k",
"+",
"T",
".",
"col0",
")",
";",
"int",
"indexX",
"=",
"offsetT",
"+",
"T",
".",
"original",
".",
"numCols",
"*",
"(",
"k",
"+",
"T",
".",
"row0",
")",
"+",
"widthT",
"*",
"(",
"j",
"+",
"T",
".",
"col0",
")",
";",
"blockMultMinus",
"(",
"dataT",
",",
"dataX",
",",
"temp",
",",
"indexL",
",",
"indexX",
",",
"0",
",",
"heightT",
",",
"widthT",
",",
"widthX",
")",
";",
"}",
"int",
"indexX",
"=",
"offsetT",
"+",
"T",
".",
"original",
".",
"numCols",
"*",
"(",
"i",
"+",
"T",
".",
"row0",
")",
"+",
"heightT",
"*",
"(",
"j",
"+",
"T",
".",
"col0",
")",
";",
"InnerTriangularSolver_DDRB",
".",
"solveL",
"(",
"dataT",
",",
"temp",
",",
"heightT",
",",
"widthX",
",",
"heightT",
",",
"indexII",
",",
"0",
")",
";",
"System",
".",
"arraycopy",
"(",
"temp",
",",
"0",
",",
"dataX",
",",
"indexX",
",",
"widthX",
"*",
"heightT",
")",
";",
"}",
"InnerTriangularSolver_DDRB",
".",
"invertLower",
"(",
"dataT",
",",
"dataX",
",",
"heightT",
",",
"indexII",
",",
"indexII",
")",
";",
"}",
"}"
] | Inverts an upper or lower triangular block submatrix.
@param blockLength
@param upper Is it upper or lower triangular.
@param T Triangular matrix that is to be inverted. Must be block aligned. Not Modified.
@param T_inv Where the inverse is stored. This can be the same as T. Modified.
@param temp Work space variable that is size blockLength*blockLength. | [
"Inverts",
"an",
"upper",
"or",
"lower",
"triangular",
"block",
"submatrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/TriangularSolver_DDRB.java#L51-L101 |
162,550 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.span | public static DMatrixRMaj[] span(int dimen, int numVectors , Random rand ) {
if( dimen < numVectors )
throw new IllegalArgumentException("The number of vectors must be less than or equal to the dimension");
DMatrixRMaj u[] = new DMatrixRMaj[numVectors];
u[0] = RandomMatrices_DDRM.rectangle(dimen,1,-1,1,rand);
NormOps_DDRM.normalizeF(u[0]);
for( int i = 1; i < numVectors; i++ ) {
// System.out.println(" i = "+i);
DMatrixRMaj a = new DMatrixRMaj(dimen,1);
DMatrixRMaj r=null;
for( int j = 0; j < i; j++ ) {
// System.out.println("j = "+j);
if( j == 0 )
r = RandomMatrices_DDRM.rectangle(dimen,1,-1,1,rand);
// find a vector that is normal to vector j
// u[i] = (1/2)*(r + Q[j]*r)
a.set(r);
VectorVectorMult_DDRM.householder(-2.0,u[j],r,a);
CommonOps_DDRM.add(r,a,a);
CommonOps_DDRM.scale(0.5,a);
// UtilEjml.print(a);
DMatrixRMaj t = a;
a = r;
r = t;
// normalize it so it doesn't get too small
double val = NormOps_DDRM.normF(r);
if( val == 0 || Double.isNaN(val) || Double.isInfinite(val))
throw new RuntimeException("Failed sanity check");
CommonOps_DDRM.divide(r,val);
}
u[i] = r;
}
return u;
} | java | public static DMatrixRMaj[] span(int dimen, int numVectors , Random rand ) {
if( dimen < numVectors )
throw new IllegalArgumentException("The number of vectors must be less than or equal to the dimension");
DMatrixRMaj u[] = new DMatrixRMaj[numVectors];
u[0] = RandomMatrices_DDRM.rectangle(dimen,1,-1,1,rand);
NormOps_DDRM.normalizeF(u[0]);
for( int i = 1; i < numVectors; i++ ) {
// System.out.println(" i = "+i);
DMatrixRMaj a = new DMatrixRMaj(dimen,1);
DMatrixRMaj r=null;
for( int j = 0; j < i; j++ ) {
// System.out.println("j = "+j);
if( j == 0 )
r = RandomMatrices_DDRM.rectangle(dimen,1,-1,1,rand);
// find a vector that is normal to vector j
// u[i] = (1/2)*(r + Q[j]*r)
a.set(r);
VectorVectorMult_DDRM.householder(-2.0,u[j],r,a);
CommonOps_DDRM.add(r,a,a);
CommonOps_DDRM.scale(0.5,a);
// UtilEjml.print(a);
DMatrixRMaj t = a;
a = r;
r = t;
// normalize it so it doesn't get too small
double val = NormOps_DDRM.normF(r);
if( val == 0 || Double.isNaN(val) || Double.isInfinite(val))
throw new RuntimeException("Failed sanity check");
CommonOps_DDRM.divide(r,val);
}
u[i] = r;
}
return u;
} | [
"public",
"static",
"DMatrixRMaj",
"[",
"]",
"span",
"(",
"int",
"dimen",
",",
"int",
"numVectors",
",",
"Random",
"rand",
")",
"{",
"if",
"(",
"dimen",
"<",
"numVectors",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The number of vectors must be less than or equal to the dimension\"",
")",
";",
"DMatrixRMaj",
"u",
"[",
"]",
"=",
"new",
"DMatrixRMaj",
"[",
"numVectors",
"]",
";",
"u",
"[",
"0",
"]",
"=",
"RandomMatrices_DDRM",
".",
"rectangle",
"(",
"dimen",
",",
"1",
",",
"-",
"1",
",",
"1",
",",
"rand",
")",
";",
"NormOps_DDRM",
".",
"normalizeF",
"(",
"u",
"[",
"0",
"]",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"numVectors",
";",
"i",
"++",
")",
"{",
"// System.out.println(\" i = \"+i);",
"DMatrixRMaj",
"a",
"=",
"new",
"DMatrixRMaj",
"(",
"dimen",
",",
"1",
")",
";",
"DMatrixRMaj",
"r",
"=",
"null",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"i",
";",
"j",
"++",
")",
"{",
"// System.out.println(\"j = \"+j);",
"if",
"(",
"j",
"==",
"0",
")",
"r",
"=",
"RandomMatrices_DDRM",
".",
"rectangle",
"(",
"dimen",
",",
"1",
",",
"-",
"1",
",",
"1",
",",
"rand",
")",
";",
"// find a vector that is normal to vector j",
"// u[i] = (1/2)*(r + Q[j]*r)",
"a",
".",
"set",
"(",
"r",
")",
";",
"VectorVectorMult_DDRM",
".",
"householder",
"(",
"-",
"2.0",
",",
"u",
"[",
"j",
"]",
",",
"r",
",",
"a",
")",
";",
"CommonOps_DDRM",
".",
"add",
"(",
"r",
",",
"a",
",",
"a",
")",
";",
"CommonOps_DDRM",
".",
"scale",
"(",
"0.5",
",",
"a",
")",
";",
"// UtilEjml.print(a);",
"DMatrixRMaj",
"t",
"=",
"a",
";",
"a",
"=",
"r",
";",
"r",
"=",
"t",
";",
"// normalize it so it doesn't get too small",
"double",
"val",
"=",
"NormOps_DDRM",
".",
"normF",
"(",
"r",
")",
";",
"if",
"(",
"val",
"==",
"0",
"||",
"Double",
".",
"isNaN",
"(",
"val",
")",
"||",
"Double",
".",
"isInfinite",
"(",
"val",
")",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed sanity check\"",
")",
";",
"CommonOps_DDRM",
".",
"divide",
"(",
"r",
",",
"val",
")",
";",
"}",
"u",
"[",
"i",
"]",
"=",
"r",
";",
"}",
"return",
"u",
";",
"}"
] | is there a faster algorithm out there? This one is a bit sluggish | [
"is",
"there",
"a",
"faster",
"algorithm",
"out",
"there?",
"This",
"one",
"is",
"a",
"bit",
"sluggish"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L58-L101 |
162,551 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.insideSpan | public static DMatrixRMaj insideSpan(DMatrixRMaj[] span , double min , double max , Random rand ) {
DMatrixRMaj A = new DMatrixRMaj(span.length,1);
DMatrixRMaj B = new DMatrixRMaj(span[0].getNumElements(),1);
for( int i = 0; i < span.length; i++ ) {
B.set(span[i]);
double val = rand.nextDouble()*(max-min)+min;
CommonOps_DDRM.scale(val,B);
CommonOps_DDRM.add(A,B,A);
}
return A;
} | java | public static DMatrixRMaj insideSpan(DMatrixRMaj[] span , double min , double max , Random rand ) {
DMatrixRMaj A = new DMatrixRMaj(span.length,1);
DMatrixRMaj B = new DMatrixRMaj(span[0].getNumElements(),1);
for( int i = 0; i < span.length; i++ ) {
B.set(span[i]);
double val = rand.nextDouble()*(max-min)+min;
CommonOps_DDRM.scale(val,B);
CommonOps_DDRM.add(A,B,A);
}
return A;
} | [
"public",
"static",
"DMatrixRMaj",
"insideSpan",
"(",
"DMatrixRMaj",
"[",
"]",
"span",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"DMatrixRMaj",
"A",
"=",
"new",
"DMatrixRMaj",
"(",
"span",
".",
"length",
",",
"1",
")",
";",
"DMatrixRMaj",
"B",
"=",
"new",
"DMatrixRMaj",
"(",
"span",
"[",
"0",
"]",
".",
"getNumElements",
"(",
")",
",",
"1",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"span",
".",
"length",
";",
"i",
"++",
")",
"{",
"B",
".",
"set",
"(",
"span",
"[",
"i",
"]",
")",
";",
"double",
"val",
"=",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"(",
"max",
"-",
"min",
")",
"+",
"min",
";",
"CommonOps_DDRM",
".",
"scale",
"(",
"val",
",",
"B",
")",
";",
"CommonOps_DDRM",
".",
"add",
"(",
"A",
",",
"B",
",",
"A",
")",
";",
"}",
"return",
"A",
";",
"}"
] | Creates a random vector that is inside the specified span.
@param span The span the random vector belongs in.
@param rand RNG
@return A random vector within the specified span. | [
"Creates",
"a",
"random",
"vector",
"that",
"is",
"inside",
"the",
"specified",
"span",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L110-L125 |
162,552 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.diagonal | public static DMatrixRMaj diagonal(int N , double min , double max , Random rand ) {
return diagonal(N,N,min,max,rand);
} | java | public static DMatrixRMaj diagonal(int N , double min , double max , Random rand ) {
return diagonal(N,N,min,max,rand);
} | [
"public",
"static",
"DMatrixRMaj",
"diagonal",
"(",
"int",
"N",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"return",
"diagonal",
"(",
"N",
",",
"N",
",",
"min",
",",
"max",
",",
"rand",
")",
";",
"}"
] | Creates a random diagonal matrix where the diagonal elements are selected from a uniform
distribution that goes from min to max.
@param N Dimension of the matrix.
@param min Minimum value of a diagonal element.
@param max Maximum value of a diagonal element.
@param rand Random number generator.
@return A random diagonal matrix. | [
"Creates",
"a",
"random",
"diagonal",
"matrix",
"where",
"the",
"diagonal",
"elements",
"are",
"selected",
"from",
"a",
"uniform",
"distribution",
"that",
"goes",
"from",
"min",
"to",
"max",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L163-L165 |
162,553 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.diagonal | public static DMatrixRMaj diagonal(int numRows , int numCols , double min , double max , Random rand ) {
if( max < min )
throw new IllegalArgumentException("The max must be >= the min");
DMatrixRMaj ret = new DMatrixRMaj(numRows,numCols);
int N = Math.min(numRows,numCols);
double r = max-min;
for( int i = 0; i < N; i++ ) {
ret.set(i,i, rand.nextDouble()*r+min);
}
return ret;
} | java | public static DMatrixRMaj diagonal(int numRows , int numCols , double min , double max , Random rand ) {
if( max < min )
throw new IllegalArgumentException("The max must be >= the min");
DMatrixRMaj ret = new DMatrixRMaj(numRows,numCols);
int N = Math.min(numRows,numCols);
double r = max-min;
for( int i = 0; i < N; i++ ) {
ret.set(i,i, rand.nextDouble()*r+min);
}
return ret;
} | [
"public",
"static",
"DMatrixRMaj",
"diagonal",
"(",
"int",
"numRows",
",",
"int",
"numCols",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"if",
"(",
"max",
"<",
"min",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The max must be >= the min\"",
")",
";",
"DMatrixRMaj",
"ret",
"=",
"new",
"DMatrixRMaj",
"(",
"numRows",
",",
"numCols",
")",
";",
"int",
"N",
"=",
"Math",
".",
"min",
"(",
"numRows",
",",
"numCols",
")",
";",
"double",
"r",
"=",
"max",
"-",
"min",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"ret",
".",
"set",
"(",
"i",
",",
"i",
",",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"r",
"+",
"min",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Creates a random matrix where all elements are zero but diagonal elements. Diagonal elements
randomly drawn from a uniform distribution from min to max, inclusive.
@param numRows Number of rows in the returned matrix..
@param numCols Number of columns in the returned matrix.
@param min Minimum value of a diagonal element.
@param max Maximum value of a diagonal element.
@param rand Random number generator.
@return A random diagonal matrix. | [
"Creates",
"a",
"random",
"matrix",
"where",
"all",
"elements",
"are",
"zero",
"but",
"diagonal",
"elements",
".",
"Diagonal",
"elements",
"randomly",
"drawn",
"from",
"a",
"uniform",
"distribution",
"from",
"min",
"to",
"max",
"inclusive",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L178-L193 |
162,554 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.symmetricWithEigenvalues | public static DMatrixRMaj symmetricWithEigenvalues(int num, Random rand , double ...eigenvalues ) {
DMatrixRMaj V = RandomMatrices_DDRM.orthogonal(num,num,rand);
DMatrixRMaj D = CommonOps_DDRM.diag(eigenvalues);
DMatrixRMaj temp = new DMatrixRMaj(num,num);
CommonOps_DDRM.mult(V,D,temp);
CommonOps_DDRM.multTransB(temp,V,D);
return D;
} | java | public static DMatrixRMaj symmetricWithEigenvalues(int num, Random rand , double ...eigenvalues ) {
DMatrixRMaj V = RandomMatrices_DDRM.orthogonal(num,num,rand);
DMatrixRMaj D = CommonOps_DDRM.diag(eigenvalues);
DMatrixRMaj temp = new DMatrixRMaj(num,num);
CommonOps_DDRM.mult(V,D,temp);
CommonOps_DDRM.multTransB(temp,V,D);
return D;
} | [
"public",
"static",
"DMatrixRMaj",
"symmetricWithEigenvalues",
"(",
"int",
"num",
",",
"Random",
"rand",
",",
"double",
"...",
"eigenvalues",
")",
"{",
"DMatrixRMaj",
"V",
"=",
"RandomMatrices_DDRM",
".",
"orthogonal",
"(",
"num",
",",
"num",
",",
"rand",
")",
";",
"DMatrixRMaj",
"D",
"=",
"CommonOps_DDRM",
".",
"diag",
"(",
"eigenvalues",
")",
";",
"DMatrixRMaj",
"temp",
"=",
"new",
"DMatrixRMaj",
"(",
"num",
",",
"num",
")",
";",
"CommonOps_DDRM",
".",
"mult",
"(",
"V",
",",
"D",
",",
"temp",
")",
";",
"CommonOps_DDRM",
".",
"multTransB",
"(",
"temp",
",",
"V",
",",
"D",
")",
";",
"return",
"D",
";",
"}"
] | Creates a new random symmetric matrix that will have the specified real eigenvalues.
@param num Dimension of the resulting matrix.
@param rand Random number generator.
@param eigenvalues Set of real eigenvalues that the matrix will have.
@return A random matrix with the specified eigenvalues. | [
"Creates",
"a",
"new",
"random",
"symmetric",
"matrix",
"that",
"will",
"have",
"the",
"specified",
"real",
"eigenvalues",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L247-L257 |
162,555 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.randomBinary | public static BMatrixRMaj randomBinary(int numRow , int numCol , Random rand ) {
BMatrixRMaj mat = new BMatrixRMaj(numRow,numCol);
setRandomB(mat, rand);
return mat;
} | java | public static BMatrixRMaj randomBinary(int numRow , int numCol , Random rand ) {
BMatrixRMaj mat = new BMatrixRMaj(numRow,numCol);
setRandomB(mat, rand);
return mat;
} | [
"public",
"static",
"BMatrixRMaj",
"randomBinary",
"(",
"int",
"numRow",
",",
"int",
"numCol",
",",
"Random",
"rand",
")",
"{",
"BMatrixRMaj",
"mat",
"=",
"new",
"BMatrixRMaj",
"(",
"numRow",
",",
"numCol",
")",
";",
"setRandomB",
"(",
"mat",
",",
"rand",
")",
";",
"return",
"mat",
";",
"}"
] | Returns new boolean matrix with true or false values selected with equal probability.
@param numRow Number of rows in the new matrix.
@param numCol Number of columns in the new matrix.
@param rand Random number generator used to fill the matrix.
@return The randomly generated matrix. | [
"Returns",
"new",
"boolean",
"matrix",
"with",
"true",
"or",
"false",
"values",
"selected",
"with",
"equal",
"probability",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L284-L290 |
162,556 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.symmetric | public static DMatrixRMaj symmetric(int length, double min, double max, Random rand) {
DMatrixRMaj A = new DMatrixRMaj(length,length);
symmetric(A,min,max,rand);
return A;
} | java | public static DMatrixRMaj symmetric(int length, double min, double max, Random rand) {
DMatrixRMaj A = new DMatrixRMaj(length,length);
symmetric(A,min,max,rand);
return A;
} | [
"public",
"static",
"DMatrixRMaj",
"symmetric",
"(",
"int",
"length",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"DMatrixRMaj",
"A",
"=",
"new",
"DMatrixRMaj",
"(",
"length",
",",
"length",
")",
";",
"symmetric",
"(",
"A",
",",
"min",
",",
"max",
",",
"rand",
")",
";",
"return",
"A",
";",
"}"
] | Creates a random symmetric matrix whose values are selected from an uniform distribution
from min to max, inclusive.
@param length Width and height of the matrix.
@param min Minimum value an element can have.
@param max Maximum value an element can have.
@param rand Random number generator.
@return A symmetric matrix. | [
"Creates",
"a",
"random",
"symmetric",
"matrix",
"whose",
"values",
"are",
"selected",
"from",
"an",
"uniform",
"distribution",
"from",
"min",
"to",
"max",
"inclusive",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L467-L473 |
162,557 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.symmetric | public static void symmetric(DMatrixRMaj A, double min, double max, Random rand) {
if( A.numRows != A.numCols )
throw new IllegalArgumentException("A must be a square matrix");
double range = max-min;
int length = A.numRows;
for( int i = 0; i < length; i++ ) {
for( int j = i; j < length; j++ ) {
double val = rand.nextDouble()*range + min;
A.set(i,j,val);
A.set(j,i,val);
}
}
} | java | public static void symmetric(DMatrixRMaj A, double min, double max, Random rand) {
if( A.numRows != A.numCols )
throw new IllegalArgumentException("A must be a square matrix");
double range = max-min;
int length = A.numRows;
for( int i = 0; i < length; i++ ) {
for( int j = i; j < length; j++ ) {
double val = rand.nextDouble()*range + min;
A.set(i,j,val);
A.set(j,i,val);
}
}
} | [
"public",
"static",
"void",
"symmetric",
"(",
"DMatrixRMaj",
"A",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"!=",
"A",
".",
"numCols",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"A must be a square matrix\"",
")",
";",
"double",
"range",
"=",
"max",
"-",
"min",
";",
"int",
"length",
"=",
"A",
".",
"numRows",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"i",
";",
"j",
"<",
"length",
";",
"j",
"++",
")",
"{",
"double",
"val",
"=",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"range",
"+",
"min",
";",
"A",
".",
"set",
"(",
"i",
",",
"j",
",",
"val",
")",
";",
"A",
".",
"set",
"(",
"j",
",",
"i",
",",
"val",
")",
";",
"}",
"}",
"}"
] | Sets the provided square matrix to be a random symmetric matrix whose values are selected from an uniform distribution
from min to max, inclusive.
@param A The matrix that is to be modified. Must be square. Modified.
@param min Minimum value an element can have.
@param max Maximum value an element can have.
@param rand Random number generator. | [
"Sets",
"the",
"provided",
"square",
"matrix",
"to",
"be",
"a",
"random",
"symmetric",
"matrix",
"whose",
"values",
"are",
"selected",
"from",
"an",
"uniform",
"distribution",
"from",
"min",
"to",
"max",
"inclusive",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L484-L499 |
162,558 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java | RandomMatrices_DDRM.triangularUpper | public static DMatrixRMaj triangularUpper(int dimen , int hessenberg , double min , double max , Random rand )
{
if( hessenberg < 0 )
throw new RuntimeException("hessenberg must be more than or equal to 0");
double range = max-min;
DMatrixRMaj A = new DMatrixRMaj(dimen,dimen);
for( int i = 0; i < dimen; i++ ) {
int start = i <= hessenberg ? 0 : i-hessenberg;
for( int j = start; j < dimen; j++ ) {
A.set(i,j, rand.nextDouble()*range+min);
}
}
return A;
} | java | public static DMatrixRMaj triangularUpper(int dimen , int hessenberg , double min , double max , Random rand )
{
if( hessenberg < 0 )
throw new RuntimeException("hessenberg must be more than or equal to 0");
double range = max-min;
DMatrixRMaj A = new DMatrixRMaj(dimen,dimen);
for( int i = 0; i < dimen; i++ ) {
int start = i <= hessenberg ? 0 : i-hessenberg;
for( int j = start; j < dimen; j++ ) {
A.set(i,j, rand.nextDouble()*range+min);
}
}
return A;
} | [
"public",
"static",
"DMatrixRMaj",
"triangularUpper",
"(",
"int",
"dimen",
",",
"int",
"hessenberg",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"if",
"(",
"hessenberg",
"<",
"0",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"hessenberg must be more than or equal to 0\"",
")",
";",
"double",
"range",
"=",
"max",
"-",
"min",
";",
"DMatrixRMaj",
"A",
"=",
"new",
"DMatrixRMaj",
"(",
"dimen",
",",
"dimen",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"dimen",
";",
"i",
"++",
")",
"{",
"int",
"start",
"=",
"i",
"<=",
"hessenberg",
"?",
"0",
":",
"i",
"-",
"hessenberg",
";",
"for",
"(",
"int",
"j",
"=",
"start",
";",
"j",
"<",
"dimen",
";",
"j",
"++",
")",
"{",
"A",
".",
"set",
"(",
"i",
",",
"j",
",",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"range",
"+",
"min",
")",
";",
"}",
"}",
"return",
"A",
";",
"}"
] | Creates an upper triangular matrix whose values are selected from a uniform distribution. If hessenberg
is greater than zero then a hessenberg matrix of the specified degree is created instead.
@param dimen Number of rows and columns in the matrix..
@param hessenberg 0 for triangular matrix and > 0 for hessenberg matrix.
@param min minimum value an element can be.
@param max maximum value an element can be.
@param rand random number generator used.
@return The randomly generated matrix. | [
"Creates",
"an",
"upper",
"triangular",
"matrix",
"whose",
"values",
"are",
"selected",
"from",
"a",
"uniform",
"distribution",
".",
"If",
"hessenberg",
"is",
"greater",
"than",
"zero",
"then",
"a",
"hessenberg",
"matrix",
"of",
"the",
"specified",
"degree",
"is",
"created",
"instead",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/RandomMatrices_DDRM.java#L512-L531 |
162,559 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/CovarianceRandomDraw_DDRM.java | CovarianceRandomDraw_DDRM.computeLikelihoodP | public double computeLikelihoodP() {
double ret = 1.0;
for( int i = 0; i < r.numRows; i++ ) {
double a = r.get(i,0);
ret *= Math.exp(-a*a/2.0);
}
return ret;
} | java | public double computeLikelihoodP() {
double ret = 1.0;
for( int i = 0; i < r.numRows; i++ ) {
double a = r.get(i,0);
ret *= Math.exp(-a*a/2.0);
}
return ret;
} | [
"public",
"double",
"computeLikelihoodP",
"(",
")",
"{",
"double",
"ret",
"=",
"1.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"r",
".",
"numRows",
";",
"i",
"++",
")",
"{",
"double",
"a",
"=",
"r",
".",
"get",
"(",
"i",
",",
"0",
")",
";",
"ret",
"*=",
"Math",
".",
"exp",
"(",
"-",
"a",
"*",
"a",
"/",
"2.0",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Computes the likelihood of the random draw
@return The likelihood. | [
"Computes",
"the",
"likelihood",
"of",
"the",
"random",
"draw"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/CovarianceRandomDraw_DDRM.java#L73-L83 |
162,560 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/SymmetricQRAlgorithmDecomposition_DDRM.java | SymmetricQRAlgorithmDecomposition_DDRM.decompose | @Override
public boolean decompose(DMatrixRMaj orig) {
if( orig.numCols != orig.numRows )
throw new IllegalArgumentException("Matrix must be square.");
if( orig.numCols <= 0 )
return false;
int N = orig.numRows;
// compute a similar tridiagonal matrix
if( !decomp.decompose(orig) )
return false;
if( diag == null || diag.length < N) {
diag = new double[N];
off = new double[N-1];
}
decomp.getDiagonal(diag,off);
// Tell the helper to work with this matrix
helper.init(diag,off,N);
if( computeVectors ) {
if( computeVectorsWithValues ) {
return extractTogether();
} else {
return extractSeparate(N);
}
} else {
return computeEigenValues();
}
} | java | @Override
public boolean decompose(DMatrixRMaj orig) {
if( orig.numCols != orig.numRows )
throw new IllegalArgumentException("Matrix must be square.");
if( orig.numCols <= 0 )
return false;
int N = orig.numRows;
// compute a similar tridiagonal matrix
if( !decomp.decompose(orig) )
return false;
if( diag == null || diag.length < N) {
diag = new double[N];
off = new double[N-1];
}
decomp.getDiagonal(diag,off);
// Tell the helper to work with this matrix
helper.init(diag,off,N);
if( computeVectors ) {
if( computeVectorsWithValues ) {
return extractTogether();
} else {
return extractSeparate(N);
}
} else {
return computeEigenValues();
}
} | [
"@",
"Override",
"public",
"boolean",
"decompose",
"(",
"DMatrixRMaj",
"orig",
")",
"{",
"if",
"(",
"orig",
".",
"numCols",
"!=",
"orig",
".",
"numRows",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Matrix must be square.\"",
")",
";",
"if",
"(",
"orig",
".",
"numCols",
"<=",
"0",
")",
"return",
"false",
";",
"int",
"N",
"=",
"orig",
".",
"numRows",
";",
"// compute a similar tridiagonal matrix",
"if",
"(",
"!",
"decomp",
".",
"decompose",
"(",
"orig",
")",
")",
"return",
"false",
";",
"if",
"(",
"diag",
"==",
"null",
"||",
"diag",
".",
"length",
"<",
"N",
")",
"{",
"diag",
"=",
"new",
"double",
"[",
"N",
"]",
";",
"off",
"=",
"new",
"double",
"[",
"N",
"-",
"1",
"]",
";",
"}",
"decomp",
".",
"getDiagonal",
"(",
"diag",
",",
"off",
")",
";",
"// Tell the helper to work with this matrix",
"helper",
".",
"init",
"(",
"diag",
",",
"off",
",",
"N",
")",
";",
"if",
"(",
"computeVectors",
")",
"{",
"if",
"(",
"computeVectorsWithValues",
")",
"{",
"return",
"extractTogether",
"(",
")",
";",
"}",
"else",
"{",
"return",
"extractSeparate",
"(",
"N",
")",
";",
"}",
"}",
"else",
"{",
"return",
"computeEigenValues",
"(",
")",
";",
"}",
"}"
] | Decomposes the matrix using the QR algorithm. Care was taken to minimize unnecessary memory copying
and cache skipping.
@param orig The matrix which is being decomposed. Not modified.
@return true if it decomposed the matrix or false if an error was detected. This will not catch all errors. | [
"Decomposes",
"the",
"matrix",
"using",
"the",
"QR",
"algorithm",
".",
"Care",
"was",
"taken",
"to",
"minimize",
"unnecessary",
"memory",
"copying",
"and",
"cache",
"skipping",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/SymmetricQRAlgorithmDecomposition_DDRM.java#L133-L164 |
162,561 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/SymmetricQRAlgorithmDecomposition_DDRM.java | SymmetricQRAlgorithmDecomposition_DDRM.computeEigenValues | private boolean computeEigenValues() {
// make a copy of the internal tridiagonal matrix data for later use
diagSaved = helper.copyDiag(diagSaved);
offSaved = helper.copyOff(offSaved);
vector.setQ(null);
vector.setFastEigenvalues(true);
// extract the eigenvalues
if( !vector.process(-1,null,null) )
return false;
// save a copy of them since this data structure will be recycled next
values = helper.copyEigenvalues(values);
return true;
} | java | private boolean computeEigenValues() {
// make a copy of the internal tridiagonal matrix data for later use
diagSaved = helper.copyDiag(diagSaved);
offSaved = helper.copyOff(offSaved);
vector.setQ(null);
vector.setFastEigenvalues(true);
// extract the eigenvalues
if( !vector.process(-1,null,null) )
return false;
// save a copy of them since this data structure will be recycled next
values = helper.copyEigenvalues(values);
return true;
} | [
"private",
"boolean",
"computeEigenValues",
"(",
")",
"{",
"// make a copy of the internal tridiagonal matrix data for later use",
"diagSaved",
"=",
"helper",
".",
"copyDiag",
"(",
"diagSaved",
")",
";",
"offSaved",
"=",
"helper",
".",
"copyOff",
"(",
"offSaved",
")",
";",
"vector",
".",
"setQ",
"(",
"null",
")",
";",
"vector",
".",
"setFastEigenvalues",
"(",
"true",
")",
";",
"// extract the eigenvalues",
"if",
"(",
"!",
"vector",
".",
"process",
"(",
"-",
"1",
",",
"null",
",",
"null",
")",
")",
"return",
"false",
";",
"// save a copy of them since this data structure will be recycled next",
"values",
"=",
"helper",
".",
"copyEigenvalues",
"(",
"values",
")",
";",
"return",
"true",
";",
"}"
] | Computes eigenvalues only
@return | [
"Computes",
"eigenvalues",
"only"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/SymmetricQRAlgorithmDecomposition_DDRM.java#L226-L241 |
162,562 | lessthanoptimal/ejml | main/ejml-zdense/src/org/ejml/dense/row/decompose/lu/LUDecompositionBase_ZDRM.java | LUDecompositionBase_ZDRM.solveL | protected void solveL(double[] vv) {
int ii = 0;
for( int i = 0; i < n; i++ ) {
int ip = indx[i];
double sumReal = vv[ip*2];
double sumImg = vv[ip*2+1];
vv[ip*2] = vv[i*2];
vv[ip*2+1] = vv[i*2+1];
if( ii != 0 ) {
// for( int j = ii-1; j < i; j++ )
// sum -= dataLU[i* n +j]*vv[j];
int index = i*stride + (ii-1)*2;
for( int j = ii-1; j < i; j++ ){
double luReal = dataLU[index++];
double luImg = dataLU[index++];
double vvReal = vv[j*2];
double vvImg = vv[j*2+1];
sumReal -= luReal*vvReal - luImg*vvImg;
sumImg -= luReal*vvImg + luImg*vvReal;
}
} else if( sumReal*sumReal + sumImg*sumImg != 0.0 ) {
ii=i+1;
}
vv[i*2] = sumReal;
vv[i*2+1] = sumImg;
}
} | java | protected void solveL(double[] vv) {
int ii = 0;
for( int i = 0; i < n; i++ ) {
int ip = indx[i];
double sumReal = vv[ip*2];
double sumImg = vv[ip*2+1];
vv[ip*2] = vv[i*2];
vv[ip*2+1] = vv[i*2+1];
if( ii != 0 ) {
// for( int j = ii-1; j < i; j++ )
// sum -= dataLU[i* n +j]*vv[j];
int index = i*stride + (ii-1)*2;
for( int j = ii-1; j < i; j++ ){
double luReal = dataLU[index++];
double luImg = dataLU[index++];
double vvReal = vv[j*2];
double vvImg = vv[j*2+1];
sumReal -= luReal*vvReal - luImg*vvImg;
sumImg -= luReal*vvImg + luImg*vvReal;
}
} else if( sumReal*sumReal + sumImg*sumImg != 0.0 ) {
ii=i+1;
}
vv[i*2] = sumReal;
vv[i*2+1] = sumImg;
}
} | [
"protected",
"void",
"solveL",
"(",
"double",
"[",
"]",
"vv",
")",
"{",
"int",
"ii",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"int",
"ip",
"=",
"indx",
"[",
"i",
"]",
";",
"double",
"sumReal",
"=",
"vv",
"[",
"ip",
"*",
"2",
"]",
";",
"double",
"sumImg",
"=",
"vv",
"[",
"ip",
"*",
"2",
"+",
"1",
"]",
";",
"vv",
"[",
"ip",
"*",
"2",
"]",
"=",
"vv",
"[",
"i",
"*",
"2",
"]",
";",
"vv",
"[",
"ip",
"*",
"2",
"+",
"1",
"]",
"=",
"vv",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
";",
"if",
"(",
"ii",
"!=",
"0",
")",
"{",
"// for( int j = ii-1; j < i; j++ )",
"// sum -= dataLU[i* n +j]*vv[j];",
"int",
"index",
"=",
"i",
"*",
"stride",
"+",
"(",
"ii",
"-",
"1",
")",
"*",
"2",
";",
"for",
"(",
"int",
"j",
"=",
"ii",
"-",
"1",
";",
"j",
"<",
"i",
";",
"j",
"++",
")",
"{",
"double",
"luReal",
"=",
"dataLU",
"[",
"index",
"++",
"]",
";",
"double",
"luImg",
"=",
"dataLU",
"[",
"index",
"++",
"]",
";",
"double",
"vvReal",
"=",
"vv",
"[",
"j",
"*",
"2",
"]",
";",
"double",
"vvImg",
"=",
"vv",
"[",
"j",
"*",
"2",
"+",
"1",
"]",
";",
"sumReal",
"-=",
"luReal",
"*",
"vvReal",
"-",
"luImg",
"*",
"vvImg",
";",
"sumImg",
"-=",
"luReal",
"*",
"vvImg",
"+",
"luImg",
"*",
"vvReal",
";",
"}",
"}",
"else",
"if",
"(",
"sumReal",
"*",
"sumReal",
"+",
"sumImg",
"*",
"sumImg",
"!=",
"0.0",
")",
"{",
"ii",
"=",
"i",
"+",
"1",
";",
"}",
"vv",
"[",
"i",
"*",
"2",
"]",
"=",
"sumReal",
";",
"vv",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
"=",
"sumImg",
";",
"}",
"}"
] | Solve the using the lower triangular matrix in LU. Diagonal elements are assumed
to be 1 | [
"Solve",
"the",
"using",
"the",
"lower",
"triangular",
"matrix",
"in",
"LU",
".",
"Diagonal",
"elements",
"are",
"assumed",
"to",
"be",
"1"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-zdense/src/org/ejml/dense/row/decompose/lu/LUDecompositionBase_ZDRM.java#L259-L291 |
162,563 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/chol/CholeskyBlockHelper_DDRM.java | CholeskyBlockHelper_DDRM.decompose | public boolean decompose(DMatrixRMaj mat , int indexStart , int n ) {
double m[] = mat.data;
double el_ii;
double div_el_ii=0;
for( int i = 0; i < n; i++ ) {
for( int j = i; j < n; j++ ) {
double sum = m[indexStart+i*mat.numCols+j];
int iEl = i*n;
int jEl = j*n;
int end = iEl+i;
// k = 0:i-1
for( ; iEl<end; iEl++,jEl++ ) {
// sum -= el[i*n+k]*el[j*n+k];
sum -= el[iEl]*el[jEl];
}
if( i == j ) {
// is it positive-definate?
if( sum <= 0.0 )
return false;
el_ii = Math.sqrt(sum);
el[i*n+i] = el_ii;
m[indexStart+i*mat.numCols+i] = el_ii;
div_el_ii = 1.0/el_ii;
} else {
double v = sum*div_el_ii;
el[j*n+i] = v;
m[indexStart+j*mat.numCols+i] = v;
}
}
}
return true;
} | java | public boolean decompose(DMatrixRMaj mat , int indexStart , int n ) {
double m[] = mat.data;
double el_ii;
double div_el_ii=0;
for( int i = 0; i < n; i++ ) {
for( int j = i; j < n; j++ ) {
double sum = m[indexStart+i*mat.numCols+j];
int iEl = i*n;
int jEl = j*n;
int end = iEl+i;
// k = 0:i-1
for( ; iEl<end; iEl++,jEl++ ) {
// sum -= el[i*n+k]*el[j*n+k];
sum -= el[iEl]*el[jEl];
}
if( i == j ) {
// is it positive-definate?
if( sum <= 0.0 )
return false;
el_ii = Math.sqrt(sum);
el[i*n+i] = el_ii;
m[indexStart+i*mat.numCols+i] = el_ii;
div_el_ii = 1.0/el_ii;
} else {
double v = sum*div_el_ii;
el[j*n+i] = v;
m[indexStart+j*mat.numCols+i] = v;
}
}
}
return true;
} | [
"public",
"boolean",
"decompose",
"(",
"DMatrixRMaj",
"mat",
",",
"int",
"indexStart",
",",
"int",
"n",
")",
"{",
"double",
"m",
"[",
"]",
"=",
"mat",
".",
"data",
";",
"double",
"el_ii",
";",
"double",
"div_el_ii",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"i",
";",
"j",
"<",
"n",
";",
"j",
"++",
")",
"{",
"double",
"sum",
"=",
"m",
"[",
"indexStart",
"+",
"i",
"*",
"mat",
".",
"numCols",
"+",
"j",
"]",
";",
"int",
"iEl",
"=",
"i",
"*",
"n",
";",
"int",
"jEl",
"=",
"j",
"*",
"n",
";",
"int",
"end",
"=",
"iEl",
"+",
"i",
";",
"// k = 0:i-1",
"for",
"(",
";",
"iEl",
"<",
"end",
";",
"iEl",
"++",
",",
"jEl",
"++",
")",
"{",
"// sum -= el[i*n+k]*el[j*n+k];",
"sum",
"-=",
"el",
"[",
"iEl",
"]",
"*",
"el",
"[",
"jEl",
"]",
";",
"}",
"if",
"(",
"i",
"==",
"j",
")",
"{",
"// is it positive-definate?",
"if",
"(",
"sum",
"<=",
"0.0",
")",
"return",
"false",
";",
"el_ii",
"=",
"Math",
".",
"sqrt",
"(",
"sum",
")",
";",
"el",
"[",
"i",
"*",
"n",
"+",
"i",
"]",
"=",
"el_ii",
";",
"m",
"[",
"indexStart",
"+",
"i",
"*",
"mat",
".",
"numCols",
"+",
"i",
"]",
"=",
"el_ii",
";",
"div_el_ii",
"=",
"1.0",
"/",
"el_ii",
";",
"}",
"else",
"{",
"double",
"v",
"=",
"sum",
"*",
"div_el_ii",
";",
"el",
"[",
"j",
"*",
"n",
"+",
"i",
"]",
"=",
"v",
";",
"m",
"[",
"indexStart",
"+",
"j",
"*",
"mat",
".",
"numCols",
"+",
"i",
"]",
"=",
"v",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Decomposes a submatrix. The results are written to the submatrix
and to its internal matrix L.
@param mat A matrix which has a submatrix that needs to be inverted
@param indexStart the first index of the submatrix
@param n The width of the submatrix that is to be inverted.
@return True if it was able to finish the decomposition. | [
"Decomposes",
"a",
"submatrix",
".",
"The",
"results",
"are",
"written",
"to",
"the",
"submatrix",
"and",
"to",
"its",
"internal",
"matrix",
"L",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/chol/CholeskyBlockHelper_DDRM.java#L59-L96 |
162,564 | lessthanoptimal/ejml | main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java | PermuteArray.createList | public static List<int[]> createList( int N )
{
int data[] = new int[ N ];
for( int i = 0; i < data.length; i++ ) {
data[i] = -1;
}
List<int[]> ret = new ArrayList<int[]>();
createList(data,0,-1,ret);
return ret;
} | java | public static List<int[]> createList( int N )
{
int data[] = new int[ N ];
for( int i = 0; i < data.length; i++ ) {
data[i] = -1;
}
List<int[]> ret = new ArrayList<int[]>();
createList(data,0,-1,ret);
return ret;
} | [
"public",
"static",
"List",
"<",
"int",
"[",
"]",
">",
"createList",
"(",
"int",
"N",
")",
"{",
"int",
"data",
"[",
"]",
"=",
"new",
"int",
"[",
"N",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"data",
"[",
"i",
"]",
"=",
"-",
"1",
";",
"}",
"List",
"<",
"int",
"[",
"]",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"int",
"[",
"]",
">",
"(",
")",
";",
"createList",
"(",
"data",
",",
"0",
",",
"-",
"1",
",",
"ret",
")",
";",
"return",
"ret",
";",
"}"
] | Creates a list of all permutations for a set with N elements.
@param N Number of elements in the list being permuted.
@return A list containing all the permutations. | [
"Creates",
"a",
"list",
"of",
"all",
"permutations",
"for",
"a",
"set",
"with",
"N",
"elements",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java#L107-L119 |
162,565 | lessthanoptimal/ejml | main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java | PermuteArray.createList | private static void createList( int data[], int k , int level , List<int[]> ret )
{
data[k] = level;
if( level < data.length-1 ) {
for( int i = 0; i < data.length; i++ ) {
if( data[i] == -1 ) {
createList(data,i,level+1,ret);
}
}
} else {
int []copy = new int[data.length];
System.arraycopy(data,0,copy,0,data.length);
ret.add(copy);
}
data[k] = -1;
} | java | private static void createList( int data[], int k , int level , List<int[]> ret )
{
data[k] = level;
if( level < data.length-1 ) {
for( int i = 0; i < data.length; i++ ) {
if( data[i] == -1 ) {
createList(data,i,level+1,ret);
}
}
} else {
int []copy = new int[data.length];
System.arraycopy(data,0,copy,0,data.length);
ret.add(copy);
}
data[k] = -1;
} | [
"private",
"static",
"void",
"createList",
"(",
"int",
"data",
"[",
"]",
",",
"int",
"k",
",",
"int",
"level",
",",
"List",
"<",
"int",
"[",
"]",
">",
"ret",
")",
"{",
"data",
"[",
"k",
"]",
"=",
"level",
";",
"if",
"(",
"level",
"<",
"data",
".",
"length",
"-",
"1",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"i",
"]",
"==",
"-",
"1",
")",
"{",
"createList",
"(",
"data",
",",
"i",
",",
"level",
"+",
"1",
",",
"ret",
")",
";",
"}",
"}",
"}",
"else",
"{",
"int",
"[",
"]",
"copy",
"=",
"new",
"int",
"[",
"data",
".",
"length",
"]",
";",
"System",
".",
"arraycopy",
"(",
"data",
",",
"0",
",",
"copy",
",",
"0",
",",
"data",
".",
"length",
")",
";",
"ret",
".",
"add",
"(",
"copy",
")",
";",
"}",
"data",
"[",
"k",
"]",
"=",
"-",
"1",
";",
"}"
] | Internal function that uses recursion to create the list | [
"Internal",
"function",
"that",
"uses",
"recursion",
"to",
"create",
"the",
"list"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java#L125-L141 |
162,566 | lessthanoptimal/ejml | main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java | PermuteArray.next | public int[] next()
{
boolean hasNewPerm = false;
escape:while( level >= 0) {
// boolean foundZero = false;
for( int i = iter[level]; i < data.length; i = iter[level] ) {
iter[level]++;
if( data[i] == -1 ) {
level++;
data[i] = level-1;
if( level >= data.length ) {
// a new permutation has been created return the results.
hasNewPerm = true;
System.arraycopy(data,0,ret,0,ret.length);
level = level-1;
data[i] = -1;
break escape;
} else {
valk[level] = i;
}
}
}
data[valk[level]] = -1;
iter[level] = 0;
level = level-1;
}
if( hasNewPerm )
return ret;
return null;
} | java | public int[] next()
{
boolean hasNewPerm = false;
escape:while( level >= 0) {
// boolean foundZero = false;
for( int i = iter[level]; i < data.length; i = iter[level] ) {
iter[level]++;
if( data[i] == -1 ) {
level++;
data[i] = level-1;
if( level >= data.length ) {
// a new permutation has been created return the results.
hasNewPerm = true;
System.arraycopy(data,0,ret,0,ret.length);
level = level-1;
data[i] = -1;
break escape;
} else {
valk[level] = i;
}
}
}
data[valk[level]] = -1;
iter[level] = 0;
level = level-1;
}
if( hasNewPerm )
return ret;
return null;
} | [
"public",
"int",
"[",
"]",
"next",
"(",
")",
"{",
"boolean",
"hasNewPerm",
"=",
"false",
";",
"escape",
":",
"while",
"(",
"level",
">=",
"0",
")",
"{",
"// boolean foundZero = false;",
"for",
"(",
"int",
"i",
"=",
"iter",
"[",
"level",
"]",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"=",
"iter",
"[",
"level",
"]",
")",
"{",
"iter",
"[",
"level",
"]",
"++",
";",
"if",
"(",
"data",
"[",
"i",
"]",
"==",
"-",
"1",
")",
"{",
"level",
"++",
";",
"data",
"[",
"i",
"]",
"=",
"level",
"-",
"1",
";",
"if",
"(",
"level",
">=",
"data",
".",
"length",
")",
"{",
"// a new permutation has been created return the results.",
"hasNewPerm",
"=",
"true",
";",
"System",
".",
"arraycopy",
"(",
"data",
",",
"0",
",",
"ret",
",",
"0",
",",
"ret",
".",
"length",
")",
";",
"level",
"=",
"level",
"-",
"1",
";",
"data",
"[",
"i",
"]",
"=",
"-",
"1",
";",
"break",
"escape",
";",
"}",
"else",
"{",
"valk",
"[",
"level",
"]",
"=",
"i",
";",
"}",
"}",
"}",
"data",
"[",
"valk",
"[",
"level",
"]",
"]",
"=",
"-",
"1",
";",
"iter",
"[",
"level",
"]",
"=",
"0",
";",
"level",
"=",
"level",
"-",
"1",
";",
"}",
"if",
"(",
"hasNewPerm",
")",
"return",
"ret",
";",
"return",
"null",
";",
"}"
] | Creates the next permutation in the sequence.
@return An array containing the permutation. The returned array is modified each time this function is called. | [
"Creates",
"the",
"next",
"permutation",
"in",
"the",
"sequence",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-experimental/src/org/ejml/dense/row/misc/PermuteArray.java#L148-L183 |
162,567 | lessthanoptimal/ejml | main/ejml-dsparse/src/org/ejml/sparse/triplet/RandomMatrices_DSTL.java | RandomMatrices_DSTL.uniform | public static DMatrixSparseTriplet uniform(int numRows , int numCols , int nz_total ,
double min , double max , Random rand ) {
// Create a list of all the possible element values
int N = numCols*numRows;
if( N < 0 )
throw new IllegalArgumentException("matrix size is too large");
nz_total = Math.min(N,nz_total);
int selected[] = new int[N];
for (int i = 0; i < N; i++) {
selected[i] = i;
}
for (int i = 0; i < nz_total; i++) {
int s = rand.nextInt(N);
int tmp = selected[s];
selected[s] = selected[i];
selected[i] = tmp;
}
// Create a sparse matrix
DMatrixSparseTriplet ret = new DMatrixSparseTriplet(numRows,numCols,nz_total);
for (int i = 0; i < nz_total; i++) {
int row = selected[i]/numCols;
int col = selected[i]%numCols;
double value = rand.nextDouble()*(max-min)+min;
ret.addItem(row,col, value);
}
return ret;
} | java | public static DMatrixSparseTriplet uniform(int numRows , int numCols , int nz_total ,
double min , double max , Random rand ) {
// Create a list of all the possible element values
int N = numCols*numRows;
if( N < 0 )
throw new IllegalArgumentException("matrix size is too large");
nz_total = Math.min(N,nz_total);
int selected[] = new int[N];
for (int i = 0; i < N; i++) {
selected[i] = i;
}
for (int i = 0; i < nz_total; i++) {
int s = rand.nextInt(N);
int tmp = selected[s];
selected[s] = selected[i];
selected[i] = tmp;
}
// Create a sparse matrix
DMatrixSparseTriplet ret = new DMatrixSparseTriplet(numRows,numCols,nz_total);
for (int i = 0; i < nz_total; i++) {
int row = selected[i]/numCols;
int col = selected[i]%numCols;
double value = rand.nextDouble()*(max-min)+min;
ret.addItem(row,col, value);
}
return ret;
} | [
"public",
"static",
"DMatrixSparseTriplet",
"uniform",
"(",
"int",
"numRows",
",",
"int",
"numCols",
",",
"int",
"nz_total",
",",
"double",
"min",
",",
"double",
"max",
",",
"Random",
"rand",
")",
"{",
"// Create a list of all the possible element values",
"int",
"N",
"=",
"numCols",
"*",
"numRows",
";",
"if",
"(",
"N",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"matrix size is too large\"",
")",
";",
"nz_total",
"=",
"Math",
".",
"min",
"(",
"N",
",",
"nz_total",
")",
";",
"int",
"selected",
"[",
"]",
"=",
"new",
"int",
"[",
"N",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"selected",
"[",
"i",
"]",
"=",
"i",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nz_total",
";",
"i",
"++",
")",
"{",
"int",
"s",
"=",
"rand",
".",
"nextInt",
"(",
"N",
")",
";",
"int",
"tmp",
"=",
"selected",
"[",
"s",
"]",
";",
"selected",
"[",
"s",
"]",
"=",
"selected",
"[",
"i",
"]",
";",
"selected",
"[",
"i",
"]",
"=",
"tmp",
";",
"}",
"// Create a sparse matrix",
"DMatrixSparseTriplet",
"ret",
"=",
"new",
"DMatrixSparseTriplet",
"(",
"numRows",
",",
"numCols",
",",
"nz_total",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nz_total",
";",
"i",
"++",
")",
"{",
"int",
"row",
"=",
"selected",
"[",
"i",
"]",
"/",
"numCols",
";",
"int",
"col",
"=",
"selected",
"[",
"i",
"]",
"%",
"numCols",
";",
"double",
"value",
"=",
"rand",
".",
"nextDouble",
"(",
")",
"*",
"(",
"max",
"-",
"min",
")",
"+",
"min",
";",
"ret",
".",
"addItem",
"(",
"row",
",",
"col",
",",
"value",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Randomly generates matrix with the specified number of matrix elements filled with values from min to max.
@param numRows Number of rows
@param numCols Number of columns
@param nz_total Total number of non-zero elements in the matrix
@param min Minimum value
@param max maximum value
@param rand Random number generated
@return Randomly generated matrix | [
"Randomly",
"generates",
"matrix",
"with",
"the",
"specified",
"number",
"of",
"matrix",
"elements",
"filled",
"with",
"values",
"from",
"min",
"to",
"max",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-dsparse/src/org/ejml/sparse/triplet/RandomMatrices_DSTL.java#L40-L73 |
162,568 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java | BlockHouseHolder_DDRB.decomposeQR_block_col | public static boolean decomposeQR_block_col( final int blockLength ,
final DSubmatrixD1 Y ,
final double gamma[] )
{
int width = Y.col1-Y.col0;
int height = Y.row1-Y.row0;
int min = Math.min(width,height);
for( int i = 0; i < min; i++ ) {
// compute the householder vector
if (!computeHouseHolderCol(blockLength, Y, gamma, i))
return false;
// apply to rest of the columns in the block
rank1UpdateMultR_Col(blockLength,Y,i,gamma[Y.col0+i]);
}
return true;
} | java | public static boolean decomposeQR_block_col( final int blockLength ,
final DSubmatrixD1 Y ,
final double gamma[] )
{
int width = Y.col1-Y.col0;
int height = Y.row1-Y.row0;
int min = Math.min(width,height);
for( int i = 0; i < min; i++ ) {
// compute the householder vector
if (!computeHouseHolderCol(blockLength, Y, gamma, i))
return false;
// apply to rest of the columns in the block
rank1UpdateMultR_Col(blockLength,Y,i,gamma[Y.col0+i]);
}
return true;
} | [
"public",
"static",
"boolean",
"decomposeQR_block_col",
"(",
"final",
"int",
"blockLength",
",",
"final",
"DSubmatrixD1",
"Y",
",",
"final",
"double",
"gamma",
"[",
"]",
")",
"{",
"int",
"width",
"=",
"Y",
".",
"col1",
"-",
"Y",
".",
"col0",
";",
"int",
"height",
"=",
"Y",
".",
"row1",
"-",
"Y",
".",
"row0",
";",
"int",
"min",
"=",
"Math",
".",
"min",
"(",
"width",
",",
"height",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"min",
";",
"i",
"++",
")",
"{",
"// compute the householder vector",
"if",
"(",
"!",
"computeHouseHolderCol",
"(",
"blockLength",
",",
"Y",
",",
"gamma",
",",
"i",
")",
")",
"return",
"false",
";",
"// apply to rest of the columns in the block",
"rank1UpdateMultR_Col",
"(",
"blockLength",
",",
"Y",
",",
"i",
",",
"gamma",
"[",
"Y",
".",
"col0",
"+",
"i",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Performs a standard QR decomposition on the specified submatrix that is one block wide.
@param blockLength
@param Y
@param gamma | [
"Performs",
"a",
"standard",
"QR",
"decomposition",
"on",
"the",
"specified",
"submatrix",
"that",
"is",
"one",
"block",
"wide",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java#L50-L67 |
162,569 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java | BlockHouseHolder_DDRB.divideElementsCol | public static void divideElementsCol(final int blockLength ,
final DSubmatrixD1 Y , final int col , final double val ) {
final int width = Math.min(blockLength,Y.col1-Y.col0);
final double dataY[] = Y.original.data;
for( int i = Y.row0; i < Y.row1; i += blockLength ) {
int height = Math.min( blockLength , Y.row1 - i );
int index = i*Y.original.numCols + height*Y.col0 + col;
if( i == Y.row0 ) {
index += width*(col+1);
for( int k = col+1; k < height; k++ , index += width ) {
dataY[index] /= val;
}
} else {
int endIndex = index + width*height;
//for( int k = 0; k < height; k++
for( ; index != endIndex; index += width ) {
dataY[index] /= val;
}
}
}
} | java | public static void divideElementsCol(final int blockLength ,
final DSubmatrixD1 Y , final int col , final double val ) {
final int width = Math.min(blockLength,Y.col1-Y.col0);
final double dataY[] = Y.original.data;
for( int i = Y.row0; i < Y.row1; i += blockLength ) {
int height = Math.min( blockLength , Y.row1 - i );
int index = i*Y.original.numCols + height*Y.col0 + col;
if( i == Y.row0 ) {
index += width*(col+1);
for( int k = col+1; k < height; k++ , index += width ) {
dataY[index] /= val;
}
} else {
int endIndex = index + width*height;
//for( int k = 0; k < height; k++
for( ; index != endIndex; index += width ) {
dataY[index] /= val;
}
}
}
} | [
"public",
"static",
"void",
"divideElementsCol",
"(",
"final",
"int",
"blockLength",
",",
"final",
"DSubmatrixD1",
"Y",
",",
"final",
"int",
"col",
",",
"final",
"double",
"val",
")",
"{",
"final",
"int",
"width",
"=",
"Math",
".",
"min",
"(",
"blockLength",
",",
"Y",
".",
"col1",
"-",
"Y",
".",
"col0",
")",
";",
"final",
"double",
"dataY",
"[",
"]",
"=",
"Y",
".",
"original",
".",
"data",
";",
"for",
"(",
"int",
"i",
"=",
"Y",
".",
"row0",
";",
"i",
"<",
"Y",
".",
"row1",
";",
"i",
"+=",
"blockLength",
")",
"{",
"int",
"height",
"=",
"Math",
".",
"min",
"(",
"blockLength",
",",
"Y",
".",
"row1",
"-",
"i",
")",
";",
"int",
"index",
"=",
"i",
"*",
"Y",
".",
"original",
".",
"numCols",
"+",
"height",
"*",
"Y",
".",
"col0",
"+",
"col",
";",
"if",
"(",
"i",
"==",
"Y",
".",
"row0",
")",
"{",
"index",
"+=",
"width",
"*",
"(",
"col",
"+",
"1",
")",
";",
"for",
"(",
"int",
"k",
"=",
"col",
"+",
"1",
";",
"k",
"<",
"height",
";",
"k",
"++",
",",
"index",
"+=",
"width",
")",
"{",
"dataY",
"[",
"index",
"]",
"/=",
"val",
";",
"}",
"}",
"else",
"{",
"int",
"endIndex",
"=",
"index",
"+",
"width",
"*",
"height",
";",
"//for( int k = 0; k < height; k++",
"for",
"(",
";",
"index",
"!=",
"endIndex",
";",
"index",
"+=",
"width",
")",
"{",
"dataY",
"[",
"index",
"]",
"/=",
"val",
";",
"}",
"}",
"}",
"}"
] | Divides the elements at the specified column by 'val'. Takes in account
leading zeros and one. | [
"Divides",
"the",
"elements",
"at",
"the",
"specified",
"column",
"by",
"val",
".",
"Takes",
"in",
"account",
"leading",
"zeros",
"and",
"one",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java#L478-L503 |
162,570 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java | BlockHouseHolder_DDRB.multAdd_zeros | public static void multAdd_zeros(final int blockLength ,
final DSubmatrixD1 Y , final DSubmatrixD1 B ,
final DSubmatrixD1 C )
{
int widthY = Y.col1 - Y.col0;
for( int i = Y.row0; i < Y.row1; i += blockLength ) {
int heightY = Math.min( blockLength , Y.row1 - i );
for( int j = B.col0; j < B.col1; j += blockLength ) {
int widthB = Math.min( blockLength , B.col1 - j );
int indexC = (i-Y.row0+C.row0)*C.original.numCols + (j-B.col0+C.col0)*heightY;
for( int k = Y.col0; k < Y.col1; k += blockLength ) {
int indexY = i*Y.original.numCols + k*heightY;
int indexB = (k-Y.col0+B.row0)*B.original.numCols + j*widthY;
if( i == Y.row0 ) {
multBlockAdd_zerosone(Y.original.data,B.original.data,C.original.data,
indexY,indexB,indexC,heightY,widthY,widthB);
} else {
InnerMultiplication_DDRB.blockMultPlus(Y.original.data,B.original.data,C.original.data,
indexY,indexB,indexC,heightY,widthY,widthB);
}
}
}
}
} | java | public static void multAdd_zeros(final int blockLength ,
final DSubmatrixD1 Y , final DSubmatrixD1 B ,
final DSubmatrixD1 C )
{
int widthY = Y.col1 - Y.col0;
for( int i = Y.row0; i < Y.row1; i += blockLength ) {
int heightY = Math.min( blockLength , Y.row1 - i );
for( int j = B.col0; j < B.col1; j += blockLength ) {
int widthB = Math.min( blockLength , B.col1 - j );
int indexC = (i-Y.row0+C.row0)*C.original.numCols + (j-B.col0+C.col0)*heightY;
for( int k = Y.col0; k < Y.col1; k += blockLength ) {
int indexY = i*Y.original.numCols + k*heightY;
int indexB = (k-Y.col0+B.row0)*B.original.numCols + j*widthY;
if( i == Y.row0 ) {
multBlockAdd_zerosone(Y.original.data,B.original.data,C.original.data,
indexY,indexB,indexC,heightY,widthY,widthB);
} else {
InnerMultiplication_DDRB.blockMultPlus(Y.original.data,B.original.data,C.original.data,
indexY,indexB,indexC,heightY,widthY,widthB);
}
}
}
}
} | [
"public",
"static",
"void",
"multAdd_zeros",
"(",
"final",
"int",
"blockLength",
",",
"final",
"DSubmatrixD1",
"Y",
",",
"final",
"DSubmatrixD1",
"B",
",",
"final",
"DSubmatrixD1",
"C",
")",
"{",
"int",
"widthY",
"=",
"Y",
".",
"col1",
"-",
"Y",
".",
"col0",
";",
"for",
"(",
"int",
"i",
"=",
"Y",
".",
"row0",
";",
"i",
"<",
"Y",
".",
"row1",
";",
"i",
"+=",
"blockLength",
")",
"{",
"int",
"heightY",
"=",
"Math",
".",
"min",
"(",
"blockLength",
",",
"Y",
".",
"row1",
"-",
"i",
")",
";",
"for",
"(",
"int",
"j",
"=",
"B",
".",
"col0",
";",
"j",
"<",
"B",
".",
"col1",
";",
"j",
"+=",
"blockLength",
")",
"{",
"int",
"widthB",
"=",
"Math",
".",
"min",
"(",
"blockLength",
",",
"B",
".",
"col1",
"-",
"j",
")",
";",
"int",
"indexC",
"=",
"(",
"i",
"-",
"Y",
".",
"row0",
"+",
"C",
".",
"row0",
")",
"*",
"C",
".",
"original",
".",
"numCols",
"+",
"(",
"j",
"-",
"B",
".",
"col0",
"+",
"C",
".",
"col0",
")",
"*",
"heightY",
";",
"for",
"(",
"int",
"k",
"=",
"Y",
".",
"col0",
";",
"k",
"<",
"Y",
".",
"col1",
";",
"k",
"+=",
"blockLength",
")",
"{",
"int",
"indexY",
"=",
"i",
"*",
"Y",
".",
"original",
".",
"numCols",
"+",
"k",
"*",
"heightY",
";",
"int",
"indexB",
"=",
"(",
"k",
"-",
"Y",
".",
"col0",
"+",
"B",
".",
"row0",
")",
"*",
"B",
".",
"original",
".",
"numCols",
"+",
"j",
"*",
"widthY",
";",
"if",
"(",
"i",
"==",
"Y",
".",
"row0",
")",
"{",
"multBlockAdd_zerosone",
"(",
"Y",
".",
"original",
".",
"data",
",",
"B",
".",
"original",
".",
"data",
",",
"C",
".",
"original",
".",
"data",
",",
"indexY",
",",
"indexB",
",",
"indexC",
",",
"heightY",
",",
"widthY",
",",
"widthB",
")",
";",
"}",
"else",
"{",
"InnerMultiplication_DDRB",
".",
"blockMultPlus",
"(",
"Y",
".",
"original",
".",
"data",
",",
"B",
".",
"original",
".",
"data",
",",
"C",
".",
"original",
".",
"data",
",",
"indexY",
",",
"indexB",
",",
"indexC",
",",
"heightY",
",",
"widthY",
",",
"widthB",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Special multiplication that takes in account the zeros and one in Y, which
is the matrix that stores the householder vectors. | [
"Special",
"multiplication",
"that",
"takes",
"in",
"account",
"the",
"zeros",
"and",
"one",
"in",
"Y",
"which",
"is",
"the",
"matrix",
"that",
"stores",
"the",
"householder",
"vectors",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/decomposition/qr/BlockHouseHolder_DDRB.java#L919-L947 |
162,571 | lessthanoptimal/ejml | examples/src/org/ejml/example/EquationCustomFunction.java | EquationCustomFunction.createMultTransA | public static ManagerFunctions.InputN createMultTransA() {
return (inputs, manager) -> {
if( inputs.size() != 2 )
throw new RuntimeException("Two inputs required");
final Variable varA = inputs.get(0);
final Variable varB = inputs.get(1);
Operation.Info ret = new Operation.Info();
if( varA instanceof VariableMatrix && varB instanceof VariableMatrix ) {
// The output matrix or scalar variable must be created with the provided manager
final VariableMatrix output = manager.createMatrix();
ret.output = output;
ret.op = new Operation("multTransA-mm") {
@Override
public void process() {
DMatrixRMaj mA = ((VariableMatrix)varA).matrix;
DMatrixRMaj mB = ((VariableMatrix)varB).matrix;
CommonOps_DDRM.multTransA(mA,mB,output.matrix);
}
};
} else {
throw new IllegalArgumentException("Expected both inputs to be a matrix");
}
return ret;
};
} | java | public static ManagerFunctions.InputN createMultTransA() {
return (inputs, manager) -> {
if( inputs.size() != 2 )
throw new RuntimeException("Two inputs required");
final Variable varA = inputs.get(0);
final Variable varB = inputs.get(1);
Operation.Info ret = new Operation.Info();
if( varA instanceof VariableMatrix && varB instanceof VariableMatrix ) {
// The output matrix or scalar variable must be created with the provided manager
final VariableMatrix output = manager.createMatrix();
ret.output = output;
ret.op = new Operation("multTransA-mm") {
@Override
public void process() {
DMatrixRMaj mA = ((VariableMatrix)varA).matrix;
DMatrixRMaj mB = ((VariableMatrix)varB).matrix;
CommonOps_DDRM.multTransA(mA,mB,output.matrix);
}
};
} else {
throw new IllegalArgumentException("Expected both inputs to be a matrix");
}
return ret;
};
} | [
"public",
"static",
"ManagerFunctions",
".",
"InputN",
"createMultTransA",
"(",
")",
"{",
"return",
"(",
"inputs",
",",
"manager",
")",
"->",
"{",
"if",
"(",
"inputs",
".",
"size",
"(",
")",
"!=",
"2",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Two inputs required\"",
")",
";",
"final",
"Variable",
"varA",
"=",
"inputs",
".",
"get",
"(",
"0",
")",
";",
"final",
"Variable",
"varB",
"=",
"inputs",
".",
"get",
"(",
"1",
")",
";",
"Operation",
".",
"Info",
"ret",
"=",
"new",
"Operation",
".",
"Info",
"(",
")",
";",
"if",
"(",
"varA",
"instanceof",
"VariableMatrix",
"&&",
"varB",
"instanceof",
"VariableMatrix",
")",
"{",
"// The output matrix or scalar variable must be created with the provided manager",
"final",
"VariableMatrix",
"output",
"=",
"manager",
".",
"createMatrix",
"(",
")",
";",
"ret",
".",
"output",
"=",
"output",
";",
"ret",
".",
"op",
"=",
"new",
"Operation",
"(",
"\"multTransA-mm\"",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
")",
"{",
"DMatrixRMaj",
"mA",
"=",
"(",
"(",
"VariableMatrix",
")",
"varA",
")",
".",
"matrix",
";",
"DMatrixRMaj",
"mB",
"=",
"(",
"(",
"VariableMatrix",
")",
"varB",
")",
".",
"matrix",
";",
"CommonOps_DDRM",
".",
"multTransA",
"(",
"mA",
",",
"mB",
",",
"output",
".",
"matrix",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Expected both inputs to be a matrix\"",
")",
";",
"}",
"return",
"ret",
";",
"}",
";",
"}"
] | Create the function. Be sure to handle all possible input types and combinations correctly and provide
meaningful error messages. The output matrix should be resized to fit the inputs. | [
"Create",
"the",
"function",
".",
"Be",
"sure",
"to",
"handle",
"all",
"possible",
"input",
"types",
"and",
"combinations",
"correctly",
"and",
"provide",
"meaningful",
"error",
"messages",
".",
"The",
"output",
"matrix",
"should",
"be",
"resized",
"to",
"fit",
"the",
"inputs",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/examples/src/org/ejml/example/EquationCustomFunction.java#L60-L90 |
162,572 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java | SpecializedOps_DDRM.copyChangeRow | public static DMatrixRMaj copyChangeRow(int order[] , DMatrixRMaj src , DMatrixRMaj dst )
{
if( dst == null ) {
dst = new DMatrixRMaj(src.numRows,src.numCols);
} else if( src.numRows != dst.numRows || src.numCols != dst.numCols ) {
throw new IllegalArgumentException("src and dst must have the same dimensions.");
}
for( int i = 0; i < src.numRows; i++ ) {
int indexDst = i*src.numCols;
int indexSrc = order[i]*src.numCols;
System.arraycopy(src.data,indexSrc,dst.data,indexDst,src.numCols);
}
return dst;
} | java | public static DMatrixRMaj copyChangeRow(int order[] , DMatrixRMaj src , DMatrixRMaj dst )
{
if( dst == null ) {
dst = new DMatrixRMaj(src.numRows,src.numCols);
} else if( src.numRows != dst.numRows || src.numCols != dst.numCols ) {
throw new IllegalArgumentException("src and dst must have the same dimensions.");
}
for( int i = 0; i < src.numRows; i++ ) {
int indexDst = i*src.numCols;
int indexSrc = order[i]*src.numCols;
System.arraycopy(src.data,indexSrc,dst.data,indexDst,src.numCols);
}
return dst;
} | [
"public",
"static",
"DMatrixRMaj",
"copyChangeRow",
"(",
"int",
"order",
"[",
"]",
",",
"DMatrixRMaj",
"src",
",",
"DMatrixRMaj",
"dst",
")",
"{",
"if",
"(",
"dst",
"==",
"null",
")",
"{",
"dst",
"=",
"new",
"DMatrixRMaj",
"(",
"src",
".",
"numRows",
",",
"src",
".",
"numCols",
")",
";",
"}",
"else",
"if",
"(",
"src",
".",
"numRows",
"!=",
"dst",
".",
"numRows",
"||",
"src",
".",
"numCols",
"!=",
"dst",
".",
"numCols",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"src and dst must have the same dimensions.\"",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"src",
".",
"numRows",
";",
"i",
"++",
")",
"{",
"int",
"indexDst",
"=",
"i",
"*",
"src",
".",
"numCols",
";",
"int",
"indexSrc",
"=",
"order",
"[",
"i",
"]",
"*",
"src",
".",
"numCols",
";",
"System",
".",
"arraycopy",
"(",
"src",
".",
"data",
",",
"indexSrc",
",",
"dst",
".",
"data",
",",
"indexDst",
",",
"src",
".",
"numCols",
")",
";",
"}",
"return",
"dst",
";",
"}"
] | Creates a copy of a matrix but swaps the rows as specified by the order array.
@param order Specifies which row in the dest corresponds to a row in the src. Not modified.
@param src The original matrix. Not modified.
@param dst A Matrix that is a row swapped copy of src. Modified. | [
"Creates",
"a",
"copy",
"of",
"a",
"matrix",
"but",
"swaps",
"the",
"rows",
"as",
"specified",
"by",
"the",
"order",
"array",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java#L97-L113 |
162,573 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java | SpecializedOps_DDRM.copyTriangle | public static DMatrixRMaj copyTriangle(DMatrixRMaj src , DMatrixRMaj dst , boolean upper ) {
if( dst == null ) {
dst = new DMatrixRMaj(src.numRows,src.numCols);
} else if( src.numRows != dst.numRows || src.numCols != dst.numCols ) {
throw new IllegalArgumentException("src and dst must have the same dimensions.");
}
if( upper ) {
int N = Math.min(src.numRows,src.numCols);
for( int i = 0; i < N; i++ ) {
int index = i*src.numCols+i;
System.arraycopy(src.data,index,dst.data,index,src.numCols-i);
}
} else {
for( int i = 0; i < src.numRows; i++ ) {
int length = Math.min(i+1,src.numCols);
int index = i*src.numCols;
System.arraycopy(src.data,index,dst.data,index,length);
}
}
return dst;
} | java | public static DMatrixRMaj copyTriangle(DMatrixRMaj src , DMatrixRMaj dst , boolean upper ) {
if( dst == null ) {
dst = new DMatrixRMaj(src.numRows,src.numCols);
} else if( src.numRows != dst.numRows || src.numCols != dst.numCols ) {
throw new IllegalArgumentException("src and dst must have the same dimensions.");
}
if( upper ) {
int N = Math.min(src.numRows,src.numCols);
for( int i = 0; i < N; i++ ) {
int index = i*src.numCols+i;
System.arraycopy(src.data,index,dst.data,index,src.numCols-i);
}
} else {
for( int i = 0; i < src.numRows; i++ ) {
int length = Math.min(i+1,src.numCols);
int index = i*src.numCols;
System.arraycopy(src.data,index,dst.data,index,length);
}
}
return dst;
} | [
"public",
"static",
"DMatrixRMaj",
"copyTriangle",
"(",
"DMatrixRMaj",
"src",
",",
"DMatrixRMaj",
"dst",
",",
"boolean",
"upper",
")",
"{",
"if",
"(",
"dst",
"==",
"null",
")",
"{",
"dst",
"=",
"new",
"DMatrixRMaj",
"(",
"src",
".",
"numRows",
",",
"src",
".",
"numCols",
")",
";",
"}",
"else",
"if",
"(",
"src",
".",
"numRows",
"!=",
"dst",
".",
"numRows",
"||",
"src",
".",
"numCols",
"!=",
"dst",
".",
"numCols",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"src and dst must have the same dimensions.\"",
")",
";",
"}",
"if",
"(",
"upper",
")",
"{",
"int",
"N",
"=",
"Math",
".",
"min",
"(",
"src",
".",
"numRows",
",",
"src",
".",
"numCols",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"int",
"index",
"=",
"i",
"*",
"src",
".",
"numCols",
"+",
"i",
";",
"System",
".",
"arraycopy",
"(",
"src",
".",
"data",
",",
"index",
",",
"dst",
".",
"data",
",",
"index",
",",
"src",
".",
"numCols",
"-",
"i",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"src",
".",
"numRows",
";",
"i",
"++",
")",
"{",
"int",
"length",
"=",
"Math",
".",
"min",
"(",
"i",
"+",
"1",
",",
"src",
".",
"numCols",
")",
";",
"int",
"index",
"=",
"i",
"*",
"src",
".",
"numCols",
";",
"System",
".",
"arraycopy",
"(",
"src",
".",
"data",
",",
"index",
",",
"dst",
".",
"data",
",",
"index",
",",
"length",
")",
";",
"}",
"}",
"return",
"dst",
";",
"}"
] | Copies just the upper or lower triangular portion of a matrix.
@param src Matrix being copied. Not modified.
@param dst Where just a triangle from src is copied. If null a new one will be created. Modified.
@param upper If the upper or lower triangle should be copied.
@return The copied matrix. | [
"Copies",
"just",
"the",
"upper",
"or",
"lower",
"triangular",
"portion",
"of",
"a",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java#L123-L145 |
162,574 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java | SpecializedOps_DDRM.splitIntoVectors | public static DMatrixRMaj[] splitIntoVectors(DMatrix1Row A , boolean column )
{
int w = column ? A.numCols : A.numRows;
int M = column ? A.numRows : 1;
int N = column ? 1 : A.numCols;
int o = Math.max(M,N);
DMatrixRMaj[] ret = new DMatrixRMaj[w];
for( int i = 0; i < w; i++ ) {
DMatrixRMaj a = new DMatrixRMaj(M,N);
if( column )
subvector(A,0,i,o,false,0,a);
else
subvector(A,i,0,o,true,0,a);
ret[i] = a;
}
return ret;
} | java | public static DMatrixRMaj[] splitIntoVectors(DMatrix1Row A , boolean column )
{
int w = column ? A.numCols : A.numRows;
int M = column ? A.numRows : 1;
int N = column ? 1 : A.numCols;
int o = Math.max(M,N);
DMatrixRMaj[] ret = new DMatrixRMaj[w];
for( int i = 0; i < w; i++ ) {
DMatrixRMaj a = new DMatrixRMaj(M,N);
if( column )
subvector(A,0,i,o,false,0,a);
else
subvector(A,i,0,o,true,0,a);
ret[i] = a;
}
return ret;
} | [
"public",
"static",
"DMatrixRMaj",
"[",
"]",
"splitIntoVectors",
"(",
"DMatrix1Row",
"A",
",",
"boolean",
"column",
")",
"{",
"int",
"w",
"=",
"column",
"?",
"A",
".",
"numCols",
":",
"A",
".",
"numRows",
";",
"int",
"M",
"=",
"column",
"?",
"A",
".",
"numRows",
":",
"1",
";",
"int",
"N",
"=",
"column",
"?",
"1",
":",
"A",
".",
"numCols",
";",
"int",
"o",
"=",
"Math",
".",
"max",
"(",
"M",
",",
"N",
")",
";",
"DMatrixRMaj",
"[",
"]",
"ret",
"=",
"new",
"DMatrixRMaj",
"[",
"w",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"w",
";",
"i",
"++",
")",
"{",
"DMatrixRMaj",
"a",
"=",
"new",
"DMatrixRMaj",
"(",
"M",
",",
"N",
")",
";",
"if",
"(",
"column",
")",
"subvector",
"(",
"A",
",",
"0",
",",
"i",
",",
"o",
",",
"false",
",",
"0",
",",
"a",
")",
";",
"else",
"subvector",
"(",
"A",
",",
"i",
",",
"0",
",",
"o",
",",
"true",
",",
"0",
",",
"a",
")",
";",
"ret",
"[",
"i",
"]",
"=",
"a",
";",
"}",
"return",
"ret",
";",
"}"
] | Takes a matrix and splits it into a set of row or column vectors.
@param A original matrix.
@param column If true then column vectors will be created.
@return Set of vectors. | [
"Takes",
"a",
"matrix",
"and",
"splits",
"it",
"into",
"a",
"set",
"of",
"row",
"or",
"column",
"vectors",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java#L339-L362 |
162,575 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java | SpecializedOps_DDRM.diagProd | public static double diagProd( DMatrix1Row T )
{
double prod = 1.0;
int N = Math.min(T.numRows,T.numCols);
for( int i = 0; i < N; i++ ) {
prod *= T.unsafe_get(i,i);
}
return prod;
} | java | public static double diagProd( DMatrix1Row T )
{
double prod = 1.0;
int N = Math.min(T.numRows,T.numCols);
for( int i = 0; i < N; i++ ) {
prod *= T.unsafe_get(i,i);
}
return prod;
} | [
"public",
"static",
"double",
"diagProd",
"(",
"DMatrix1Row",
"T",
")",
"{",
"double",
"prod",
"=",
"1.0",
";",
"int",
"N",
"=",
"Math",
".",
"min",
"(",
"T",
".",
"numRows",
",",
"T",
".",
"numCols",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"prod",
"*=",
"T",
".",
"unsafe_get",
"(",
"i",
",",
"i",
")",
";",
"}",
"return",
"prod",
";",
"}"
] | Computes the product of the diagonal elements. For a diagonal or triangular
matrix this is the determinant.
@param T A matrix.
@return product of the diagonal elements. | [
"Computes",
"the",
"product",
"of",
"the",
"diagonal",
"elements",
".",
"For",
"a",
"diagonal",
"or",
"triangular",
"matrix",
"this",
"is",
"the",
"determinant",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java#L410-L419 |
162,576 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java | SpecializedOps_DDRM.elementSumSq | public static double elementSumSq( DMatrixD1 m ) {
// minimize round off error
double maxAbs = CommonOps_DDRM.elementMaxAbs(m);
if( maxAbs == 0)
return 0;
double total = 0;
int N = m.getNumElements();
for( int i = 0; i < N; i++ ) {
double d = m.data[i]/maxAbs;
total += d*d;
}
return maxAbs*total*maxAbs;
} | java | public static double elementSumSq( DMatrixD1 m ) {
// minimize round off error
double maxAbs = CommonOps_DDRM.elementMaxAbs(m);
if( maxAbs == 0)
return 0;
double total = 0;
int N = m.getNumElements();
for( int i = 0; i < N; i++ ) {
double d = m.data[i]/maxAbs;
total += d*d;
}
return maxAbs*total*maxAbs;
} | [
"public",
"static",
"double",
"elementSumSq",
"(",
"DMatrixD1",
"m",
")",
"{",
"// minimize round off error",
"double",
"maxAbs",
"=",
"CommonOps_DDRM",
".",
"elementMaxAbs",
"(",
"m",
")",
";",
"if",
"(",
"maxAbs",
"==",
"0",
")",
"return",
"0",
";",
"double",
"total",
"=",
"0",
";",
"int",
"N",
"=",
"m",
".",
"getNumElements",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"double",
"d",
"=",
"m",
".",
"data",
"[",
"i",
"]",
"/",
"maxAbs",
";",
"total",
"+=",
"d",
"*",
"d",
";",
"}",
"return",
"maxAbs",
"*",
"total",
"*",
"maxAbs",
";",
"}"
] | Sums up the square of each element in the matrix. This is equivalent to the
Frobenius norm squared.
@param m Matrix.
@return Sum of elements squared. | [
"Sums",
"up",
"the",
"square",
"of",
"each",
"element",
"in",
"the",
"matrix",
".",
"This",
"is",
"equivalent",
"to",
"the",
"Frobenius",
"norm",
"squared",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/SpecializedOps_DDRM.java#L480-L496 |
162,577 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java | SymmetricQREigenHelper_DDRM.init | public void init( double diag[] ,
double off[],
int numCols ) {
reset(numCols);
this.diag = diag;
this.off = off;
} | java | public void init( double diag[] ,
double off[],
int numCols ) {
reset(numCols);
this.diag = diag;
this.off = off;
} | [
"public",
"void",
"init",
"(",
"double",
"diag",
"[",
"]",
",",
"double",
"off",
"[",
"]",
",",
"int",
"numCols",
")",
"{",
"reset",
"(",
"numCols",
")",
";",
"this",
".",
"diag",
"=",
"diag",
";",
"this",
".",
"off",
"=",
"off",
";",
"}"
] | Sets up and declares internal data structures.
@param diag Diagonal elements from tridiagonal matrix. Modified.
@param off Off diagonal elements from tridiagonal matrix. Modified.
@param numCols number of columns (and rows) in the matrix. | [
"Sets",
"up",
"and",
"declares",
"internal",
"data",
"structures",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java#L106-L113 |
162,578 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java | SymmetricQREigenHelper_DDRM.reset | public void reset( int N ) {
this.N = N;
this.diag = null;
this.off = null;
if( splits.length < N ) {
splits = new int[N];
}
numSplits = 0;
x1 = 0;
x2 = N-1;
steps = numExceptional = lastExceptional = 0;
this.Q = null;
} | java | public void reset( int N ) {
this.N = N;
this.diag = null;
this.off = null;
if( splits.length < N ) {
splits = new int[N];
}
numSplits = 0;
x1 = 0;
x2 = N-1;
steps = numExceptional = lastExceptional = 0;
this.Q = null;
} | [
"public",
"void",
"reset",
"(",
"int",
"N",
")",
"{",
"this",
".",
"N",
"=",
"N",
";",
"this",
".",
"diag",
"=",
"null",
";",
"this",
".",
"off",
"=",
"null",
";",
"if",
"(",
"splits",
".",
"length",
"<",
"N",
")",
"{",
"splits",
"=",
"new",
"int",
"[",
"N",
"]",
";",
"}",
"numSplits",
"=",
"0",
";",
"x1",
"=",
"0",
";",
"x2",
"=",
"N",
"-",
"1",
";",
"steps",
"=",
"numExceptional",
"=",
"lastExceptional",
"=",
"0",
";",
"this",
".",
"Q",
"=",
"null",
";",
"}"
] | Sets the size of the matrix being decomposed, declares new memory if needed,
and sets all helper functions to their initial value. | [
"Sets",
"the",
"size",
"of",
"the",
"matrix",
"being",
"decomposed",
"declares",
"new",
"memory",
"if",
"needed",
"and",
"sets",
"all",
"helper",
"functions",
"to",
"their",
"initial",
"value",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java#L139-L157 |
162,579 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java | SymmetricQREigenHelper_DDRM.isZero | protected boolean isZero( int index ) {
double bottom = Math.abs(diag[index])+Math.abs(diag[index+1]);
return( Math.abs(off[index]) <= bottom*UtilEjml.EPS);
} | java | protected boolean isZero( int index ) {
double bottom = Math.abs(diag[index])+Math.abs(diag[index+1]);
return( Math.abs(off[index]) <= bottom*UtilEjml.EPS);
} | [
"protected",
"boolean",
"isZero",
"(",
"int",
"index",
")",
"{",
"double",
"bottom",
"=",
"Math",
".",
"abs",
"(",
"diag",
"[",
"index",
"]",
")",
"+",
"Math",
".",
"abs",
"(",
"diag",
"[",
"index",
"+",
"1",
"]",
")",
";",
"return",
"(",
"Math",
".",
"abs",
"(",
"off",
"[",
"index",
"]",
")",
"<=",
"bottom",
"*",
"UtilEjml",
".",
"EPS",
")",
";",
"}"
] | Checks to see if the specified off diagonal element is zero using a relative metric. | [
"Checks",
"to",
"see",
"if",
"the",
"specified",
"off",
"diagonal",
"element",
"is",
"zero",
"using",
"a",
"relative",
"metric",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java#L202-L206 |
162,580 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java | SymmetricQREigenHelper_DDRM.createBulge | protected void createBulge( int x1 , double p , boolean byAngle ) {
double a11 = diag[x1];
double a22 = diag[x1+1];
double a12 = off[x1];
double a23 = off[x1+1];
if( byAngle ) {
c = Math.cos(p);
s = Math.sin(p);
c2 = c*c;
s2 = s*s;
cs = c*s;
} else {
computeRotation(a11-p, a12);
}
// multiply the rotator on the top left.
diag[x1] = c2*a11 + 2.0*cs*a12 + s2*a22;
diag[x1+1] = c2*a22 - 2.0*cs*a12 + s2*a11;
off[x1] = a12*(c2-s2) + cs*(a22 - a11);
off[x1+1] = c*a23;
bulge = s*a23;
if( Q != null )
updateQ(x1,x1+1,c,s);
} | java | protected void createBulge( int x1 , double p , boolean byAngle ) {
double a11 = diag[x1];
double a22 = diag[x1+1];
double a12 = off[x1];
double a23 = off[x1+1];
if( byAngle ) {
c = Math.cos(p);
s = Math.sin(p);
c2 = c*c;
s2 = s*s;
cs = c*s;
} else {
computeRotation(a11-p, a12);
}
// multiply the rotator on the top left.
diag[x1] = c2*a11 + 2.0*cs*a12 + s2*a22;
diag[x1+1] = c2*a22 - 2.0*cs*a12 + s2*a11;
off[x1] = a12*(c2-s2) + cs*(a22 - a11);
off[x1+1] = c*a23;
bulge = s*a23;
if( Q != null )
updateQ(x1,x1+1,c,s);
} | [
"protected",
"void",
"createBulge",
"(",
"int",
"x1",
",",
"double",
"p",
",",
"boolean",
"byAngle",
")",
"{",
"double",
"a11",
"=",
"diag",
"[",
"x1",
"]",
";",
"double",
"a22",
"=",
"diag",
"[",
"x1",
"+",
"1",
"]",
";",
"double",
"a12",
"=",
"off",
"[",
"x1",
"]",
";",
"double",
"a23",
"=",
"off",
"[",
"x1",
"+",
"1",
"]",
";",
"if",
"(",
"byAngle",
")",
"{",
"c",
"=",
"Math",
".",
"cos",
"(",
"p",
")",
";",
"s",
"=",
"Math",
".",
"sin",
"(",
"p",
")",
";",
"c2",
"=",
"c",
"*",
"c",
";",
"s2",
"=",
"s",
"*",
"s",
";",
"cs",
"=",
"c",
"*",
"s",
";",
"}",
"else",
"{",
"computeRotation",
"(",
"a11",
"-",
"p",
",",
"a12",
")",
";",
"}",
"// multiply the rotator on the top left.",
"diag",
"[",
"x1",
"]",
"=",
"c2",
"*",
"a11",
"+",
"2.0",
"*",
"cs",
"*",
"a12",
"+",
"s2",
"*",
"a22",
";",
"diag",
"[",
"x1",
"+",
"1",
"]",
"=",
"c2",
"*",
"a22",
"-",
"2.0",
"*",
"cs",
"*",
"a12",
"+",
"s2",
"*",
"a11",
";",
"off",
"[",
"x1",
"]",
"=",
"a12",
"*",
"(",
"c2",
"-",
"s2",
")",
"+",
"cs",
"*",
"(",
"a22",
"-",
"a11",
")",
";",
"off",
"[",
"x1",
"+",
"1",
"]",
"=",
"c",
"*",
"a23",
";",
"bulge",
"=",
"s",
"*",
"a23",
";",
"if",
"(",
"Q",
"!=",
"null",
")",
"updateQ",
"(",
"x1",
",",
"x1",
"+",
"1",
",",
"c",
",",
"s",
")",
";",
"}"
] | Performs a similar transform on A-pI | [
"Performs",
"a",
"similar",
"transform",
"on",
"A",
"-",
"pI"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java#L247-L273 |
162,581 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java | SymmetricQREigenHelper_DDRM.eigenvalue2by2 | protected void eigenvalue2by2( int x1 ) {
double a = diag[x1];
double b = off[x1];
double c = diag[x1+1];
// normalize to reduce overflow
double absA = Math.abs(a);
double absB = Math.abs(b);
double absC = Math.abs(c);
double scale = absA > absB ? absA : absB;
if( absC > scale ) scale = absC;
// see if it is a pathological case. the diagonal must already be zero
// and the eigenvalues are all zero. so just return
if( scale == 0 ) {
off[x1] = 0;
diag[x1] = 0;
diag[x1+1] = 0;
return;
}
a /= scale;
b /= scale;
c /= scale;
eigenSmall.symm2x2_fast(a,b,c);
off[x1] = 0;
diag[x1] = scale*eigenSmall.value0.real;
diag[x1+1] = scale*eigenSmall.value1.real;
} | java | protected void eigenvalue2by2( int x1 ) {
double a = diag[x1];
double b = off[x1];
double c = diag[x1+1];
// normalize to reduce overflow
double absA = Math.abs(a);
double absB = Math.abs(b);
double absC = Math.abs(c);
double scale = absA > absB ? absA : absB;
if( absC > scale ) scale = absC;
// see if it is a pathological case. the diagonal must already be zero
// and the eigenvalues are all zero. so just return
if( scale == 0 ) {
off[x1] = 0;
diag[x1] = 0;
diag[x1+1] = 0;
return;
}
a /= scale;
b /= scale;
c /= scale;
eigenSmall.symm2x2_fast(a,b,c);
off[x1] = 0;
diag[x1] = scale*eigenSmall.value0.real;
diag[x1+1] = scale*eigenSmall.value1.real;
} | [
"protected",
"void",
"eigenvalue2by2",
"(",
"int",
"x1",
")",
"{",
"double",
"a",
"=",
"diag",
"[",
"x1",
"]",
";",
"double",
"b",
"=",
"off",
"[",
"x1",
"]",
";",
"double",
"c",
"=",
"diag",
"[",
"x1",
"+",
"1",
"]",
";",
"// normalize to reduce overflow",
"double",
"absA",
"=",
"Math",
".",
"abs",
"(",
"a",
")",
";",
"double",
"absB",
"=",
"Math",
".",
"abs",
"(",
"b",
")",
";",
"double",
"absC",
"=",
"Math",
".",
"abs",
"(",
"c",
")",
";",
"double",
"scale",
"=",
"absA",
">",
"absB",
"?",
"absA",
":",
"absB",
";",
"if",
"(",
"absC",
">",
"scale",
")",
"scale",
"=",
"absC",
";",
"// see if it is a pathological case. the diagonal must already be zero",
"// and the eigenvalues are all zero. so just return",
"if",
"(",
"scale",
"==",
"0",
")",
"{",
"off",
"[",
"x1",
"]",
"=",
"0",
";",
"diag",
"[",
"x1",
"]",
"=",
"0",
";",
"diag",
"[",
"x1",
"+",
"1",
"]",
"=",
"0",
";",
"return",
";",
"}",
"a",
"/=",
"scale",
";",
"b",
"/=",
"scale",
";",
"c",
"/=",
"scale",
";",
"eigenSmall",
".",
"symm2x2_fast",
"(",
"a",
",",
"b",
",",
"c",
")",
";",
"off",
"[",
"x1",
"]",
"=",
"0",
";",
"diag",
"[",
"x1",
"]",
"=",
"scale",
"*",
"eigenSmall",
".",
"value0",
".",
"real",
";",
"diag",
"[",
"x1",
"+",
"1",
"]",
"=",
"scale",
"*",
"eigenSmall",
".",
"value1",
".",
"real",
";",
"}"
] | Computes the eigenvalue of the 2 by 2 matrix. | [
"Computes",
"the",
"eigenvalue",
"of",
"the",
"2",
"by",
"2",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/eig/symm/SymmetricQREigenHelper_DDRM.java#L378-L409 |
162,582 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/linsol/LinearSolver_DDRB_to_DDRM.java | LinearSolver_DDRB_to_DDRM.solve | @Override
public void solve(DMatrixRMaj B, DMatrixRMaj X) {
X.reshape(blockA.numCols,B.numCols);
blockB.reshape(B.numRows,B.numCols,false);
blockX.reshape(X.numRows,X.numCols,false);
MatrixOps_DDRB.convert(B,blockB);
alg.solve(blockB,blockX);
MatrixOps_DDRB.convert(blockX,X);
} | java | @Override
public void solve(DMatrixRMaj B, DMatrixRMaj X) {
X.reshape(blockA.numCols,B.numCols);
blockB.reshape(B.numRows,B.numCols,false);
blockX.reshape(X.numRows,X.numCols,false);
MatrixOps_DDRB.convert(B,blockB);
alg.solve(blockB,blockX);
MatrixOps_DDRB.convert(blockX,X);
} | [
"@",
"Override",
"public",
"void",
"solve",
"(",
"DMatrixRMaj",
"B",
",",
"DMatrixRMaj",
"X",
")",
"{",
"X",
".",
"reshape",
"(",
"blockA",
".",
"numCols",
",",
"B",
".",
"numCols",
")",
";",
"blockB",
".",
"reshape",
"(",
"B",
".",
"numRows",
",",
"B",
".",
"numCols",
",",
"false",
")",
";",
"blockX",
".",
"reshape",
"(",
"X",
".",
"numRows",
",",
"X",
".",
"numCols",
",",
"false",
")",
";",
"MatrixOps_DDRB",
".",
"convert",
"(",
"B",
",",
"blockB",
")",
";",
"alg",
".",
"solve",
"(",
"blockB",
",",
"blockX",
")",
";",
"MatrixOps_DDRB",
".",
"convert",
"(",
"blockX",
",",
"X",
")",
";",
"}"
] | Converts B and X into block matrices and calls the block matrix solve routine.
@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. | [
"Converts",
"B",
"and",
"X",
"into",
"block",
"matrices",
"and",
"calls",
"the",
"block",
"matrix",
"solve",
"routine",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/linsol/LinearSolver_DDRB_to_DDRM.java#L75-L85 |
162,583 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/linsol/LinearSolver_DDRB_to_DDRM.java | LinearSolver_DDRB_to_DDRM.invert | @Override
public void invert(DMatrixRMaj A_inv) {
blockB.reshape(A_inv.numRows,A_inv.numCols,false);
alg.invert(blockB);
MatrixOps_DDRB.convert(blockB,A_inv);
} | java | @Override
public void invert(DMatrixRMaj A_inv) {
blockB.reshape(A_inv.numRows,A_inv.numCols,false);
alg.invert(blockB);
MatrixOps_DDRB.convert(blockB,A_inv);
} | [
"@",
"Override",
"public",
"void",
"invert",
"(",
"DMatrixRMaj",
"A_inv",
")",
"{",
"blockB",
".",
"reshape",
"(",
"A_inv",
".",
"numRows",
",",
"A_inv",
".",
"numCols",
",",
"false",
")",
";",
"alg",
".",
"invert",
"(",
"blockB",
")",
";",
"MatrixOps_DDRB",
".",
"convert",
"(",
"blockB",
",",
"A_inv",
")",
";",
"}"
] | Creates a block matrix the same size as A_inv, inverts the matrix and copies the results back
onto A_inv.
@param A_inv Where the inverted matrix saved. Modified. | [
"Creates",
"a",
"block",
"matrix",
"the",
"same",
"size",
"as",
"A_inv",
"inverts",
"the",
"matrix",
"and",
"copies",
"the",
"results",
"back",
"onto",
"A_inv",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/linsol/LinearSolver_DDRB_to_DDRM.java#L93-L100 |
162,584 | lessthanoptimal/ejml | main/ejml-ddense/generate/org/ejml/dense/row/misc/GenerateInverseFromMinor.java | GenerateInverseFromMinor.printMinors | public void printMinors(int matrix[], int N, PrintStream stream) {
this.N = N;
this.stream = stream;
// compute all the minors
int index = 0;
for( int i = 1; i <= N; i++ ) {
for( int j = 1; j <= N; j++ , index++) {
stream.print(" double m"+i+""+j+" = ");
if( (i+j) % 2 == 1 )
stream.print("-( ");
printTopMinor(matrix,i-1,j-1,N);
if( (i+j) % 2 == 1 )
stream.print(")");
stream.print(";\n");
}
}
stream.println();
// compute the determinant
stream.print(" double det = (a11*m11");
for( int i = 2; i <= N; i++ ) {
stream.print(" + "+a(i-1)+"*m"+1+""+i);
}
stream.println(")/scale;");
} | java | public void printMinors(int matrix[], int N, PrintStream stream) {
this.N = N;
this.stream = stream;
// compute all the minors
int index = 0;
for( int i = 1; i <= N; i++ ) {
for( int j = 1; j <= N; j++ , index++) {
stream.print(" double m"+i+""+j+" = ");
if( (i+j) % 2 == 1 )
stream.print("-( ");
printTopMinor(matrix,i-1,j-1,N);
if( (i+j) % 2 == 1 )
stream.print(")");
stream.print(";\n");
}
}
stream.println();
// compute the determinant
stream.print(" double det = (a11*m11");
for( int i = 2; i <= N; i++ ) {
stream.print(" + "+a(i-1)+"*m"+1+""+i);
}
stream.println(")/scale;");
} | [
"public",
"void",
"printMinors",
"(",
"int",
"matrix",
"[",
"]",
",",
"int",
"N",
",",
"PrintStream",
"stream",
")",
"{",
"this",
".",
"N",
"=",
"N",
";",
"this",
".",
"stream",
"=",
"stream",
";",
"// compute all the minors",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"N",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"1",
";",
"j",
"<=",
"N",
";",
"j",
"++",
",",
"index",
"++",
")",
"{",
"stream",
".",
"print",
"(",
"\" double m\"",
"+",
"i",
"+",
"\"\"",
"+",
"j",
"+",
"\" = \"",
")",
";",
"if",
"(",
"(",
"i",
"+",
"j",
")",
"%",
"2",
"==",
"1",
")",
"stream",
".",
"print",
"(",
"\"-( \"",
")",
";",
"printTopMinor",
"(",
"matrix",
",",
"i",
"-",
"1",
",",
"j",
"-",
"1",
",",
"N",
")",
";",
"if",
"(",
"(",
"i",
"+",
"j",
")",
"%",
"2",
"==",
"1",
")",
"stream",
".",
"print",
"(",
"\")\"",
")",
";",
"stream",
".",
"print",
"(",
"\";\\n\"",
")",
";",
"}",
"}",
"stream",
".",
"println",
"(",
")",
";",
"// compute the determinant",
"stream",
".",
"print",
"(",
"\" double det = (a11*m11\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"2",
";",
"i",
"<=",
"N",
";",
"i",
"++",
")",
"{",
"stream",
".",
"print",
"(",
"\" + \"",
"+",
"a",
"(",
"i",
"-",
"1",
")",
"+",
"\"*m\"",
"+",
"1",
"+",
"\"\"",
"+",
"i",
")",
";",
"}",
"stream",
".",
"println",
"(",
"\")/scale;\"",
")",
";",
"}"
] | Put the core auto-code algorithm here so an external class can call it | [
"Put",
"the",
"core",
"auto",
"-",
"code",
"algorithm",
"here",
"so",
"an",
"external",
"class",
"can",
"call",
"it"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/generate/org/ejml/dense/row/misc/GenerateInverseFromMinor.java#L147-L173 |
162,585 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/linsol/qr/QrHouseHolderSolver_DDRB.java | QrHouseHolderSolver_DDRB.setA | @Override
public boolean setA(DMatrixRBlock A) {
if( A.numRows < A.numCols )
throw new IllegalArgumentException("Number of rows must be more than or equal to the number of columns. " +
"Can't solve an underdetermined system.");
if( !decomposer.decompose(A))
return false;
this.QR = decomposer.getQR();
return true;
} | java | @Override
public boolean setA(DMatrixRBlock A) {
if( A.numRows < A.numCols )
throw new IllegalArgumentException("Number of rows must be more than or equal to the number of columns. " +
"Can't solve an underdetermined system.");
if( !decomposer.decompose(A))
return false;
this.QR = decomposer.getQR();
return true;
} | [
"@",
"Override",
"public",
"boolean",
"setA",
"(",
"DMatrixRBlock",
"A",
")",
"{",
"if",
"(",
"A",
".",
"numRows",
"<",
"A",
".",
"numCols",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Number of rows must be more than or equal to the number of columns. \"",
"+",
"\"Can't solve an underdetermined system.\"",
")",
";",
"if",
"(",
"!",
"decomposer",
".",
"decompose",
"(",
"A",
")",
")",
"return",
"false",
";",
"this",
".",
"QR",
"=",
"decomposer",
".",
"getQR",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Computes the QR decomposition of A and store the results in A.
@param A The A matrix in the linear equation. Modified. Reference saved.
@return true if the decomposition was successful. | [
"Computes",
"the",
"QR",
"decomposition",
"of",
"A",
"and",
"store",
"the",
"results",
"in",
"A",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/linsol/qr/QrHouseHolderSolver_DDRB.java#L68-L80 |
162,586 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/block/linsol/qr/QrHouseHolderSolver_DDRB.java | QrHouseHolderSolver_DDRB.invert | @Override
public void invert(DMatrixRBlock A_inv) {
int M = Math.min(QR.numRows,QR.numCols);
if( A_inv.numRows != M || A_inv.numCols != M )
throw new IllegalArgumentException("A_inv must be square an have dimension "+M);
// Solve for A^-1
// Q*R*A^-1 = I
// Apply householder reflectors to the identity matrix
// y = Q^T*I = Q^T
MatrixOps_DDRB.setIdentity(A_inv);
decomposer.applyQTran(A_inv);
// Solve using upper triangular R matrix
// R*A^-1 = y
// A^-1 = R^-1*y
TriangularSolver_DDRB.solve(QR.blockLength,true,
new DSubmatrixD1(QR,0,M,0,M),new DSubmatrixD1(A_inv),false);
} | java | @Override
public void invert(DMatrixRBlock A_inv) {
int M = Math.min(QR.numRows,QR.numCols);
if( A_inv.numRows != M || A_inv.numCols != M )
throw new IllegalArgumentException("A_inv must be square an have dimension "+M);
// Solve for A^-1
// Q*R*A^-1 = I
// Apply householder reflectors to the identity matrix
// y = Q^T*I = Q^T
MatrixOps_DDRB.setIdentity(A_inv);
decomposer.applyQTran(A_inv);
// Solve using upper triangular R matrix
// R*A^-1 = y
// A^-1 = R^-1*y
TriangularSolver_DDRB.solve(QR.blockLength,true,
new DSubmatrixD1(QR,0,M,0,M),new DSubmatrixD1(A_inv),false);
} | [
"@",
"Override",
"public",
"void",
"invert",
"(",
"DMatrixRBlock",
"A_inv",
")",
"{",
"int",
"M",
"=",
"Math",
".",
"min",
"(",
"QR",
".",
"numRows",
",",
"QR",
".",
"numCols",
")",
";",
"if",
"(",
"A_inv",
".",
"numRows",
"!=",
"M",
"||",
"A_inv",
".",
"numCols",
"!=",
"M",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"A_inv must be square an have dimension \"",
"+",
"M",
")",
";",
"// Solve for A^-1",
"// Q*R*A^-1 = I",
"// Apply householder reflectors to the identity matrix",
"// y = Q^T*I = Q^T",
"MatrixOps_DDRB",
".",
"setIdentity",
"(",
"A_inv",
")",
";",
"decomposer",
".",
"applyQTran",
"(",
"A_inv",
")",
";",
"// Solve using upper triangular R matrix",
"// R*A^-1 = y",
"// A^-1 = R^-1*y",
"TriangularSolver_DDRB",
".",
"solve",
"(",
"QR",
".",
"blockLength",
",",
"true",
",",
"new",
"DSubmatrixD1",
"(",
"QR",
",",
"0",
",",
"M",
",",
"0",
",",
"M",
")",
",",
"new",
"DSubmatrixD1",
"(",
"A_inv",
")",
",",
"false",
")",
";",
"}"
] | Invert by solving for against an identity matrix.
@param A_inv Where the inverted matrix saved. Modified. | [
"Invert",
"by",
"solving",
"for",
"against",
"an",
"identity",
"matrix",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/block/linsol/qr/QrHouseHolderSolver_DDRB.java#L124-L144 |
162,587 | lessthanoptimal/ejml | main/ejml-simple/src/org/ejml/equation/Sequence.java | Sequence.perform | public void perform() {
for (int i = 0; i < operations.size(); i++) {
operations.get(i).process();
}
} | java | public void perform() {
for (int i = 0; i < operations.size(); i++) {
operations.get(i).process();
}
} | [
"public",
"void",
"perform",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"operations",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"operations",
".",
"get",
"(",
"i",
")",
".",
"process",
"(",
")",
";",
"}",
"}"
] | Executes the sequence of operations | [
"Executes",
"the",
"sequence",
"of",
"operations"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-simple/src/org/ejml/equation/Sequence.java#L44-L48 |
162,588 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/chol/CholeskyDecompositionBlock_DDRM.java | CholeskyDecompositionBlock_DDRM.setExpectedMaxSize | @Override
public void setExpectedMaxSize( int numRows , int numCols ) {
super.setExpectedMaxSize(numRows,numCols);
// if the matrix that is being decomposed is smaller than the block we really don't
// see the B matrix.
if( numRows < blockWidth)
B = new DMatrixRMaj(0,0);
else
B = new DMatrixRMaj(blockWidth,maxWidth);
chol = new CholeskyBlockHelper_DDRM(blockWidth);
} | java | @Override
public void setExpectedMaxSize( int numRows , int numCols ) {
super.setExpectedMaxSize(numRows,numCols);
// if the matrix that is being decomposed is smaller than the block we really don't
// see the B matrix.
if( numRows < blockWidth)
B = new DMatrixRMaj(0,0);
else
B = new DMatrixRMaj(blockWidth,maxWidth);
chol = new CholeskyBlockHelper_DDRM(blockWidth);
} | [
"@",
"Override",
"public",
"void",
"setExpectedMaxSize",
"(",
"int",
"numRows",
",",
"int",
"numCols",
")",
"{",
"super",
".",
"setExpectedMaxSize",
"(",
"numRows",
",",
"numCols",
")",
";",
"// if the matrix that is being decomposed is smaller than the block we really don't",
"// see the B matrix.",
"if",
"(",
"numRows",
"<",
"blockWidth",
")",
"B",
"=",
"new",
"DMatrixRMaj",
"(",
"0",
",",
"0",
")",
";",
"else",
"B",
"=",
"new",
"DMatrixRMaj",
"(",
"blockWidth",
",",
"maxWidth",
")",
";",
"chol",
"=",
"new",
"CholeskyBlockHelper_DDRM",
"(",
"blockWidth",
")",
";",
"}"
] | Declares additional internal data structures. | [
"Declares",
"additional",
"internal",
"data",
"structures",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/chol/CholeskyDecompositionBlock_DDRM.java#L54-L66 |
162,589 | lessthanoptimal/ejml | main/ejml-core/src/org/ejml/ops/ConvertDMatrixStruct.java | ConvertDMatrixStruct.convert | public static DMatrixSparseCSC convert(DMatrixSparseTriplet src , DMatrixSparseCSC dst , int hist[] ) {
if( dst == null )
dst = new DMatrixSparseCSC(src.numRows, src.numCols , src.nz_length);
else
dst.reshape(src.numRows, src.numCols, src.nz_length);
if( hist == null )
hist = new int[ src.numCols ];
else if( hist.length >= src.numCols )
Arrays.fill(hist,0,src.numCols, 0);
else
throw new IllegalArgumentException("Length of hist must be at least numCols");
// compute the number of elements in each columns
for (int i = 0; i < src.nz_length; i++) {
hist[src.nz_rowcol.data[i*2+1]]++;
}
// define col_idx
dst.histogramToStructure(hist);
System.arraycopy(dst.col_idx,0,hist,0,dst.numCols);
// now write the row indexes and the values
for (int i = 0; i < src.nz_length; i++) {
int row = src.nz_rowcol.data[i*2];
int col = src.nz_rowcol.data[i*2+1];
double value = src.nz_value.data[i];
int index = hist[col]++;
dst.nz_rows[index] = row;
dst.nz_values[index] = value;
}
dst.indicesSorted = false;
return dst;
} | java | public static DMatrixSparseCSC convert(DMatrixSparseTriplet src , DMatrixSparseCSC dst , int hist[] ) {
if( dst == null )
dst = new DMatrixSparseCSC(src.numRows, src.numCols , src.nz_length);
else
dst.reshape(src.numRows, src.numCols, src.nz_length);
if( hist == null )
hist = new int[ src.numCols ];
else if( hist.length >= src.numCols )
Arrays.fill(hist,0,src.numCols, 0);
else
throw new IllegalArgumentException("Length of hist must be at least numCols");
// compute the number of elements in each columns
for (int i = 0; i < src.nz_length; i++) {
hist[src.nz_rowcol.data[i*2+1]]++;
}
// define col_idx
dst.histogramToStructure(hist);
System.arraycopy(dst.col_idx,0,hist,0,dst.numCols);
// now write the row indexes and the values
for (int i = 0; i < src.nz_length; i++) {
int row = src.nz_rowcol.data[i*2];
int col = src.nz_rowcol.data[i*2+1];
double value = src.nz_value.data[i];
int index = hist[col]++;
dst.nz_rows[index] = row;
dst.nz_values[index] = value;
}
dst.indicesSorted = false;
return dst;
} | [
"public",
"static",
"DMatrixSparseCSC",
"convert",
"(",
"DMatrixSparseTriplet",
"src",
",",
"DMatrixSparseCSC",
"dst",
",",
"int",
"hist",
"[",
"]",
")",
"{",
"if",
"(",
"dst",
"==",
"null",
")",
"dst",
"=",
"new",
"DMatrixSparseCSC",
"(",
"src",
".",
"numRows",
",",
"src",
".",
"numCols",
",",
"src",
".",
"nz_length",
")",
";",
"else",
"dst",
".",
"reshape",
"(",
"src",
".",
"numRows",
",",
"src",
".",
"numCols",
",",
"src",
".",
"nz_length",
")",
";",
"if",
"(",
"hist",
"==",
"null",
")",
"hist",
"=",
"new",
"int",
"[",
"src",
".",
"numCols",
"]",
";",
"else",
"if",
"(",
"hist",
".",
"length",
">=",
"src",
".",
"numCols",
")",
"Arrays",
".",
"fill",
"(",
"hist",
",",
"0",
",",
"src",
".",
"numCols",
",",
"0",
")",
";",
"else",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Length of hist must be at least numCols\"",
")",
";",
"// compute the number of elements in each columns",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"src",
".",
"nz_length",
";",
"i",
"++",
")",
"{",
"hist",
"[",
"src",
".",
"nz_rowcol",
".",
"data",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
"]",
"++",
";",
"}",
"// define col_idx",
"dst",
".",
"histogramToStructure",
"(",
"hist",
")",
";",
"System",
".",
"arraycopy",
"(",
"dst",
".",
"col_idx",
",",
"0",
",",
"hist",
",",
"0",
",",
"dst",
".",
"numCols",
")",
";",
"// now write the row indexes and the values",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"src",
".",
"nz_length",
";",
"i",
"++",
")",
"{",
"int",
"row",
"=",
"src",
".",
"nz_rowcol",
".",
"data",
"[",
"i",
"*",
"2",
"]",
";",
"int",
"col",
"=",
"src",
".",
"nz_rowcol",
".",
"data",
"[",
"i",
"*",
"2",
"+",
"1",
"]",
";",
"double",
"value",
"=",
"src",
".",
"nz_value",
".",
"data",
"[",
"i",
"]",
";",
"int",
"index",
"=",
"hist",
"[",
"col",
"]",
"++",
";",
"dst",
".",
"nz_rows",
"[",
"index",
"]",
"=",
"row",
";",
"dst",
".",
"nz_values",
"[",
"index",
"]",
"=",
"value",
";",
"}",
"dst",
".",
"indicesSorted",
"=",
"false",
";",
"return",
"dst",
";",
"}"
] | Converts SMatrixTriplet_64 into a SMatrixCC_64.
@param src Original matrix which is to be copied. Not modified.
@param dst Destination. Will be a copy. Modified.
@param hist Workspace. Should be at least as long as the number of columns. Can be null. | [
"Converts",
"SMatrixTriplet_64",
"into",
"a",
"SMatrixCC_64",
"."
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-core/src/org/ejml/ops/ConvertDMatrixStruct.java#L858-L893 |
162,590 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java | QRColPivDecompositionHouseholderColumn_DDRM.setupPivotInfo | protected void setupPivotInfo() {
for( int col = 0; col < numCols; col++ ) {
pivots[col] = col;
double c[] = dataQR[col];
double norm = 0;
for( int row = 0; row < numRows; row++ ) {
double element = c[row];
norm += element*element;
}
normsCol[col] = norm;
}
} | java | protected void setupPivotInfo() {
for( int col = 0; col < numCols; col++ ) {
pivots[col] = col;
double c[] = dataQR[col];
double norm = 0;
for( int row = 0; row < numRows; row++ ) {
double element = c[row];
norm += element*element;
}
normsCol[col] = norm;
}
} | [
"protected",
"void",
"setupPivotInfo",
"(",
")",
"{",
"for",
"(",
"int",
"col",
"=",
"0",
";",
"col",
"<",
"numCols",
";",
"col",
"++",
")",
"{",
"pivots",
"[",
"col",
"]",
"=",
"col",
";",
"double",
"c",
"[",
"]",
"=",
"dataQR",
"[",
"col",
"]",
";",
"double",
"norm",
"=",
"0",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<",
"numRows",
";",
"row",
"++",
")",
"{",
"double",
"element",
"=",
"c",
"[",
"row",
"]",
";",
"norm",
"+=",
"element",
"*",
"element",
";",
"}",
"normsCol",
"[",
"col",
"]",
"=",
"norm",
";",
"}",
"}"
] | Sets the initial pivot ordering and compute the F-norm squared for each column | [
"Sets",
"the",
"initial",
"pivot",
"ordering",
"and",
"compute",
"the",
"F",
"-",
"norm",
"squared",
"for",
"each",
"column"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java#L173-L184 |
162,591 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java | QRColPivDecompositionHouseholderColumn_DDRM.updateNorms | protected void updateNorms( int j ) {
boolean foundNegative = false;
for( int col = j; col < numCols; col++ ) {
double e = dataQR[col][j-1];
double v = normsCol[col] -= e*e;
if( v < 0 ) {
foundNegative = true;
break;
}
}
// if a negative sum has been found then clearly too much precision has been lost
// and it should recompute the column norms from scratch
if( foundNegative ) {
for( int col = j; col < numCols; col++ ) {
double u[] = dataQR[col];
double actual = 0;
for( int i=j; i < numRows; i++ ) {
double v = u[i];
actual += v*v;
}
normsCol[col] = actual;
}
}
} | java | protected void updateNorms( int j ) {
boolean foundNegative = false;
for( int col = j; col < numCols; col++ ) {
double e = dataQR[col][j-1];
double v = normsCol[col] -= e*e;
if( v < 0 ) {
foundNegative = true;
break;
}
}
// if a negative sum has been found then clearly too much precision has been lost
// and it should recompute the column norms from scratch
if( foundNegative ) {
for( int col = j; col < numCols; col++ ) {
double u[] = dataQR[col];
double actual = 0;
for( int i=j; i < numRows; i++ ) {
double v = u[i];
actual += v*v;
}
normsCol[col] = actual;
}
}
} | [
"protected",
"void",
"updateNorms",
"(",
"int",
"j",
")",
"{",
"boolean",
"foundNegative",
"=",
"false",
";",
"for",
"(",
"int",
"col",
"=",
"j",
";",
"col",
"<",
"numCols",
";",
"col",
"++",
")",
"{",
"double",
"e",
"=",
"dataQR",
"[",
"col",
"]",
"[",
"j",
"-",
"1",
"]",
";",
"double",
"v",
"=",
"normsCol",
"[",
"col",
"]",
"-=",
"e",
"*",
"e",
";",
"if",
"(",
"v",
"<",
"0",
")",
"{",
"foundNegative",
"=",
"true",
";",
"break",
";",
"}",
"}",
"// if a negative sum has been found then clearly too much precision has been lost",
"// and it should recompute the column norms from scratch",
"if",
"(",
"foundNegative",
")",
"{",
"for",
"(",
"int",
"col",
"=",
"j",
";",
"col",
"<",
"numCols",
";",
"col",
"++",
")",
"{",
"double",
"u",
"[",
"]",
"=",
"dataQR",
"[",
"col",
"]",
";",
"double",
"actual",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"j",
";",
"i",
"<",
"numRows",
";",
"i",
"++",
")",
"{",
"double",
"v",
"=",
"u",
"[",
"i",
"]",
";",
"actual",
"+=",
"v",
"*",
"v",
";",
"}",
"normsCol",
"[",
"col",
"]",
"=",
"actual",
";",
"}",
"}",
"}"
] | Performs an efficient update of each columns' norm | [
"Performs",
"an",
"efficient",
"update",
"of",
"each",
"columns",
"norm"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java#L190-L215 |
162,592 | lessthanoptimal/ejml | main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java | QRColPivDecompositionHouseholderColumn_DDRM.swapColumns | protected void swapColumns( int j ) {
// find the column with the largest norm
int largestIndex = j;
double largestNorm = normsCol[j];
for( int col = j+1; col < numCols; col++ ) {
double n = normsCol[col];
if( n > largestNorm ) {
largestNorm = n;
largestIndex = col;
}
}
// swap the columns
double []tempC = dataQR[j];
dataQR[j] = dataQR[largestIndex];
dataQR[largestIndex] = tempC;
double tempN = normsCol[j];
normsCol[j] = normsCol[largestIndex];
normsCol[largestIndex] = tempN;
int tempP = pivots[j];
pivots[j] = pivots[largestIndex];
pivots[largestIndex] = tempP;
} | java | protected void swapColumns( int j ) {
// find the column with the largest norm
int largestIndex = j;
double largestNorm = normsCol[j];
for( int col = j+1; col < numCols; col++ ) {
double n = normsCol[col];
if( n > largestNorm ) {
largestNorm = n;
largestIndex = col;
}
}
// swap the columns
double []tempC = dataQR[j];
dataQR[j] = dataQR[largestIndex];
dataQR[largestIndex] = tempC;
double tempN = normsCol[j];
normsCol[j] = normsCol[largestIndex];
normsCol[largestIndex] = tempN;
int tempP = pivots[j];
pivots[j] = pivots[largestIndex];
pivots[largestIndex] = tempP;
} | [
"protected",
"void",
"swapColumns",
"(",
"int",
"j",
")",
"{",
"// find the column with the largest norm",
"int",
"largestIndex",
"=",
"j",
";",
"double",
"largestNorm",
"=",
"normsCol",
"[",
"j",
"]",
";",
"for",
"(",
"int",
"col",
"=",
"j",
"+",
"1",
";",
"col",
"<",
"numCols",
";",
"col",
"++",
")",
"{",
"double",
"n",
"=",
"normsCol",
"[",
"col",
"]",
";",
"if",
"(",
"n",
">",
"largestNorm",
")",
"{",
"largestNorm",
"=",
"n",
";",
"largestIndex",
"=",
"col",
";",
"}",
"}",
"// swap the columns",
"double",
"[",
"]",
"tempC",
"=",
"dataQR",
"[",
"j",
"]",
";",
"dataQR",
"[",
"j",
"]",
"=",
"dataQR",
"[",
"largestIndex",
"]",
";",
"dataQR",
"[",
"largestIndex",
"]",
"=",
"tempC",
";",
"double",
"tempN",
"=",
"normsCol",
"[",
"j",
"]",
";",
"normsCol",
"[",
"j",
"]",
"=",
"normsCol",
"[",
"largestIndex",
"]",
";",
"normsCol",
"[",
"largestIndex",
"]",
"=",
"tempN",
";",
"int",
"tempP",
"=",
"pivots",
"[",
"j",
"]",
";",
"pivots",
"[",
"j",
"]",
"=",
"pivots",
"[",
"largestIndex",
"]",
";",
"pivots",
"[",
"largestIndex",
"]",
"=",
"tempP",
";",
"}"
] | Finds the column with the largest normal and makes that the first column
@param j Current column being inspected | [
"Finds",
"the",
"column",
"with",
"the",
"largest",
"normal",
"and",
"makes",
"that",
"the",
"first",
"column"
] | 1444680cc487af5e866730e62f48f5f9636850d9 | https://github.com/lessthanoptimal/ejml/blob/1444680cc487af5e866730e62f48f5f9636850d9/main/ejml-ddense/src/org/ejml/dense/row/decomposition/qr/QRColPivDecompositionHouseholderColumn_DDRM.java#L222-L244 |
162,593 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/config/HiveRunnerConfig.java | HiveRunnerConfig.getHiveExecutionEngine | public String getHiveExecutionEngine() {
String executionEngine = hiveConfSystemOverride.get(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname);
return executionEngine == null ? HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.getDefaultValue() : executionEngine;
} | java | public String getHiveExecutionEngine() {
String executionEngine = hiveConfSystemOverride.get(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname);
return executionEngine == null ? HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.getDefaultValue() : executionEngine;
} | [
"public",
"String",
"getHiveExecutionEngine",
"(",
")",
"{",
"String",
"executionEngine",
"=",
"hiveConfSystemOverride",
".",
"get",
"(",
"HiveConf",
".",
"ConfVars",
".",
"HIVE_EXECUTION_ENGINE",
".",
"varname",
")",
";",
"return",
"executionEngine",
"==",
"null",
"?",
"HiveConf",
".",
"ConfVars",
".",
"HIVE_EXECUTION_ENGINE",
".",
"getDefaultValue",
"(",
")",
":",
"executionEngine",
";",
"}"
] | Get the configured hive.execution.engine. If not set it will default to the default value of HiveConf | [
"Get",
"the",
"configured",
"hive",
".",
"execution",
".",
"engine",
".",
"If",
"not",
"set",
"it",
"will",
"default",
"to",
"the",
"default",
"value",
"of",
"HiveConf"
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/config/HiveRunnerConfig.java#L145-L148 |
162,594 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/config/HiveRunnerConfig.java | HiveRunnerConfig.override | public void override(HiveRunnerConfig hiveRunnerConfig) {
config.putAll(hiveRunnerConfig.config);
hiveConfSystemOverride.putAll(hiveRunnerConfig.hiveConfSystemOverride);
} | java | public void override(HiveRunnerConfig hiveRunnerConfig) {
config.putAll(hiveRunnerConfig.config);
hiveConfSystemOverride.putAll(hiveRunnerConfig.hiveConfSystemOverride);
} | [
"public",
"void",
"override",
"(",
"HiveRunnerConfig",
"hiveRunnerConfig",
")",
"{",
"config",
".",
"putAll",
"(",
"hiveRunnerConfig",
".",
"config",
")",
";",
"hiveConfSystemOverride",
".",
"putAll",
"(",
"hiveRunnerConfig",
".",
"hiveConfSystemOverride",
")",
";",
"}"
] | Copy values from the inserted config to this config. Note that if properties has not been explicitly set,
the defaults will apply. | [
"Copy",
"values",
"from",
"the",
"inserted",
"config",
"to",
"this",
"config",
".",
"Note",
"that",
"if",
"properties",
"has",
"not",
"been",
"explicitly",
"set",
"the",
"defaults",
"will",
"apply",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/config/HiveRunnerConfig.java#L186-L189 |
162,595 | klarna/HiveRunner | src/main/java/com/klarna/reflection/ReflectionUtils.java | ReflectionUtils.getField | public static Optional<Field> getField(Class<?> type, final String fieldName) {
Optional<Field> field = Iterables.tryFind(newArrayList(type.getDeclaredFields()), havingFieldName(fieldName));
if (!field.isPresent() && type.getSuperclass() != null){
field = getField(type.getSuperclass(), fieldName);
}
return field;
} | java | public static Optional<Field> getField(Class<?> type, final String fieldName) {
Optional<Field> field = Iterables.tryFind(newArrayList(type.getDeclaredFields()), havingFieldName(fieldName));
if (!field.isPresent() && type.getSuperclass() != null){
field = getField(type.getSuperclass(), fieldName);
}
return field;
} | [
"public",
"static",
"Optional",
"<",
"Field",
">",
"getField",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"final",
"String",
"fieldName",
")",
"{",
"Optional",
"<",
"Field",
">",
"field",
"=",
"Iterables",
".",
"tryFind",
"(",
"newArrayList",
"(",
"type",
".",
"getDeclaredFields",
"(",
")",
")",
",",
"havingFieldName",
"(",
"fieldName",
")",
")",
";",
"if",
"(",
"!",
"field",
".",
"isPresent",
"(",
")",
"&&",
"type",
".",
"getSuperclass",
"(",
")",
"!=",
"null",
")",
"{",
"field",
"=",
"getField",
"(",
"type",
".",
"getSuperclass",
"(",
")",
",",
"fieldName",
")",
";",
"}",
"return",
"field",
";",
"}"
] | Finds the first Field with given field name in the Class and in its super classes.
@param type The Class type
@param fieldName The field name to get
@return an {@code Optional}. Use isPresent() to find out if the field name was found. | [
"Finds",
"the",
"first",
"Field",
"with",
"given",
"field",
"name",
"in",
"the",
"Class",
"and",
"in",
"its",
"super",
"classes",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/reflection/ReflectionUtils.java#L72-L80 |
162,596 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/HiveServerContainer.java | HiveServerContainer.init | public void init(Map<String, String> testConfig, Map<String, String> hiveVars) {
context.init();
HiveConf hiveConf = context.getHiveConf();
// merge test case properties with hive conf before HiveServer is started.
for (Map.Entry<String, String> property : testConfig.entrySet()) {
hiveConf.set(property.getKey(), property.getValue());
}
try {
hiveServer2 = new HiveServer2();
hiveServer2.init(hiveConf);
// Locate the ClIService in the HiveServer2
for (Service service : hiveServer2.getServices()) {
if (service instanceof CLIService) {
client = (CLIService) service;
}
}
Preconditions.checkNotNull(client, "ClIService was not initialized by HiveServer2");
sessionHandle = client.openSession("noUser", "noPassword", null);
SessionState sessionState = client.getSessionManager().getSession(sessionHandle).getSessionState();
currentSessionState = sessionState;
currentSessionState.setHiveVariables(hiveVars);
} catch (Exception e) {
throw new IllegalStateException("Failed to create HiveServer :" + e.getMessage(), e);
}
// Ping hive server before we do anything more with it! If validation
// is switched on, this will fail if metastorage is not set up properly
pingHiveServer();
} | java | public void init(Map<String, String> testConfig, Map<String, String> hiveVars) {
context.init();
HiveConf hiveConf = context.getHiveConf();
// merge test case properties with hive conf before HiveServer is started.
for (Map.Entry<String, String> property : testConfig.entrySet()) {
hiveConf.set(property.getKey(), property.getValue());
}
try {
hiveServer2 = new HiveServer2();
hiveServer2.init(hiveConf);
// Locate the ClIService in the HiveServer2
for (Service service : hiveServer2.getServices()) {
if (service instanceof CLIService) {
client = (CLIService) service;
}
}
Preconditions.checkNotNull(client, "ClIService was not initialized by HiveServer2");
sessionHandle = client.openSession("noUser", "noPassword", null);
SessionState sessionState = client.getSessionManager().getSession(sessionHandle).getSessionState();
currentSessionState = sessionState;
currentSessionState.setHiveVariables(hiveVars);
} catch (Exception e) {
throw new IllegalStateException("Failed to create HiveServer :" + e.getMessage(), e);
}
// Ping hive server before we do anything more with it! If validation
// is switched on, this will fail if metastorage is not set up properly
pingHiveServer();
} | [
"public",
"void",
"init",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"testConfig",
",",
"Map",
"<",
"String",
",",
"String",
">",
"hiveVars",
")",
"{",
"context",
".",
"init",
"(",
")",
";",
"HiveConf",
"hiveConf",
"=",
"context",
".",
"getHiveConf",
"(",
")",
";",
"// merge test case properties with hive conf before HiveServer is started.",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"property",
":",
"testConfig",
".",
"entrySet",
"(",
")",
")",
"{",
"hiveConf",
".",
"set",
"(",
"property",
".",
"getKey",
"(",
")",
",",
"property",
".",
"getValue",
"(",
")",
")",
";",
"}",
"try",
"{",
"hiveServer2",
"=",
"new",
"HiveServer2",
"(",
")",
";",
"hiveServer2",
".",
"init",
"(",
"hiveConf",
")",
";",
"// Locate the ClIService in the HiveServer2",
"for",
"(",
"Service",
"service",
":",
"hiveServer2",
".",
"getServices",
"(",
")",
")",
"{",
"if",
"(",
"service",
"instanceof",
"CLIService",
")",
"{",
"client",
"=",
"(",
"CLIService",
")",
"service",
";",
"}",
"}",
"Preconditions",
".",
"checkNotNull",
"(",
"client",
",",
"\"ClIService was not initialized by HiveServer2\"",
")",
";",
"sessionHandle",
"=",
"client",
".",
"openSession",
"(",
"\"noUser\"",
",",
"\"noPassword\"",
",",
"null",
")",
";",
"SessionState",
"sessionState",
"=",
"client",
".",
"getSessionManager",
"(",
")",
".",
"getSession",
"(",
"sessionHandle",
")",
".",
"getSessionState",
"(",
")",
";",
"currentSessionState",
"=",
"sessionState",
";",
"currentSessionState",
".",
"setHiveVariables",
"(",
"hiveVars",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Failed to create HiveServer :\"",
"+",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"// Ping hive server before we do anything more with it! If validation",
"// is switched on, this will fail if metastorage is not set up properly",
"pingHiveServer",
"(",
")",
";",
"}"
] | Will start the HiveServer.
@param testConfig Specific test case properties. Will be merged with the HiveConf of the context
@param hiveVars HiveVars to pass on to the HiveServer for this session | [
"Will",
"start",
"the",
"HiveServer",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/HiveServerContainer.java#L72-L108 |
162,597 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java | InsertIntoTable.addRowsFromDelimited | public InsertIntoTable addRowsFromDelimited(File file, String delimiter, Object nullValue) {
builder.addRowsFromDelimited(file, delimiter, nullValue);
return this;
} | java | public InsertIntoTable addRowsFromDelimited(File file, String delimiter, Object nullValue) {
builder.addRowsFromDelimited(file, delimiter, nullValue);
return this;
} | [
"public",
"InsertIntoTable",
"addRowsFromDelimited",
"(",
"File",
"file",
",",
"String",
"delimiter",
",",
"Object",
"nullValue",
")",
"{",
"builder",
".",
"addRowsFromDelimited",
"(",
"file",
",",
"delimiter",
",",
"nullValue",
")",
";",
"return",
"this",
";",
"}"
] | Adds all rows from the TSV file specified, using the provided delimiter and null value.
@param file The file to read the data from.
@param delimiter A column delimiter.
@param nullValue Value to be treated as null in the source data.
@return {@code this} | [
"Adds",
"all",
"rows",
"from",
"the",
"TSV",
"file",
"specified",
"using",
"the",
"provided",
"delimiter",
"and",
"null",
"value",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java#L160-L163 |
162,598 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java | InsertIntoTable.addRowsFrom | public InsertIntoTable addRowsFrom(File file, FileParser fileParser) {
builder.addRowsFrom(file, fileParser);
return this;
} | java | public InsertIntoTable addRowsFrom(File file, FileParser fileParser) {
builder.addRowsFrom(file, fileParser);
return this;
} | [
"public",
"InsertIntoTable",
"addRowsFrom",
"(",
"File",
"file",
",",
"FileParser",
"fileParser",
")",
"{",
"builder",
".",
"addRowsFrom",
"(",
"file",
",",
"fileParser",
")",
";",
"return",
"this",
";",
"}"
] | Adds all rows from the file specified, using the provided parser.
@param file File to read the data from.
@param fileParser Parser to be used to parse the file.
@return {@code this} | [
"Adds",
"all",
"rows",
"from",
"the",
"file",
"specified",
"using",
"the",
"provided",
"parser",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java#L172-L175 |
162,599 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java | InsertIntoTable.set | public InsertIntoTable set(String name, Object value) {
builder.set(name, value);
return this;
} | java | public InsertIntoTable set(String name, Object value) {
builder.set(name, value);
return this;
} | [
"public",
"InsertIntoTable",
"set",
"(",
"String",
"name",
",",
"Object",
"value",
")",
"{",
"builder",
".",
"set",
"(",
"name",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Set the given column name to the given value.
@param name The column name to set.
@param value the value to set.
@return {@code this}
@throws IllegalArgumentException if a column name does not exist in the table. | [
"Set",
"the",
"given",
"column",
"name",
"to",
"the",
"given",
"value",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/data/InsertIntoTable.java#L195-L198 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.