Package cc.redberry.core.context

Examples of cc.redberry.core.context.NameDescriptor


    public static TensorField field(int 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.");
        NameDescriptor descriptor = CC.getNameDescriptor(name);
        if (descriptor == null)
            throw new IllegalArgumentException("This name is not registered in the system.");
        if (!descriptor.isField())
            throw new IllegalArgumentException("Name correspods to simple tensor (not a field).");
        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) {
            if (!descriptor.getStructuresOfIndices()[i + 1].isStructureOf(argIndices[i]))
                throw new IllegalArgumentException("Arguments indices are inconsistent with field signature.");
            if (!arguments[i].getIndices().getFree().equalsRegardlessOrder(argIndices[i]))
                throw new IllegalArgumentException("Arguments indices are inconsistent with arguments.");
        }
        return new TensorField(name,
                UnsafeIndicesFactory.createOfTensor(descriptor.getSymmetries(), indices),
                arguments, argIndices);
    }
View Full Code Here


     * @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);
    }
View Full Code Here

     * @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("Illegal structure of indices.");
        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));
    }
View Full Code Here

            minFree[i] = nextInt(random, maxMinFreeIndicesCount[i]);

        int N = nMin + nextInt(random, nMax - nMin);
        List<NameDescriptor> descriptors = new ArrayList<>();
        int[] typesCount;
        NameDescriptor nameDescriptor;
        for (i = 0; i < N; ++i) {
            typesCount = new int[IndexType.TYPES_COUNT];
            for (j = 0; j < IndexType.TYPES_COUNT; ++j)
                typesCount[j] = nextInt(random, maxIndicesPerTensor[j]);
            IndicesTypeStructure typeStructure = new IndicesTypeStructure(TYPES, typesCount);
            descriptors.add(nameDescriptor = new NameDescriptor(getName(i), typeStructure));
            CC.getNameManager().mapNameDescriptor(descriptors.get(i));
            if (withSymmetries)
                addRandomSymmetries(nameDescriptor);
        }

        Product product = new Product();
        IndicesProvider indicesProvider = new IndicesProvider(random, indicesCount, minFree);
        SimpleIndices ind;
        int scalars = 0;
        while (!descriptors.isEmpty() && product.size() <= maxTensorCount) {
            int descriptorIndex = nextInt(random, descriptors.size());
            NameDescriptor nd = descriptors.get(descriptorIndex);
            if (nd.getIndexTypeStructure().size() == 0)
                if (scalars++ > maxScalarsCount) {
                    descriptors.remove(descriptorIndex);
                    continue;
                }
            ind = indicesProvider.next(nd);
            if (ind == null) {
                descriptors.remove(descriptorIndex);
                continue;
            }
            product.add(new SimpleTensor(nd.getId(), ind));
        }
        return product;
    }
View Full Code Here

        this.tensorNames = new int[nameSpaceSize];
        for(int i=0; i< nameSpaceSize; ++i){
            int first = i % ALPHABET_SIZE;
            int second = i - first;
            String sName = new String(new char[]{(char) (0x41 + first), (char) (0x41 + second)});
            tensorNames[i] = CC.getNameManager().mapNameDescriptor(new NameDescriptor(sName, new IndicesTypeStructure(EmptyIndices.INSTANCE)));
        }
    }
View Full Code Here

        int i;
        for (i = 0; i < actualInput; ++i) {
            if (!(inputValues[i].get(0) instanceof SimpleTensor))
                throw new IllegalArgumentException();
            SimpleTensor st = (SimpleTensor) inputValues[i].get(0);
            NameDescriptor nd = CC.getNameDescriptor(st.getName());
            if (!nd.getName(null).equals(getStringInputName(i)))
                throw new IllegalArgumentException();
        }
        for (; i < INPUT_VALUES_GENERAL_COUNT; ++i)
            if (inputValues[i] != null)
                throw new IllegalArgumentException();
View Full Code Here

     * @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));
    }
View Full Code Here

     * @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));
    }
View Full Code Here

            throw new IllegalArgumentException("Illegal derivative indices.");

        int[] orders = new int[parent.size()];
        orders[argPosition] = order;
        NameDescriptorForTensorField fieldDescriptor = parent.getNameDescriptor();
        NameDescriptor derivativeDescriptor = fieldDescriptor.getDerivative(orders);

        SimpleIndices totalIndices;

        if (!fieldDescriptor.isDerivative() || derivativeIndices.size() == 0 || parent.indices.size() == 0) {
            totalIndices = new SimpleIndicesBuilder().append(parent.getIndices()).append(derivativeIndices).getIndices();
        } else {
            orders = fieldDescriptor.getDerivativeOrders();

            SimpleIndicesBuilder ib = new SimpleIndicesBuilder();
            StructureOfIndices[] structures = fieldDescriptor.getStructuresOfIndices();
            int i, from;
            SimpleIndices singleType;
            IndexType eType;
            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));
            }
            totalIndices = ib.getIndices();
        }

        return new TensorField(derivativeDescriptor.getId(),
                UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), totalIndices),
                parent.args, parent.argIndices);
    }
View Full Code Here

            structures[0] = structureOfIndices;

            NameDescriptorForTensorField fieldDescriptor =
                    (NameDescriptorForTensorField) CC.getNameManager().mapNameDescriptor(name, structures);

            NameDescriptor derivativeDescriptor = fieldDescriptor.getDerivative(orders);

            return new TensorField(derivativeDescriptor.getId(),
                    UnsafeIndicesFactory.createOfTensor(derivativeDescriptor.getSymmetries(), indices),
                    arguments, argIndices);
        } catch (RuntimeException re) {
            throw new IllegalArgumentException("Inconsistent derivative orders/indices.", re);
        }
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.context.NameDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.