Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.SimpleIndices


    }

    private static Tensor applyIndexMapping(Tensor tensor, IndexMapper indexMapper, boolean contractIndices) {
        if (tensor instanceof SimpleTensor) {
            SimpleTensor simpleTensor = (SimpleTensor) tensor;
            SimpleIndices oldIndices = simpleTensor.getIndices(),
                    newIndices = oldIndices.applyIndexMapping(indexMapper);
            if (oldIndices == newIndices)
                return tensor;
            if (tensor instanceof TensorField) {
                TensorField field = (TensorField) simpleTensor;
                return Tensors.field(field.name, newIndices, field.argIndices, field.args);
View Full Code Here


    @Override
    public IndexMappingBuffer take() {
        if (currentBuffer == null)
            return null;

        SimpleIndices fromIndices = from.getIndices();
        SimpleIndices toIndices = to.getIndices();
        int size = fromIndices.size();
        if (size == 0) {
            IndexMappingBuffer r = currentBuffer;
            currentBuffer = null;
            return r;
        }

        if (symmetryIterator != null) {
            OUT:
            while (symmetryIterator.hasNext()) {
                Symmetry s = symmetryIterator.next();
                IndexMappingBuffer tempBuffer = currentBuffer.clone();
                for (int i = 0; i < size; ++i)
                    if (!tempBuffer.tryMap(fromIndices.get(s.newIndexOf(i)), toIndices.get(i)))
                        continue OUT;
                tempBuffer.addSign(s.isAntiSymmetry());
                return tempBuffer;
            }
            symmetryIterator = null;
            currentBuffer = null;
            return null;
        }
        if (fromIndices.getSymmetries().isEmpty()) {
            IndexMappingBuffer tempBuffer = currentBuffer;
            for (int i = 0; i < size; ++i)
                if (!tempBuffer.tryMap(fromIndices.get(i), toIndices.get(i))) {
                    currentBuffer = null;
                    return null;
                }
            currentBuffer = null;
            return tempBuffer;
View Full Code Here

            this.node = node;
        }

        @Override
        public void apply(IndexMapper indexMapper, IGWrapper generator, int[] upper, int[] lower) {
            SimpleIndices oldIndices = node.indices;
            int[] _newIndices = new int[oldIndices.size() + 2 * upper.length];
            int i;
            for (i = 0; i < oldIndices.size(); ++i)
                _newIndices[i] = indexMapper.map(oldIndices.get(i));
            System.arraycopy(upper, 0, _newIndices, oldIndices.size(), upper.length);
            System.arraycopy(lower, 0, _newIndices, oldIndices.size() + upper.length, lower.length);
            for (i = 0; i < upper.length; ++i)
                _newIndices[i + oldIndices.size()] |= 0x80000000;
            node.indices = IndicesFactory.createSimple(null, _newIndices);
        }
View Full Code Here

        List<Indices> indices = new ArrayList<>();

        int beginIndex = 0, level = 0;
        char[] argsChars = argString.toCharArray();
        ParseToken a;
        SimpleIndices aIndices;
        for (int i = 0; i < argsChars.length; ++i) {
            char c = argsChars[i];

            if ((c == ',' && level == 0) || i == argsChars.length - 1) {
                String argument = argString.substring(beginIndex, i == argsChars.length - 1 ? i + 1 : i);
View Full Code Here

                return res;
            return Integer.compare(indices[1], o.indices[1]);
        }

        SimpleTensor apply(SimpleTensor t) {
            SimpleIndices oldIndices = t.getIndices();
            int from = -1, to = -1;
            OUTER:
            for (int i = 0; i < oldIndices.size(); ++i)
                for (int j = 0; j < 2; ++j)
                    if ((oldIndices.get(i) ^ indices[j])
                            == 0x80000000) {
                        from = oldIndices.get(i);
                        to = indices[1 - j];
                        break OUTER;
                    }
            IM im = new IM(from, to);
            SimpleIndices newIndices = oldIndices.applyIndexMapping(im);
            if (oldIndices == newIndices)
                return t;
            return Tensors.simpleTensor(t.getName(), newIndices);
        }
View Full Code Here

    private TensorHashCalculator() {
    }

    private static int _hashWithIndices(final Tensor tensor, final int[] indices) {
        if (tensor instanceof SimpleTensor) {
            SimpleIndices si = ((SimpleTensor) tensor).getIndices();
            short[] sInds = si.getDiffIds();
            int hash = tensor.hashCode();
            int pos;
            for (int i = 0; i < si.size(); ++i)
                if ((pos = Arrays.binarySearch(indices, si.get(i))) >= 0)
                    hash += (HashFunctions.JenkinWang32shift(sInds[i])
                            * HashFunctions.JenkinWang32shift(pos) * 7);
            return HashFunctions.JenkinWang32shift(hash);
        }
        if (tensor instanceof ScalarFunction)
View Full Code Here

        List<Indices> indices = new ArrayList<>();

        int beginIndex = 0, level = 0;
        char[] argsChars = argString.toCharArray();
        ParseNode a;
        SimpleIndices aIndices;
        for (int i = 0; i < argsChars.length; ++i) {
            char c = argsChars[i];

            if ((c == ',' && level == 0) || i == argsChars.length - 1) {
                String argument = argString.substring(beginIndex, i == argsChars.length - 1 ? i + 1 : i);
View Full Code Here

            this.node = node;
        }

        @Override
        public void apply(IndexMapper indexMapper, IGWrapper generator, int[] upper, int[] lower) {
            SimpleIndices oldIndices = node.indices;
            int[] _newIndices = new int[oldIndices.size() + 2 * upper.length];
            int i;
            for (i = 0; i < oldIndices.size(); ++i)
                _newIndices[i] = indexMapper.map(oldIndices.get(i));
            System.arraycopy(upper, 0, _newIndices, oldIndices.size(), upper.length);
            System.arraycopy(lower, 0, _newIndices, oldIndices.size() + upper.length, lower.length);
            for (i = 0; i < upper.length; ++i)
                _newIndices[i + oldIndices.size()] |= 0x80000000;
            node.indices = IndicesFactory.createSimple(null, _newIndices);
        }
View Full Code Here

    @Override
    public IndexMappingBuffer take() {
        if (currentBuffer == null)
            return null;

        SimpleIndices fromIndices = from.getIndices();
        SimpleIndices toIndices = to.getIndices();
        int size = fromIndices.size();
        if (size == 0) {
            IndexMappingBuffer r = currentBuffer;
            currentBuffer = null;
            return r;
        }

        if (symmetryIterator != null) {
            OUT:
            while (symmetryIterator.hasNext()) {
                Symmetry s = symmetryIterator.next();
                IndexMappingBuffer tempBuffer = currentBuffer.clone();
                for (int i = 0; i < size; ++i)
                    if (!tempBuffer.tryMap(fromIndices.get(s.newIndexOf(i)), toIndices.get(i)))
                        continue OUT;
                tempBuffer.addSignum(s.isAntiSymmetry());
                return tempBuffer;
            }
            symmetryIterator = null;
            currentBuffer = null;
            return null;
        }
        if (fromIndices.getSymmetries().isEmpty()) {
            IndexMappingBuffer tempBuffer = currentBuffer;
            for (int i = 0; i < size; ++i)
                if (!tempBuffer.tryMap(fromIndices.get(i), toIndices.get(i))) {
                    currentBuffer = null;
                    return null;
                }
            currentBuffer = null;
            return tempBuffer;
View Full Code Here

        }
        if (level != 0)
            throw new BracketsError();
        if (indexMode)
            ParserIndices.parseIndices(indicesList, indicesString, indexState);
        SimpleIndices indices = IndicesFactory.createSimple(null, indicesList.toArray());
        String name = nameBuilder.toString();
        return new ParseNodeSimpleTensor(indices, name);
    }
View Full Code Here

TOP

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

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.