| 4925 | |
| 4926 | |
| 4927 | shared_ptr<CoefficientFunction> |
| 4928 | MakeTensorTraceCoefficientFunction (shared_ptr<CoefficientFunction> c1, int i1, int i2) |
| 4929 | { |
| 4930 | if (i1 < 0 || i1 >= c1->Dimensions().Size()) |
| 4931 | throw Exception ("TensorTrace, i1 out of range"); |
| 4932 | if (i2 < 0 || i2 >= c1->Dimensions().Size()) |
| 4933 | throw Exception ("TensorTrace, i2 out of range"); |
| 4934 | |
| 4935 | // a simple workaround for the beginning: |
| 4936 | if ( (i1 == 0 && i2 == 1) || (i1 == 1 && i2 == 0) ) |
| 4937 | { |
| 4938 | Array<int> dims1 { c1->Dimensions() }; |
| 4939 | auto dimsres = dims1.Range(2, END); |
| 4940 | |
| 4941 | // auto shapematT = TransposeCF (ReshapeCF (std::move(c1), sqr(dims1[0]), -1) ); |
| 4942 | // auto prod = shapematT * ReshapeCF ( IdentityCF(dims1[0]), sqr (dims1[0]) ); |
| 4943 | |
| 4944 | auto shapematT = c1 -> Reshape (sqr(dims1[0]), -1) -> Transpose(); |
| 4945 | auto prod = shapematT * IdentityCF(dims1[0]) -> Reshape (sqr (dims1[0])); |
| 4946 | |
| 4947 | return prod -> Reshape (Array<int> (dimsres)); |
| 4948 | } |
| 4949 | |
| 4950 | throw Exception("MakeTensorTraceCF not implemented for general case"); |
| 4951 | } |
| 4952 | |
| 4953 | |
| 4954 |
no test coverage detected