| 4827 | }; |
| 4828 | |
| 4829 | shared_ptr<CoefficientFunction> |
| 4830 | MakeSubTensorCoefficientFunction (shared_ptr<CoefficientFunction> c1, int first, Array<int> num, Array<int> dist) |
| 4831 | { |
| 4832 | //further optimization possible by checking if only subtensor of c1 is zero.. |
| 4833 | if (c1->IsZeroCF()) |
| 4834 | return ZeroCF(num); |
| 4835 | |
| 4836 | // trivial sub-tensor ? |
| 4837 | const auto dims = c1->Dimensions(); |
| 4838 | bool trivial = (first == 0) && (num.Size() == dims.Size()) && (num == dims); |
| 4839 | for (int i = 0; i+1 < dist.Size(); i++) |
| 4840 | if (dist[i] != num[i]*dist[i+1]) trivial = false; |
| 4841 | if (dist.Size() >= 1) |
| 4842 | if (dist.Last() != 1) trivial = false; |
| 4843 | |
| 4844 | if (trivial) |
| 4845 | { |
| 4846 | cout << IM(5) << "optimizing out trivial sub-tensor" << endl; |
| 4847 | return c1; |
| 4848 | } |
| 4849 | |
| 4850 | return make_shared<SubTensorCoefficientFunction> (c1, first, std::move(num), std::move(dist)); |
| 4851 | } |
| 4852 | |
| 4853 | |
| 4854 | shared_ptr<CoefficientFunction> |
no test coverage detected