| 214 | } |
| 215 | |
| 216 | void ProxyFunction :: |
| 217 | GenerateCode(Code &code, FlatArray<int> inputs, int index) const |
| 218 | { |
| 219 | // auto dims = Dimensions(); |
| 220 | |
| 221 | string header = "\n\ |
| 222 | {flatmatrix} {values};\n\ |
| 223 | ProxyUserData * {ud} = (ProxyUserData*)mir.GetTransformation().userdata;\n\ |
| 224 | {\n\ |
| 225 | // if (!{ud})\n \ |
| 226 | // throw Exception (\"cannot evaluate ProxyFunction without userdata\");\n \ |
| 227 | "; |
| 228 | |
| 229 | if(!testfunction) { |
| 230 | header+= |
| 231 | " if ({ud}->fel) {\n\ |
| 232 | // if ({ud}->HasMemory ({this})) {\n"; |
| 233 | if(code.is_simd) { |
| 234 | header += "auto x = {ud}->GetAMemory ({this});\n"; |
| 235 | header += "{values}.AssignMemory(x.Height(), x.Width(), &x(0,0));\n"; |
| 236 | } else { |
| 237 | header += "auto x = {ud}->GetMemory ({this});\n"; |
| 238 | header += "{values}.AssignMemory(x.Height(), x.Width(), &x(0,0));\n"; |
| 239 | } |
| 240 | header+= |
| 241 | " // }\n\ |
| 242 | // else\n\ |
| 243 | // throw Exception(\"userdata has no memory!\");\n\ |
| 244 | }\n"; |
| 245 | } |
| 246 | header += "}\n"; |
| 247 | if(code.deriv || !testfunction) |
| 248 | header += "const bool {has_values} = {ud}->HasMemory({this});\n"; |
| 249 | else |
| 250 | header += "constexpr bool {has_values} = true;\n"; // always need values in case code.deriv==0 (i.e. evaluation of proxy) |
| 251 | |
| 252 | for (int i = 0; i < this->Dimension(); i++) { |
| 253 | header += Var("comp", index,i,this->Dimensions()).Declare("{scal_type}", 0.0); |
| 254 | if(!testfunction && code.deriv==2) |
| 255 | { |
| 256 | header += "if(( ({ud}->trialfunction == {this}) && ({ud}->trial_comp=="+ToLiteral(i)+"))\n"+ |
| 257 | " || (({ud}->testfunction == {this}) && ({ud}->test_comp=="+ToLiteral(i)+")))\n"; |
| 258 | } |
| 259 | else |
| 260 | header += "if({ud}->{comp_string}=="+ToLiteral(i)+" && {ud}->{func_string} == {this})\n"; |
| 261 | header += Var("comp", index,i,this->Dimensions()).S() + string("{get_component}") + " = 1.0;\n"; |
| 262 | } |
| 263 | |
| 264 | string body = ""; |
| 265 | |
| 266 | if (code_uses_tensors) |
| 267 | { |
| 268 | body += "Tens<" + code.res_type; |
| 269 | for (auto d : this->Dimensions()) |
| 270 | body += ',' + ToLiteral(d); |
| 271 | body += "> var_" + ToLiteral(index) + ";\n"; |
| 272 | } |
| 273 |
nothing calls this directly
no test coverage detected