| 999 | } |
| 1000 | |
| 1001 | EinsumCoefficientFunction::EinsumCoefficientFunction( |
| 1002 | const string &aindex_signature, |
| 1003 | const Array<shared_ptr<CoefficientFunction>> &acfs, |
| 1004 | const map<string, bool> &aoptions) |
| 1005 | : |
| 1006 | BASE(1, |
| 1007 | std::find_if(acfs.begin(), acfs.end(), |
| 1008 | [](const auto &item) |
| 1009 | { |
| 1010 | return item->IsComplex(); |
| 1011 | }) != acfs.end()), |
| 1012 | max_mem{0}, |
| 1013 | options{aoptions}, |
| 1014 | node{}, |
| 1015 | original_index_signature{validate_signature(aindex_signature)}, |
| 1016 | original_inputs{acfs} { |
| 1017 | |
| 1018 | if (original_inputs.Size() != (split_signature(original_index_signature).size() - 1)) |
| 1019 | throw NG_EXCEPTION("number of input cfs does not match the number of inputs in the index signature"); |
| 1020 | |
| 1021 | if (get_option(options, "expand_einsum", true)) |
| 1022 | { |
| 1023 | try |
| 1024 | { |
| 1025 | tie(expanded_index_signature, expanded_inputs) = |
| 1026 | flatten_einsum(original_index_signature, original_inputs, options); |
| 1027 | } |
| 1028 | catch (const Exception& e) { |
| 1029 | cout << "Caught exception during Einsum flattening:\n" |
| 1030 | << e.What() << endl; |
| 1031 | tie(expanded_index_signature, expanded_inputs) = |
| 1032 | tie(original_index_signature, original_inputs); |
| 1033 | options["expand_einsum"] = false; |
| 1034 | } |
| 1035 | } |
| 1036 | else |
| 1037 | tie(expanded_index_signature, expanded_inputs) = |
| 1038 | tie(original_index_signature, original_inputs); |
| 1039 | |
| 1040 | bool detected_zero_input = find_if( |
| 1041 | expanded_inputs.begin(), expanded_inputs.end(), |
| 1042 | [](const auto& cf) { return cf->IsZeroCF();} |
| 1043 | ) != expanded_inputs.end(); |
| 1044 | |
| 1045 | if (detected_zero_input) |
| 1046 | { |
| 1047 | is_zero = true; |
| 1048 | const auto index_sets = compute_multi_indices(expanded_index_signature, expanded_inputs); |
| 1049 | auto dims = index_dimensions(index_sets[expanded_inputs.Size()]); |
| 1050 | node = ZeroCF(dims); |
| 1051 | index_signature = ""; |
| 1052 | cfs = {}; |
| 1053 | } |
| 1054 | else if (get_option(options, "optimize_path", false)) |
| 1055 | { |
| 1056 | if (get_option(options, "optimize_identities", false)) |
| 1057 | { |
| 1058 | tie(index_signature, cfs) = expand_higher_order_identities( |
nothing calls this directly
no test coverage detected