MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / DiffJacobi

Method DiffJacobi

fem/tensorcoefficient.cpp:1399–1450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1397 }
1398
1399 shared_ptr<CoefficientFunction>
1400 EinsumCoefficientFunction::DiffJacobi(
1401 const CoefficientFunction *var, T_DJC & cache) const
1402 {
1403 if (this == var)
1404 return IdentityCF(Dimensions());
1405
1406 Array<int> res_dims;
1407 res_dims.Append(Dimensions());
1408 res_dims.Append(var->Dimensions());
1409
1410 auto dres = ZeroCF(res_dims);
1411 try
1412 {
1413 // IMPORTANT NOTE:
1414 // use "original_index_signature" and "original_inputs" as only
1415 // these protect variables etc, i.e. they do not carry any
1416 // optimization!
1417 auto parts = split_signature(original_index_signature);
1418
1419 for (size_t i: Range(original_inputs.Size()))
1420 {
1421 auto new_inputs{original_inputs};
1422 new_inputs[i] = original_inputs[i]->DiffJacobi(var,cache);
1423 if (new_inputs[i]->IsZeroCF())
1424 continue;
1425 auto new_parts{parts};
1426 new_parts[i] = parts[i] + "...";
1427 new_parts.back() += "...";
1428 dres = dres + EinsumCF(form_index_signature(new_parts), new_inputs, options);
1429 }
1430
1431 // TODO: great potential for optimization when equivalent objects are
1432 // identified in Compile
1433 return dres;
1434 }
1435 catch (const OutOfIndices& e)
1436 {
1437 if (options.find("optimize_path") == options.end() || !options.at("optimize_path"))
1438 {
1439 cout << "Caught exception during DiffJacobi:\n"
1440 << e.What()
1441 << "\n"
1442 << "Trying again with a broken-down EinsumCF." << endl;
1443 auto opts = options;
1444 opts["optimize_path"] = true;
1445 opts["expand_einsum"] = false;
1446 return Optimize(opts)->DiffJacobi(var, cache);
1447 }
1448 throw e;
1449 }
1450 }
1451
1452 shared_ptr<EinsumCoefficientFunction>
1453 EinsumCoefficientFunction::Optimize(const map<string, bool> &aoptions) const

Callers

nothing calls this directly

Calls 13

IdentityCFFunction · 0.85
DimensionsFunction · 0.85
ZeroCFFunction · 0.85
split_signatureFunction · 0.85
EinsumCFFunction · 0.85
form_index_signatureFunction · 0.85
DimensionsMethod · 0.80
findMethod · 0.80
RangeFunction · 0.50
AppendMethod · 0.45
SizeMethod · 0.45
IsZeroCFMethod · 0.45

Tested by

no test coverage detected