@Override public void apply(IndexMapper indexMapper, IGWrapper generator, int[] upper, int[] lower) { SimpleIndices oldIndices = node.indices; int[] _newIndices = new int[oldIndices.size() + 2 * upper.length]; int i; for (i = 0; i < oldIndices.size(); ++i) _newIndices[i] = indexMapper.map(oldIndices.get(i)); System.arraycopy(upper, 0, _newIndices, oldIndices.size(), upper.length); System.arraycopy(lower, 0, _newIndices, oldIndices.size() + upper.length, lower.length); for (i = 0; i < upper.length; ++i) _newIndices[i + oldIndices.size()] |= 0x80000000; node.indices = IndicesFactory.createSimple(null, _newIndices); } }
public IndicesInsertion(SimpleIndices upper, SimpleIndices lower, Indicator<ParseTokenSimpleTensor> indicator) { checkIndices(upper, lower); int[] upperArray = new int[upper.size()]; for (int i = upper.size() - 1; i >= 0; --i) upperArray[i] = IndicesUtils.getNameWithType(upper.get(i)); this.upper = upperArray; this.lower = lower.getAllIndices().copy(); this.indicator = indicator; }
private TensorGenerator(SimpleIndices indices, Tensor[] samples, boolean symmetricForm, boolean withCoefficients, boolean raiseLowerSamples) { if (raiseLowerSamples) this.samples = expandSamples(samples); else this.samples = samples; this.indices = indices; this.symmetricForm = symmetricForm; this.lowerArray = indices.getLower().toArray(); this.upperArray = indices.getUpper().toArray(); this.withCoefficients = withCoefficients; Arrays.sort(lowerArray); Arrays.sort(upperArray); generate(); }
/** * Returns {@code true} if this is structure of specified indices. * * @param indices indices * @return {@code true} if this is structure of specified indices */ public boolean isStructureOf(SimpleIndices indices) { if (size != indices.size()) return false; return equals(indices.getStructureOfIndices()); }
SymmetricDifferentiationRule(SimpleTensor var, boolean useDeltaFunction) { super(var, useDeltaFunction); SimpleIndices varIndices = var.getIndices(); int[] allFreeVarIndices = new int[varIndices.size()]; int[] allFreeArgIndices = new int[varIndices.size()]; byte type; int state, i = 0, length = allFreeArgIndices.length; IndexGeneratorImpl indexGenerator = new IndexGeneratorImpl(varIndices); for (; i < length; ++i) { type = getType(varIndices.get(i)); state = getRawStateInt(varIndices.get(i)); allFreeVarIndices[i] = setRawState(indexGenerator.generate(type), inverseIndexState(state)); allFreeArgIndices[i] = setRawState(indexGenerator.generate(type), state); SimpleIndices dIndices = IndicesFactory.createSimple(null, allIndices); SimpleTensor symmetric = simpleTensor("@!@#@##_AS@23@@#", dIndices); SimpleIndices allFreeVarIndicesI = IndicesFactory.createSimple(varIndices.getSymmetries(), allFreeVarIndices); Tensor derivative = new SymmetrizeTransformation(allFreeVarIndicesI, true).transform(symmetric); derivative, new Mapping(allIndices, addAll(varIndices.getInverted().getAllIndices().copy(), allFreeArgIndices)), new int[0]); ProductBuilder builder = new ProductBuilder(0, length); derivative = new SubstitutionTransformation(symmetric, builder.build()).transform(derivative); this.derivative = derivative; this.freeVarIndices = var.getIndices().getFree().getInverted().getAllIndices().copy(); this.allFreeFrom = addAll(allFreeArgIndices, freeVarIndices);
final int argPosition, final int order) { if (!derivativeIndices.getStructureOfIndices().equals(parent.argIndices[argPosition].getInverted().getStructureOfIndices().pow(order))) throw new IllegalArgumentException("Illegal derivative indices."); if (!fieldDescriptor.isDerivative() || derivativeIndices.size() == 0 || parent.indices.size() == 0) { totalIndices = new SimpleIndicesBuilder().append(parent.getIndices()).append(derivativeIndices).getIndices(); } else { for (byte type = IndexType.TYPES_COUNT - 1; type >= 0; --type) { eType = IndexType.values()[type]; singleType = parent.getIndices().getOfType(eType); from = fieldDescriptor.getParent().getStructureOfIndices().getTypeData(type).length; for (i = 0; i <= argPosition; ++i) from += structures[i + 1].getTypeData(type).length * orders[i]; for (i = 0; i < from; ++i) ib.append(singleType.get(i)); ib.append(derivativeIndices.getOfType(eType)); for (; i < singleType.size(); ++i) ib.append(singleType.get(i));
private PermutationGroup conjugatedSymmetriesOfSubIndices(SimpleIndices allIndices) { //positions of indices in allIndices that should be stabilized int[] stabilizedPoints = new int[allIndices.size() - indices.size()]; int[] nonStabilizedPoints = new int[indices.size()]; int[] mapping = new int[indices.size()]; int sPointer = 0, nPointer = 0, index; for (int s = 0; s < allIndices.size(); ++s) { index = Arrays.binarySearch(sortedIndicesNames, getNameWithType(allIndices.get(s))); if (index < 0) stabilizedPoints[sPointer++] = s; else { nonStabilizedPoints[nPointer] = s; mapping[nPointer++] = index; } } PermutationGroup result = allIndices.getSymmetries().getPermutationGroup(). pointwiseStabilizerRestricted(stabilizedPoints); return result.conjugate(Permutations.createPermutation(mapping)); }
if (!mode.printMatrixIndices && Tensors.isKronecker(this) && !CC.isMetric(IndicesUtils.getType(indices.get(0)))) { String str = clazz == Sum.class ? "1" : ""; return indices.getFree().size() == 0 ? toString0(mode.printMatrixIndices()) : str; SimpleIndices ofType = indices.getOfType(type); if (ofType.getFree().size() == 0) {
/** * Creates simple indices of simple tensor. * * @param symmetries symmetries * @param indices indices * @return simple indices of simple tensor */ public static SimpleIndices createOfTensor(IndicesSymmetries symmetries, SimpleIndices indices) { if (indices.size() == 0) return IndicesFactory.EMPTY_SIMPLE_INDICES; return new SimpleIndicesOfTensor(true, ((AbstractIndices) indices).data, symmetries); }
/** * Appends specified simple indices to this taking into account symmetries of passing indices. * * @param indices simple indices * @return this */ public SimpleIndicesBuilder append(SimpleIndices indices) { if (indices.size() == 0) return this; data.addAll(((AbstractSimpleIndices) indices).data); symmetries.add(new SymmetriesHolder(indices.size(), indices.getSymmetries().getGenerators())); return this; }
/** * Attaches symmetry to simple tensor. * * @param tensor simple tensor * @param permutation permutation * @throws java.lang.IllegalStateException if this tensor is already in use (it's permutation group calculated) * @throws java.lang.IllegalArgumentException if degree of specified permutation differs from the size of indices * of specified tensor */ public static void addSymmetry(SimpleTensor tensor, Permutation permutation) { tensor.getIndices().getSymmetries().addSymmetry(permutation); }
private static void revertIndex(ParseToken token, int index) { if (token instanceof ParseTokenSimpleTensor) { ParseTokenSimpleTensor pToken = (ParseTokenSimpleTensor) token; SimpleIndices indices = pToken.indices; for (int i = 0; i < indices.size(); i++) { if (indices.get(i) == index) { int[] inds = indices.toArray(); inds[i] = IndicesUtils.inverseIndexState(index); pToken.indices = IndicesFactory.createSimple(null, inds); break; } } } else if (token.tokenType == TokenType.Product || token.tokenType == TokenType.Trace || token.tokenType == TokenType.Sum) for (ParseToken c : token.content) revertIndex(c, index); } }
while (order > 0) { var = (SimpleTensor) from.get(i); indices = new int[var.getIndices().size()]; 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;
SimpleTensor apply(SimpleTensor t) { SimpleIndices oldIndices = t.getIndices(); int from = -1, to = -1; OUTER: for (int i = 0; i < oldIndices.size(); ++i) for (int j = 0; j < 2; ++j) if ((oldIndices.get(i) ^ indices[j]) == 0x80000000) { from = oldIndices.get(i); to = indices[1 - j]; break OUTER; } IM im = new IM(from, to); SimpleIndices newIndices = oldIndices.applyIndexMapping(im); if (oldIndices == newIndices) return t; if (t.getClass() == SimpleTensor.class) return Tensors.simpleTensor(t.getName(), newIndices); TensorField ff = (TensorField) t; return Tensors.field(ff.getName(), newIndices, ff.getArgIndices(), ff.getArguments()); }
private static int _hashWithIndices(final Tensor tensor, final int[] indices) { if (tensor instanceof SimpleTensor) { SimpleIndices si = ((SimpleTensor) tensor).getIndices(); short[] sInds = si.getPositionsInOrbits(); int hash = tensor.hashCode(); int pos; for (int i = 0; i < si.size(); ++i) if ((pos = Arrays.binarySearch(indices, si.get(i))) >= 0) hash += (HashFunctions.JenkinWang32shift(sInds[i]) ^ (HashFunctions.JenkinWang32shift(pos) * 37));
/** * Returns whether specified tensor is matrix of specified type and with specified signature. * * @param tensor simple tensor * @param type type of matrix * @param upper number of upper matrix indices * @param lower number of lower matrix indices * @return true if specified tensor is matrix of specified type and with specified signature and false in other case */ public static boolean isGeneralizedMatrix(SimpleTensor tensor, IndexType type, int upper, int lower) { if (CC.isMetric(type)) throw new IllegalArgumentException("Matrices can not be of metric type."); SimpleIndices indices = tensor.getIndices().getOfType(type); int i = 0; for (; i < upper; ++i) if (!getState(indices.get(i))) return false; upper += lower; for (; i < upper; ++i) if (getState(indices.get(i))) return false; return true; }