@Override public Tensor transform(Tensor t) { return optimizeDummies(t); } });
FactorNode(Tensor factor, TensorBuilder builder) { this.factor = ApplyIndexMapping.optimizeDummies(factor); this.builder = builder; factorForbiddenIndices = TensorUtils.getAllIndicesNamesT(this.factor).toArray(); }
PrimitiveSubstitution(Tensor from, Tensor to) { this.from = ApplyIndexMapping.optimizeDummies(from); this.to = ApplyIndexMapping.optimizeDummies(to); int[] typesCounts = new int[IndexType.TYPES_COUNT]; TIntIterator iterator = TensorUtils.getAllDummyIndicesIncludingScalarFunctionsT(to).iterator(); while (iterator.hasNext()) ++typesCounts[IndicesUtils.getType(iterator.next())]; iterator = TensorUtils.getAllDummyIndicesT(from).iterator(); while (iterator.hasNext()) --typesCounts[IndicesUtils.getType(iterator.next())]; boolean possiblyAddsDummies = false; for (int i : typesCounts) if (i > 0) { possiblyAddsDummies = true; break; } this.possiblyAddsDummies = possiblyAddsDummies; this.toIsSymbolic = TensorUtils.isSymbolic(to); }
@Override public Tensor toTensor() { SimpleTensor[] vars = new SimpleTensor[content.length - 1]; Tensor temp = content[0].toTensor(); TIntHashSet allowedDummies = TensorUtils.getAllIndicesNamesT(temp); IndicesBuilder free = new IndicesBuilder().append(temp.getIndices()); for (int i = 1; i < content.length; ++i) { temp = content[i].toTensor(); free.append(temp.getIndices().getInverted()); allowedDummies.addAll(IndicesUtils.getIndicesNames(temp.getIndices())); if (!(temp instanceof SimpleTensor) && !(temp instanceof TensorField)) throw new IllegalArgumentException("Derivative with respect to non simple argument: " + temp); vars[i - 1] = (SimpleTensor) temp; } allowedDummies.removeAll(IndicesUtils.getIndicesNames(free.getIndices().getFree())); Tensor result = new DifferentiateTransformation( vars, new Transformation[]{ExpandAndEliminateTransformation.EXPAND_AND_ELIMINATE} ).transform(content[0].toTensor()); result = ApplyIndexMapping.optimizeDummies(result); TIntHashSet generated = TensorUtils.getAllDummyIndicesT(result); generated.removeAll(allowedDummies); result = ApplyIndexMapping.renameDummy(result, generated.toArray(), allowedDummies.toArray()); return result; } }
TByteObjectHashMap<MaxType> maxTypeCounts = new TByteObjectHashMap<>(); for (int i = oldData.length - 1; i >= 0; --i) { c = optimizeDummies(oldData[i]); if (c != oldData[i]) { if (newData == null)