private void generateDescriptors() { if (!generateNewDescriptors) return; for (int i = 0; i < initialNamespaceSize; ++i) { int[] typesCount = new int[TYPES_COUNT]; for (int j = 0; j < TYPES_COUNT; ++j) typesCount[j] = minIndices[j] + nextInt(maxIndices[j] - minIndices[j]); StructureOfIndices typeStructure = StructureOfIndices.create(TYPES, typesCount); NameDescriptor nameDescriptor = CC.getNameManager().mapNameDescriptor(nextName(), typeStructure); if (withSymmetries) addRandomSymmetries(nameDescriptor); namespace.add(nameDescriptor); } }
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; }
/** * Returns new tensor field with specified string name, indices, arguments * list and explicit argument indices bindings. * * @param name int name of the field * @param indices indices * @param argIndices argument indices bindings * @param arguments arguments list * @return new instance of {@link TensorField} object */ public static TensorField field(String name, SimpleIndices indices, SimpleIndices[] argIndices, Tensor[] arguments) { if (argIndices.length != arguments.length) throw new IllegalArgumentException("Argument indices array and arguments array have different length."); if (arguments.length == 0) throw new IllegalArgumentException("No arguments in field."); for (int i = 0; i < argIndices.length; ++i) if (!arguments[i].getIndices().getFree().equalsRegardlessOrder(argIndices[i])) throw new IllegalArgumentException("Arguments indices are inconsistent with arguments."); StructureOfIndices[] structures = new StructureOfIndices[argIndices.length + 1]; structures[0] = indices.getStructureOfIndices(); for (int i = 0; i < argIndices.length; ++i) structures[i + 1] = argIndices[i].getStructureOfIndices(); NameDescriptor descriptor = CC.getNameManager().mapNameDescriptor(name, structures); return new TensorField(descriptor.getId(), UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), arguments, argIndices); }
(NameDescriptorForTensorField) CC.getNameManager().mapNameDescriptor(name, structures);
/** * Returns metric tensor with specified indices. * * @param index1 first index * @param index2 second index * @return metric tensor with specified indices * @throws IllegalArgumentException if indices have different states * @throws IllegalArgumentException if indices have different types * @throws IllegalArgumentException if indices have non metric types */ public SimpleTensor createMetric(int index1, int index2) { byte type; if ((type = IndicesUtils.getType(index1)) != IndicesUtils.getType(index2) || !IndicesUtils.haveEqualStates(index1, index2) || !metricTypesBits.get(type)) throw new IllegalArgumentException("Not metric indices."); SimpleIndices indices = IndicesFactory.createSimple(null, index1, index2); NameDescriptor nd = nameManager.mapNameDescriptor(nameManager.getMetricName(), StructureOfIndices.create(indices)); int name = nd.getId(); return Tensors.simpleTensor(name, indices); }
/** * Returns Kronecker tensor with specified upper and lower indices. * * @param index1 first index * @param index2 second index * @return Kronecker tensor with specified upper and lower indices * @throws IllegalArgumentException if indices have same states * @throws IllegalArgumentException if indices have different types */ public SimpleTensor createKronecker(int index1, int index2) { byte type; if ((type = IndicesUtils.getType(index1)) != IndicesUtils.getType(index2) || IndicesUtils.getRawStateInt(index1) == IndicesUtils.getRawStateInt(index2)) throw new IllegalArgumentException("This is not kronecker indices!"); if (!isMetric(type) && IndicesUtils.getState(index2)) { int t = index1; index1 = index2; index2 = t; } SimpleIndices indices = IndicesFactory.createSimple(null, index1, index2); NameDescriptor nd = nameManager.mapNameDescriptor(nameManager.getKroneckerName(), StructureOfIndices.create(indices)); int name = nd.getId(); return Tensors.simpleTensor(name, indices); }
/** * Returns new simple tensor with specified string name and indices. * * @param name string name of the tensor * @param indices indices * @return new instance of {@link SimpleTensor} object */ public static SimpleTensor simpleTensor(String name, SimpleIndices indices) { NameDescriptor descriptor = CC.getNameManager().mapNameDescriptor(name, indices.getStructureOfIndices()); 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(descriptor.getId(), UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices)); }