protected Tensor nextTensorTree(TensorType head, int depth, Parameters parameters) { return nextTensorTree(head, depth, parameters, IndicesFactory.createSimple(null, nextIndices(nextNameDescriptor().getStructureOfIndices()))); }
private NameDescriptor nextNameDescriptor(StructureOfIndices typeStructure) { //search IntArrayList positions = new IntArrayList(); for (int i = namespace.size() - 1; i >= 0; --i) if (namespace.get(i).getStructureOfIndices().equals(typeStructure)) positions.add(i); if (!positions.isEmpty()) return namespace.get(positions.get(random.nextInt(positions.size()))); if (!generateNewDescriptors) throw new IllegalArgumentException("No descriptor for such structure: " + typeStructure); //create new nameDescriptor NameDescriptor nameDescriptor = CC.getNameManager().mapNameDescriptor(nextName(), typeStructure); if (withSymmetries) addRandomSymmetries(nameDescriptor); if (namespace.indexOf(nameDescriptor) == -1) namespace.add(nameDescriptor); return nameDescriptor; }
public Tensor nextProduct(int minProductSize) { return nextProduct(minProductSize, IndicesFactory.createSimple(null, nextIndices(nextNameDescriptor().getStructureOfIndices()))); }
static final IndexType[] extractTypesFromMatrix(SimpleTensor matrix) { if (matrix.getIndices().size() != 3) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); NameDescriptor descriptor = CC.getNameDescriptor(matrix.getName()); StructureOfIndices typeStructure = descriptor.getStructureOfIndices(); byte metricType = -1, matrixType = -1; int typeCount; for (byte type = 0; type < IndexType.TYPES_COUNT; ++type) { typeCount = typeStructure.typeCount(type); if (typeCount == 0) continue; else if (typeCount == 2) { if (matrixType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); matrixType = type; if (CC.isMetric(matrixType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else if (typeCount == 1) { if (metricType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); metricType = type; if (!CC.isMetric(metricType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } return new IndexType[]{IndexType.getType(metricType), IndexType.getType(matrixType)}; }
public void addInsertionRule(NameDescriptor nd, IndexType omittedIndexType) { NameAndStructureOfIndices originalStructureAndName = NameDescriptor.extractKey(nd); StructureOfIndices structure = nd.getStructureOfIndices(); if (structure.getTypeData(omittedIndexType.getType()).length == 0) throw new IllegalArgumentException("No indices of specified type in tensor."); if (CC.isMetric(omittedIndexType.getType())) { int omittedIndicesCount = structure.getTypeData(omittedIndexType.getType()).length; if ((omittedIndicesCount % 2) == 1) throw new IllegalArgumentException("The number of omitted indices for metric types should be even."); omittedIndicesCount /= 2; BitArray omittedIndices = structure.getTypeData(omittedIndexType.getType()).states; for (int i = 0, size = omittedIndices.size(); i < size; ++i) { if (i < omittedIndicesCount && !omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); if (i >= omittedIndicesCount && omittedIndices.get(i)) throw new IllegalArgumentException("Inconsistent states signature for metric type."); } } mappedRules = null; InsertionRule rule = initialRules.get(originalStructureAndName); if (rule == null) initialRules.put(originalStructureAndName, rule = new InsertionRule(originalStructureAndName)); rule.indicesAllowedToOmit.add(omittedIndexType); }
if (descriptor.getStructuresOfIndices().length - 1 != argIndices.length) throw new IllegalArgumentException("This name corresponds to field with different number of arguments."); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException("Specified indices are not indices of specified tensor."); for (int i = 0; i < argIndices.length; ++i) {
/** * Returns new tensor field with specified int name (see {@link cc.redberry.core.context.NameManager} * for details), indices and arguments list. Free indices of arguments * assumed as arguments indices bindings of this field bindings. * * @param name int name of the field * @param indices indices * @param arguments arguments list * @return new instance of {@link TensorField} object */ public static TensorField field(int name, SimpleIndices indices, Tensor[] arguments) { if (arguments.length == 0) throw new IllegalArgumentException("No arguments in field."); NameDescriptor descriptor = CC.getNameDescriptor(name); if (descriptor == null) throw new IllegalArgumentException("This name is not registered in the system."); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException("Specified indices are not indices of specified tensor."); SimpleIndices[] argIndices = new SimpleIndices[arguments.length]; for (int i = 0; i < arguments.length; ++i) argIndices[i] = IndicesFactory.createSimple(null, arguments[i].getIndices().getFree()); return new TensorField(name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), arguments, argIndices); }
public SimpleTensor nextSimpleTensor() { NameDescriptor nd = nextNameDescriptor(); StructureOfIndices structureOfIndices = nd.getStructureOfIndices(); int[] indices = nextIndices(structureOfIndices); return Tensors.simpleTensor(nd.getId(), IndicesFactory.createSimple(nd.getSymmetries(), indices)); }
public SimpleTensor nextSimpleTensor(SimpleIndices indices) { NameDescriptor nd = nextNameDescriptor(indices.getStructureOfIndices()); StructureOfIndices structureOfIndices = nd.getStructureOfIndices(); int[] _indices = nextIndices(structureOfIndices); return Tensors.simpleTensor(nd.getId(), IndicesFactory.createSimple(nd.getSymmetries(), _indices)); }
/** * Returns an instance of specified simple tensor with specified indices * * @param tensor simple tensor * @param indices indices * @return instance of specified simple tensor with specified indices */ public static SimpleTensor setIndices(SimpleTensor tensor, SimpleIndices indices) { if (tensor.getIndices() == indices) return tensor; NameDescriptor descriptor = tensor.getNameDescriptor(); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException(String.format("Illegal structure of indices (tensor = %s, indices = %s).", tensor, indices)); if (indices.size() == 0) return tensor; if (descriptor.isField()) return new TensorField(tensor.name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), ((TensorField) tensor).args, ((TensorField) tensor).argIndices); else return new SimpleTensor(tensor.name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
/** * Returns new simple tensor with specified int name (see {@link cc.redberry.core.context.NameManager} * for details) and indices. * * @param name int name of the tensor * @param indices indices * @return new instance of {@link SimpleTensor} object */ public static SimpleTensor simpleTensor(int name, SimpleIndices indices) { NameDescriptor descriptor = CC.getNameDescriptor(name); if (descriptor == null) throw new IllegalArgumentException("This name is not registered in the system."); if (!descriptor.getStructureOfIndices().isStructureOf(indices)) throw new IllegalArgumentException("Specified indices ( " + indices + " )are not indices of specified tensor ( " + descriptor + " )."); if (indices.size() == 0) { assert indices == IndicesFactory.EMPTY_SIMPLE_INDICES; NameDescriptorForSimpleTensor nst = (NameDescriptorForSimpleTensor) descriptor; if (nst.getCachedSymbol() == null) { SimpleTensor st; nst.setCachedInstance(st = new SimpleTensor(descriptor.getId(), indices)); return st; } else return nst.getCachedSymbol(); } return new SimpleTensor(name, UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }
private void addRandomSymmetries(NameDescriptor descriptor) {//TODO add antisymmetries if (!descriptor.getSymmetries().isTrivial()) //todo <= review this moment return; StructureOfIndices typeStructure = descriptor.getStructureOfIndices(); int i; for (byte type = 0; type < TYPES_COUNT; ++type) { StructureOfIndices.TypeData typeData = typeStructure.getTypeData(type); if (typeData == null) continue; if (typeData.length == 0)//redundant continue; int count = random.nextInt(4); for (i = 0; i < count; ++i) descriptor.getSymmetries().addSymmetry(type, Permutations.createPermutation(false, nextPermutation(typeData.length))); } }