DFromTo derivative = derivatives.get(orders);
if (derivative == null) {
int order, j;
SimpleTensor var;
int[] indices;
SimpleIndices varIndices;
TensorField __from = (TensorField) this.from;
Tensor __to = this.to;
IndexGeneratorImpl ig = null;
for (int i = orders.length() - 1; i >= 0; --i) {
order = orders.get(i) - this.orders.get(i);
while (order > 0) {
var = (SimpleTensor) from.get(i);
indices = new int[var.getIndices().size()];
//lazy initialization
if (indices.length != 0 && ig == null) {
TIntHashSet forbidden = new TIntHashSet(iterator.getForbidden());
forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.from));
forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.to));
ig = new IndexGeneratorImpl(forbidden.toArray());
}
for (j = indices.length - 1; j >= 0; --j)
indices[j] = setRawState(getRawStateInt(var.getIndices().get(j)),
ig.generate(getType(var.getIndices().get(j))));
varIndices = UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, indices);
var = Tensors.setIndices(var, varIndices);
__from = Tensors.fieldDerivative(__from, varIndices.getInverted(), i);
__to = new DifferentiateTransformation(var).transform(__to);
--order;
}
}
derivative = new DFromTo(__from, __to);