Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.SimpleIndices


    }

    public static Tensor applyIndexMapping(Tensor tensor, IndexMapper mapper) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(tensor, TraverseGuide.EXCEPT_FUNCTIONS_AND_FIELDS);
        TraverseState state;
        SimpleIndices oldIndices, newIndices;
        SimpleTensor simpleTensor;
        while ((state = iterator.next()) != null) {
            if (state == TraverseState.Leaving)
                continue;
            if (!(iterator.current() instanceof SimpleTensor))
                continue;
            simpleTensor = (SimpleTensor) iterator.current();
            oldIndices = simpleTensor.getIndices();
            newIndices = oldIndices.applyIndexMapping(mapper);
            if (oldIndices != newIndices)
                if (simpleTensor instanceof TensorField)
                    iterator.set(Tensors.setIndicesToField((TensorField) simpleTensor, newIndices));
                else
                    iterator.set(Tensors.setIndicesToSimpleTensor(simpleTensor, newIndices));
View Full Code Here


    }

    private static Tensor renameDummy(Tensor tensor, IndexMapper mapper) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(tensor);
        TraverseState state;
        SimpleIndices oldIndices, newIndices;
        SimpleTensor simpleTensor;
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Leaving)
                continue;

            if (!(iterator.current() instanceof SimpleTensor))
                continue;
            simpleTensor = (SimpleTensor) iterator.current();
            oldIndices = simpleTensor.getIndices();
            newIndices = oldIndices.applyIndexMapping(mapper);
            if (oldIndices != newIndices)
                if (simpleTensor instanceof TensorField)
                    iterator.set(Tensors.setIndicesToField((TensorField) simpleTensor, newIndices));
                else
                    iterator.set(Tensors.setIndicesToSimpleTensor(simpleTensor, 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.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

        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

            this.freeVarIndices = freeVarIndices;
        }

        SymmetricDifferentiationRule(SimpleTensor var) {
            super(var);
            SimpleIndices varIndices = var.getIndices();
            int[] allFreeVarIndices = new int[varIndices.size()];
            int[] allFreeArgIndices = new int[varIndices.size()];
            byte type;
            int state, i = 0, length = allFreeArgIndices.length;
            IndexGeneratorImpl indexGenerator = new IndexGeneratorImpl(varIndices);
            for (; i < length; ++i) {
                type = getType(varIndices.get(i));
                state = getRawStateInt(varIndices.get(i));
                allFreeVarIndices[i] = setRawState(indexGenerator.generate(type), inverseIndexState(state));
                allFreeArgIndices[i] = setRawState(indexGenerator.generate(type), state);
            }
            int[] allIndices = addAll(allFreeVarIndices, allFreeArgIndices);
            SimpleIndices dIndices = IndicesFactory.createSimple(null, allIndices);
            SimpleTensor symmetric = simpleTensor("@!@#@##_AS@23@@#", dIndices);
            SimpleIndices allFreeVarIndicesI = IndicesFactory.createSimple(varIndices.getSymmetries(), allFreeVarIndices);
            Tensor derivative =
                    new SymmetrizeTransformation(allFreeVarIndicesI, true).transform(symmetric);

            derivative = applyIndexMapping(
                    derivative,
View Full Code Here

    }

    private static Tensor applyIndexMapping(Tensor tensor, final 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

    private static TIntObjectHashMap<ParseToken> cachedLeviCivitaSelfContractions = new TIntObjectHashMap<>();
    private static TIntObjectHashMap<Map<IntArray, Boolean>> cachedLeviCivitaSymmetries = new TIntObjectHashMap<>();

    private static void checkLeviCivita(SimpleTensor LeviCivita) {
        SimpleIndices indices = LeviCivita.getIndices();
        if (indices.size() <= 1)
            throw new IllegalArgumentException("Levi-Civita cannot be a scalar.");
        byte type = getType(indices.get(0));
        for (int i = 1; i < indices.size(); ++i)
            if (type != getType(indices.get(i)))
                throw new IllegalArgumentException("Levi-Civita have indices with different types.");
    }
View Full Code Here

    private static TIntObjectHashMap<ParseToken> cachedLeviCivitaSelfContractions = new TIntObjectHashMap<>();
    private static TIntObjectHashMap<Map<IntArray, Boolean>> cachedLeviCivitaSymmetries = new TIntObjectHashMap<>();

    private static void checkLeviCivita(SimpleTensor LeviCivita) {
        SimpleIndices indices = LeviCivita.getIndices();
        if (indices.size() <= 1)
            throw new IllegalArgumentException("Levi-Civita cannot be a scalar.");
        byte type = getType(indices.get(0));
        for (int i = 1; i < indices.size(); ++i)
            if (type != getType(indices.get(i)))
                throw new IllegalArgumentException("Levi-Civita have indices with different types.");
    }
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.