Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.Indices


        return set;
    }

    private static void getAllIndicesT1(ParseToken node, TIntSet set) {
        if (node instanceof ParseTokenSimpleTensor) {
            Indices indices = node.getIndices();
            for (int i = indices.size() - 1; i >= 0; --i)
                set.add(IndicesUtils.getNameWithType(indices.get(i)));
        } else
            for (ParseToken pn : node.content)
                if (!(pn instanceof ParseTokenScalarFunction))
                    getAllIndicesT1(pn, set);
    }
View Full Code Here


        }

        int tensorIndex;
        for (tensorIndex = 0; tensorIndex < data.length; ++tensorIndex) {
            //Main algorithm
            Indices tInds = data[tensorIndex].getIndices();
            short[] diffIds = tInds.getDiffIds();

            //FUTURE move to other place
            if (tInds.size() >= 0x10000)
                throw new RuntimeException("Too many indices!!! max count = 2^16");

            for (i = 0; i < tInds.size(); ++i) {
                index = tInds.get(i);
                state = IndicesUtils.getStateInt(index);
                info[state][pointer[state]] = packToLong(tensorIndex, diffIds[i], i);
                indices[state][pointer[state]++] = IndicesUtils.getNameWithType(index);
            }

            //Result allocation
            contractions[tensorIndex] = new long[tInds.size()];
        }

        //Here we can use unstable sorting algorithm (all indices are different)
        ArraysUtils.quickSort(indices[0], info[0]);
        ArraysUtils.quickSort(indices[1], info[1]);
View Full Code Here

        appendAllIndicesNamesT(tensor, set, true);
    }

    private static void appendAllIndicesNamesT(Tensor tensor, TIntHashSet set, boolean includeScalarFunctions) {
        if (tensor instanceof SimpleTensor) {
            Indices ind = tensor.getIndices();
            set.ensureCapacity(ind.size());
            final int size = ind.size();
            for (int i = 0; i < size; ++i)
                set.add(IndicesUtils.getNameWithType(ind.get(i)));
        } else if (tensor instanceof Power) {
            appendAllIndicesNamesT(tensor.get(0), set);
        } else if (tensor instanceof ScalarFunction && !includeScalarFunctions)
            return;
        else {
View Full Code Here

        assertIndicesConsistency(t, new TIntHashSet());
    }

    private static void assertIndicesConsistency(Tensor t, TIntHashSet indices) {
        if (t instanceof SimpleTensor) {
            Indices ind = t.getIndices();
            for (int i = ind.size() - 1; i >= 0; --i)
                if (indices.contains(ind.get(i)))
                    throw new AssertionError(new InconsistentIndicesException(ind.get(i)));
                else
                    indices.add(ind.get(i));
        }
        if (t instanceof Product)
            for (int i = t.size() - 1; i >= 0; --i)
                assertIndicesConsistency(t.get(i), indices);
        if (t instanceof Sum) {
View Full Code Here

                assertIndicesConsistency(c, new TIntHashSet(indices));
    }

    private static void appendAllIndicesT(Tensor tensor, TIntHashSet set) {
        if (tensor instanceof SimpleTensor) {
            Indices ind = tensor.getIndices();
            final int size = ind.size();
            for (int i = 0; i < size; ++i)
                set.add(ind.get(i));
        } else if (tensor instanceof Power) {
            appendAllIndicesT(tensor.get(0), set);
        } else {
            Tensor t;
            for (int i = tensor.size() - 1; i >= 0; --i) {
View Full Code Here


        //Processing data with indices
        int i;
        ProductContent content;
        Indices indices;
        Tensor[] data = dataContainer.list.toArray(new Tensor[dataContainer.list.size()]);
        if (dataContainer.count == 1) {
            content = dataContainer.content;
            indices = dataContainer.indices;
            if (indices == null) {
View Full Code Here

     * @return {@code true} if specified tensors are mathematically (not programming) equal
     */
    public static boolean equals(Tensor u, Tensor v) {
        if (u == v)
            return true;
        Indices freeIndices = u.getIndices().getFree();
        if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree()))
            return false;
        int[] free = freeIndices.getAllIndices().copy();
        IndexMappingBuffer tester = new IndexMappingBufferTester(free, false);
        OutputPortUnsafe<IndexMappingBuffer> mp = IndexMappings.createPortOfBuffers(tester, u, v);
        IndexMappingBuffer buffer;

        while ((buffer = mp.take()) != null)
View Full Code Here

     * @param v tensor
     * @return {@code true} {@code true} if tensor u mathematically (not programming) equals to tensor v,
     *         {@code false} if they they differ only in the sign and {@code null} otherwise
     */
    public static Boolean compare1(Tensor u, Tensor v) {
        Indices freeIndices = u.getIndices().getFree();
        if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree()))
            return null;
        int[] free = freeIndices.getAllIndices().copy();
        IndexMappingBuffer tester = new IndexMappingBufferTester(free, false);
        IndexMappingBuffer buffer = IndexMappings.createPortOfBuffers(tester, u, v).take();
        if (buffer == null)
            return null;
        return buffer.getSign();
View Full Code Here

        }

        int tensorIndex;
        for (tensorIndex = 0; tensorIndex < data.length; ++tensorIndex) {
            //Main algorithm
            Indices tInds = data[tensorIndex].getIndices();
            short[] diffIds = tInds.getDiffIds();
            for (i = 0; i < tInds.size(); ++i) {
                index = tInds.get(i);
                state = IndicesUtils.getStateInt(index);
                info[state][pointer[state]] = packToLong(tensorIndex, stretchIndices[tensorIndex], diffIds[i]);
                indices[state][pointer[state]++] = IndicesUtils.getNameWithType(index);
            }

            //Result allocation
            contractions[tensorIndex] = new TensorContraction(stretchIndices[tensorIndex], new long[tInds.size()]);
        }

        //Here we can use unstable sorting algorithm (all indices are different)
        ArraysUtils.quickSort(indices[0], info[0]);
        ArraysUtils.quickSort(indices[1], info[1]);
View Full Code Here

            if (sp.getName() != var.getName())
                return null;
            if (sp.getIndices().size() == 0)
                return TensorNumber.createONE();
            Product kroneckers = new Product();
            Indices targetIndices = sp.getIndices();
            Indices varIndices = var.getIndices();
            for (int i = 0; i < sp.getIndices().size(); ++i)
                kroneckers.add(CC.createMetricOrKronecker(targetIndices.get(i), varIndices.get(i)));
            return kroneckers.equivalent();
        } else if (target.getClass() == TensorField.class) {
            TensorField field = (TensorField) target;
            Tensor[] args = field.getArgs();
            for (int i = 0; i < args.length; ++i)
View Full Code Here

TOP

Related Classes of cc.redberry.core.indices.Indices

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.