| 221 | } |
| 222 | |
| 223 | shared_ptr<CoefficientFunction> CoefficientFunction :: |
| 224 | DiffJacobi (const CoefficientFunction * var, T_DJC & cache) const |
| 225 | { |
| 226 | auto thisptr = const_pointer_cast<CoefficientFunction>(this->shared_from_this()); |
| 227 | if (cache.find(thisptr) != cache.end()) |
| 228 | return cache[thisptr]; |
| 229 | |
| 230 | /* |
| 231 | if (var->Dimensions().Size() == 0) |
| 232 | return this->Diff(var, make_shared<ConstantCoefficientFunction>(1)); |
| 233 | else |
| 234 | { |
| 235 | */ |
| 236 | Array<int> resultdims; |
| 237 | resultdims += this->Dimensions(); |
| 238 | resultdims += var->Dimensions(); |
| 239 | |
| 240 | if (this == var) // diff by me |
| 241 | return IdentityCF(Dimensions()); |
| 242 | |
| 243 | if (this->InputCoefficientFunctions().Size()==0) |
| 244 | return ZeroCF(resultdims); |
| 245 | |
| 246 | cout << IM(5) << "DiffJacobi for CoefficientFunction, type = " << typeid(*this).name() << endl; |
| 247 | |
| 248 | int dim = var->Dimension(); |
| 249 | Array<shared_ptr<CoefficientFunction>> ddi(dim); |
| 250 | for (int i = 0; i < dim; i++) |
| 251 | { |
| 252 | auto vec = UnitVectorCF(dim,i)->Reshape(var->Dimensions()); |
| 253 | ddi[i] = this->Diff(var, vec); |
| 254 | } |
| 255 | auto dvec = MakeVectorialCoefficientFunction (std::move(ddi)); |
| 256 | auto dvec1 = dvec->Reshape(var->Dimension(), this->Dimension()) -> Transpose(); |
| 257 | auto res = dvec1 -> Reshape(resultdims); |
| 258 | cache[thisptr] = res; |
| 259 | return res; |
| 260 | } |
| 261 | |
| 262 | shared_ptr<CoefficientFunction> CoefficientFunction :: |
| 263 | Primary() const |
nothing calls this directly
no test coverage detected