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

Function optimize_legacy

fem/tensorcoefficient.cpp:618–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616
617
618 shared_ptr<CoefficientFunction>
619 optimize_legacy(const string& signature,
620 const Array<shared_ptr<CoefficientFunction>>& cfs,
621 [[maybe_unused]] const map<string, bool> &options) {
622
623 const auto index_sets = compute_multi_indices(signature, cfs);
624 for (size_t i: Range(cfs))
625 if (cfs[i]->IsZeroCF())
626 {
627 auto dims = index_dimensions(index_sets[cfs.Size()]);
628 return ZeroCF(dims);
629 }
630
631 cout << IM(5) << "EinsumCF: trying to detect some 'legacy' operations" << endl;
632
633 const bool optimize_identities =
634 get_option(options, "optimize_identities", true);
635
636 // Trace
637 if (cfs.Size() == 1 && index_sets[0].Size() == 2) {
638 if (index_sets[0][0].symbol == index_sets[0][1].symbol && index_sets[1].Size() == 0)
639 {
640 cout << IM(5) << "EinsumCF: detected trace" << endl;
641 return TraceCF(cfs[0]);
642 }
643 }
644
645 // Transpose
646 if (cfs.Size() == 1)
647 return optimize_transpose(signature, cfs, options);
648
649 // Mat * Vec
650 if (cfs.Size() == 2 && index_sets[0].Size() == 2 && index_sets[1].Size() == 1 &&
651 index_sets[2].Size() == 1 && index_sets[0][0].symbol != index_sets[0][1].symbol) {
652 if (index_sets[1][0].symbol == index_sets[0][1].symbol)
653 {
654 if (dynamic_pointer_cast<IdentityCoefficientFunction>(cfs[0]) &&
655 optimize_identities)
656 {
657 cout << IM(5) << "EinsumCF: detected I * vec" << endl;
658 return cfs[1];
659 }
660 cout << IM(5) << "EinsumCF: detected Mat * Vec" << endl;
661 return cfs[0] * cfs[1];
662 }
663 else if (index_sets[1][0].symbol == index_sets[0][0].symbol)
664 {
665 if (dynamic_pointer_cast<IdentityCoefficientFunction>(cfs[0]) &&
666 optimize_identities)
667 {
668 cout << IM(5) << "EinsumCF: detected I * vec" << endl;
669 return cfs[1];
670 }
671 cout << IM(5) << "EinsumCF: detected Mat.trans * Vec" << endl;
672 return TransposeCF(cfs[0]) * cfs[1];
673 }
674 }
675

Callers 1

Calls 11

compute_multi_indicesFunction · 0.85
index_dimensionsFunction · 0.85
ZeroCFFunction · 0.85
IMClass · 0.85
get_optionFunction · 0.85
TraceCFFunction · 0.85
optimize_transposeFunction · 0.85
TransposeCFFunction · 0.85
RangeFunction · 0.50
IsZeroCFMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected