@Override public SimpleIndices getOfType(IndexType type) { int type_ = type.getType() << 24; int i = 0; for (; i < data.length && (data[i] & 0x7F000000) != type_; ++i) ; int start = i; for (; i < data.length && (data[i] & 0x7F000000) == type_; ++i) ; int[] newData; if (start == 0 && i == data.length) newData = data; else newData = Arrays.copyOfRange(data, start, i); return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, newData); }
@Override public SimpleIndices getUpper() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.upper.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.upper, new UpperLowerIndices(ul.upper, new int[0])); }
/** * Returns resulting {@code Indices}. * * @return resulting {@code Indices} * @throws InconsistentIndicesException if there was more then one same index (with same names, types and states) */ public Indices getIndices() { return UnsafeIndicesFactory.createSortedWithoutCopy(data.toArray()); }
/** * 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)); }
UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices), arguments, argIndices);
/** * 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); }
@Override public SimpleIndices getFree() { IntArrayList dataList = new IntArrayList(); boolean y; for (int i = 0; i < data.length; i++) { y = true; for (int j = 0; j < data.length; j++) if (i != j && (data[i] ^ data[j]) == 0x80000000) { y = false; break; } if (y) dataList.add(data[i]); } return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, dataList.toArray()); }
@Override public SimpleIndices getLower() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.lower.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.lower, new UpperLowerIndices(new int[0], ul.lower)); }
/** * 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); }
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);
UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), indices), arguments, argIndices); } catch (RuntimeException re) {
/** * 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)); }
/** * 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)); }
UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), totalIndices), parent.args, parent.argIndices);