Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.Indices


    private void testConsistent() {
        boolean isSymbol = (indices instanceof EmptyIndices);
        boolean b = true;
        for (Tensor t : this) {
            Indices ind = t.getIndices().getFreeIndices();
            if (!indices.equalsIgnoreOrder(ind))
                b = false;
            // Take care if sum e.g. a+h^i_i that indices will not be EmptyIndices (sum is not symbol)
            if (isSymbol && !(ind instanceof EmptyIndices)) {
                isSymbol = false;
View Full Code Here


        }

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

            //TODO 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

        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();
                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

            if (ps.getGraphType() != GraphType.Line)
                continue;
            int[] partition = ps.getPartition();

            Tensor left = null, right = null;
            Indices leftIndices = null, rightIndices = null;
            Indices leftSubIndices = null, rightSubIndices = null;
            int leftUpperCount, leftLowerCount, rightUpperCount, rightLowerCount, luCount = -1;
            boolean leftSkip = false, rightSkip = false, leftMatrix = false, rightMatrix = false;

            for (int leftPointer = 0, rightPointer = partition.length - 1;
                 leftPointer < rightPointer; ++leftPointer, --rightPointer) {

                if (!leftSkip) {
                    left = data[partition[leftPointer]];

                    leftIndices = left.getIndices();
                    leftSubIndices = leftIndices.getOfType(type);

                    leftUpperCount = leftSubIndices.getUpper().length();
                    leftLowerCount = leftSubIndices.getLower().length();

                    if (leftUpperCount != leftLowerCount) {
                        if (leftLowerCount != 0 && leftUpperCount != 0)
                            throw new IllegalArgumentException("Not a product of matrices.");
                        leftMatrix = false;
View Full Code Here

        return set;
    }

    public static void appendAllIndicesNamesT(Tensor tensor, TIntHashSet set) {
        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)
            return;
        else {
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);
        MappingsPort mp = IndexMappings.createPort(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.createPort(tester, u, v).take();
        if (buffer == null)
            return null;
        return buffer.getSign();
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

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.