| 481 | } |
| 482 | |
| 483 | pair<string, Array<shared_ptr<CoefficientFunction>>> |
| 484 | flatten_einsum(const string& signature, |
| 485 | const Array<shared_ptr<CoefficientFunction>>& cfs, |
| 486 | const map<string, bool> &options) { |
| 487 | |
| 488 | Array<shared_ptr<CoefficientFunction>> new_cfs; |
| 489 | new_cfs.SetAllocSize(cfs.Size()); |
| 490 | |
| 491 | cout << IM(5) << "EinsumCF: flatten einsum CF (no recursion)" << endl; |
| 492 | auto parts = split_signature(signature); |
| 493 | |
| 494 | string used_symbols = signature; |
| 495 | |
| 496 | for (auto i : Range(cfs)) |
| 497 | if (auto cfi = dynamic_pointer_cast<EinsumCoefficientFunction>(cfs[i]); cfi) |
| 498 | { |
| 499 | auto nested_signature = cfi->ExpandedIndexSignature(); |
| 500 | parts[i] = expand_einsum_part(parts[i], nested_signature, used_symbols); |
| 501 | used_symbols += parts[i]; |
| 502 | auto nested_inputs = cfi->ExpandedInputCoefficientFunctions(); |
| 503 | new_cfs.Append(nested_inputs); |
| 504 | } |
| 505 | else |
| 506 | new_cfs.Append(cfs[i]); |
| 507 | |
| 508 | return {form_index_signature(parts), std::move(new_cfs)}; |
| 509 | } |
| 510 | |
| 511 | bool is_identity(const shared_ptr<CoefficientFunction> cf) { |
| 512 | if (dynamic_pointer_cast<IdentityCoefficientFunction>(cf)) |
no test coverage detected