Commit 7e484447 authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Merge branch 'devel/matrix_init_fix' into 'master'

Devel/matrix init fix

See merge request exastencils/exastencils!54
parents e5f5e5c9 c2c43e32
...@@ -212,11 +212,15 @@ object IR_MatNodeUtils { ...@@ -212,11 +212,15 @@ object IR_MatNodeUtils {
/** Method: split a declaration with init to declaration and assignment with init /** Method: split a declaration with init to declaration and assignment with init
* *
* @param decl : IR_VariableDeclaration, declaration to be split * @param decl : IR_VariableDeclaration, declaration to be split
* @return list containing variable declaration without init and assignment of that variable with init expresion * @return list containing variable declaration without init and assignment of that variable with init expression
* */ * */
def splitDeclaration(decl : IR_VariableDeclaration) : ListBuffer[IR_Statement] = { def splitDeclaration(decl : IR_VariableDeclaration, zeroInit : Boolean = false) : ListBuffer[IR_Statement] = {
val newStmts = ListBuffer[IR_Statement]() val newStmts = ListBuffer[IR_Statement]()
if(zeroInit) {
newStmts += IR_VariableDeclaration(decl.datatype, decl.name, IR_IntegerConstant(0))
} else {
newStmts += IR_VariableDeclaration(decl.datatype, decl.name, None) newStmts += IR_VariableDeclaration(decl.datatype, decl.name, None)
}
newStmts += IR_Assignment(IR_VariableAccess(decl), decl.initialValue.getOrElse(IR_NullExpression)) newStmts += IR_Assignment(IR_VariableAccess(decl), decl.initialValue.getOrElse(IR_NullExpression))
newStmts newStmts
} }
......
...@@ -118,7 +118,7 @@ object IR_GenerateBasicMatrixOperations { ...@@ -118,7 +118,7 @@ object IR_GenerateBasicMatrixOperations {
var _j = IR_VariableAccess("_j", IR_IntegerDatatype) var _j = IR_VariableAccess("_j", IR_IntegerDatatype)
func.body += IR_ForLoop(IR_VariableDeclaration(_i, IR_IntegerConstant(0)), IR_Lower(_i, sizeMLeft), IR_PreIncrement(_i), ListBuffer[IR_Statement]( func.body += IR_ForLoop(IR_VariableDeclaration(_i, IR_IntegerConstant(0)), IR_Lower(_i, sizeMLeft), IR_PreIncrement(_i), ListBuffer[IR_Statement](
IR_ForLoop(IR_VariableDeclaration(_j, 0), IR_Lower(_j, sizeNLeft), IR_PreIncrement(_j), ListBuffer[IR_Statement]( IR_ForLoop(IR_VariableDeclaration(_j, 0), IR_Lower(_j, sizeNLeft), IR_PreIncrement(_j), ListBuffer[IR_Statement](
IR_IfCondition(IR_Greater(IR_FunctionCall(IR_ExternalFunctionReference.fabs, IR_Subtraction(IR_FunctionCall(IR_ExternalFunctionReference.fabs, IR_HighDimAccess(left, IR_ExpressionIndex(_i, _j))), IR_FunctionCall(IR_ExternalFunctionReference.fabs, IR_HighDimAccess(right, IR_ExpressionIndex(_i, _j))))), precision), ListBuffer[IR_Statement]( IR_IfCondition(IR_Greater(IR_FunctionCall(IR_ExternalFunctionReference.fabs, IR_Subtraction(IR_HighDimAccess(left, IR_ExpressionIndex(_i, _j)), IR_HighDimAccess(right, IR_ExpressionIndex(_i, _j)))), precision), ListBuffer[IR_Statement](
IR_Print(outstream, ListBuffer[IR_Expression](IR_StringConstant("[Test] comparison failed at "), _i, IR_StringConstant(" "), _j, IR_StringConstant("\\n"), IR_HighDimAccess(left, IR_ExpressionIndex(_i, _j)), IR_StringConstant(" vs "), IR_HighDimAccess(right, IR_ExpressionIndex(_i, _j)), IR_StringConstant("\\n"))), IR_Print(outstream, ListBuffer[IR_Expression](IR_StringConstant("[Test] comparison failed at "), _i, IR_StringConstant(" "), _j, IR_StringConstant("\\n"), IR_HighDimAccess(left, IR_ExpressionIndex(_i, _j)), IR_StringConstant(" vs "), IR_HighDimAccess(right, IR_ExpressionIndex(_i, _j)), IR_StringConstant("\\n"))),
if (returnStmt) IR_Return(IR_IntegerConstant(-1)) else IR_NullStatement if (returnStmt) IR_Return(IR_IntegerConstant(-1)) else IR_NullStatement
), ListBuffer[IR_Statement]()) ), ListBuffer[IR_Statement]())
...@@ -692,9 +692,9 @@ object IR_GenerateRuntimeInversion { ...@@ -692,9 +692,9 @@ object IR_GenerateRuntimeInversion {
// copy A and invert // copy A and invert
//TODO use algorithm that exploits structure -> receive matrix structure information from classifier -> e.g. blockdiagonal //TODO use algorithm that exploits structure -> receive matrix structure information from classifier -> e.g. blockdiagonal
// blocksize of the diagonal blocks of A if A is a blockdiagonal matrix -> later this information comes from the classifyer? // blocksize of the diagonal blocks of A if A is a blockdiagonal matrix -> later this information comes from the classifyer?
func.body += IR_VariableDeclaration(A) func.body += IR_VariableDeclaration(A, IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, A, 0, 0, n, n) func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, A, 0, 0, n, n)
func.body += IR_VariableDeclaration(A_inv) func.body += IR_VariableDeclaration(A_inv,IR_IntegerConstant(0))
if (structureA == "blockdiagonal") if (structureA == "blockdiagonal")
func.body += IR_GenerateRuntimeInversion.blockdiagonalInlined(A, blockSizeA, A_inv) func.body += IR_GenerateRuntimeInversion.blockdiagonalInlined(A, blockSizeA, A_inv)
else if (structureA == "diagonal") else if (structureA == "diagonal")
...@@ -706,33 +706,33 @@ object IR_GenerateRuntimeInversion { ...@@ -706,33 +706,33 @@ object IR_GenerateRuntimeInversion {
func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(A_inv) func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(A_inv)
// copy B // copy B
func.body += IR_VariableDeclaration(B) func.body += IR_VariableDeclaration(B, IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, B, 0, n, n, m) func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, B, 0, n, n, m)
// copy C // copy C
func.body += IR_VariableDeclaration(C) func.body += IR_VariableDeclaration(C, IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, C, n, 0, m, n) func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, C, n, 0, m, n)
// copy D // copy D
func.body += IR_VariableDeclaration(D) func.body += IR_VariableDeclaration(D, IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, D, n, n, m, m) func.body += IR_GenerateBasicMatrixOperations.loopCopySubmatrix(in, D, n, n, m, m)
// calculate S // calculate S
func.body += IR_VariableDeclaration(S) func.body += IR_VariableDeclaration(S, IR_IntegerConstant(0))
func.body += IR_VariableDeclaration(CA_inv) func.body += IR_VariableDeclaration(CA_inv,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(C, A_inv, CA_inv, m, n, n, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(C, A_inv, CA_inv, m, n, n, 0, 0)
func.body += IR_VariableDeclaration(CA_invB) func.body += IR_VariableDeclaration(CA_invB,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(CA_inv, B, CA_invB, m, m, n, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(CA_inv, B, CA_invB, m, m, n, 0, 0)
func.body += IR_GenerateBasicMatrixOperations.subAtSubmatrix(D, CA_invB, S, m, m, m, 0, 0) func.body += IR_GenerateBasicMatrixOperations.subAtSubmatrix(D, CA_invB, S, m, m, m, 0, 0)
// calculate S_inv // calculate S_inv
func.body += IR_VariableDeclaration(S_inv) func.body += IR_VariableDeclaration(S_inv,IR_IntegerConstant(0))
func.body += IR_GenerateRuntimeInversion.inverse(S, S_inv, IR_MatShape("filled")) func.body += IR_GenerateRuntimeInversion.inverse(S, S_inv, IR_MatShape("filled"))
// calculate upper right result block // calculate upper right result block
func.body += IR_VariableDeclaration(A_invB) func.body += IR_VariableDeclaration(A_invB,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_inv, B, A_invB, n, m, n, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_inv, B, A_invB, n, m, n, 0, 0)
func.body += IR_VariableDeclaration(A_invBS_inv) func.body += IR_VariableDeclaration(A_invBS_inv,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_invB, S_inv, A_invBS_inv, n, m, m, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_invB, S_inv, A_invBS_inv, n, m, m, 0, 0)
func.body += IR_GenerateBasicMatrixOperations.negAtSubmatrix(A_invBS_inv, out, n + m, n, m, 0, n_asInt) func.body += IR_GenerateBasicMatrixOperations.negAtSubmatrix(A_invBS_inv, out, n + m, n, m, 0, n_asInt)
...@@ -745,7 +745,7 @@ object IR_GenerateRuntimeInversion { ...@@ -745,7 +745,7 @@ object IR_GenerateRuntimeInversion {
func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(S_inv) func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(S_inv)
// calculate lower left result block // calculate lower left result block
func.body += IR_VariableDeclaration(S_invCA_inv) func.body += IR_VariableDeclaration(S_invCA_inv,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(S_inv, CA_inv, S_invCA_inv, m, n, m, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(S_inv, CA_inv, S_invCA_inv, m, n, m, 0, 0)
func.body += IR_GenerateBasicMatrixOperations.negAtSubmatrix(S_invCA_inv, out, m + n, m, n, n_asInt, 0) func.body += IR_GenerateBasicMatrixOperations.negAtSubmatrix(S_invCA_inv, out, m + n, m, n, n_asInt, 0)
...@@ -753,7 +753,7 @@ object IR_GenerateRuntimeInversion { ...@@ -753,7 +753,7 @@ object IR_GenerateRuntimeInversion {
func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(S_invCA_inv) func.body ++= IR_GenerateBasicMatrixOperations.printMatrix(S_invCA_inv)
// calculate upper left result block // calculate upper left result block
func.body += IR_VariableDeclaration(A_invBS_invCA_inv) func.body += IR_VariableDeclaration(A_invBS_invCA_inv,IR_IntegerConstant(0))
func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_invB, S_invCA_inv, A_invBS_invCA_inv, n, n, m, 0, 0) func.body += IR_GenerateBasicMatrixOperations.multAtSubmatrix(A_invB, S_invCA_inv, A_invBS_invCA_inv, n, n, m, 0, 0)
func.body += IR_GenerateBasicMatrixOperations.addAtSubmatrix(A_inv, A_invBS_invCA_inv, out, n + m, n, n, 0, 0) func.body += IR_GenerateBasicMatrixOperations.addAtSubmatrix(A_inv, A_invBS_invCA_inv, out, n + m, n, n, 0, 0)
......
...@@ -276,8 +276,12 @@ object IR_ResolveMatFuncs extends DefaultStrategy("Resolve matFuncs") { ...@@ -276,8 +276,12 @@ object IR_ResolveMatFuncs extends DefaultStrategy("Resolve matFuncs") {
*/ */
this += new Transformation("Insert resolvables and resolve", { this += new Transformation("Insert resolvables and resolve", {
case decl @ IR_VariableDeclaration(_, _, Some(r : IR_RuntimeMNode), _) if r.resolveAtRuntime => case decl @ IR_VariableDeclaration(dt, _, Some(r : IR_RuntimeMNode), _) if r.resolveAtRuntime =>
if(dt.isInstanceOf[IR_MatrixDatatype]) {
IR_MatNodeUtils.splitDeclaration(decl, true)
} else {
IR_MatNodeUtils.splitDeclaration(decl) IR_MatNodeUtils.splitDeclaration(decl)
}
// not to resolve at runtime // not to resolve at runtime
case r : IR_RuntimeMNode if !r.resolveAtRuntime => case r : IR_RuntimeMNode if !r.resolveAtRuntime =>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment