Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.SimpleIndices


* @author Stanislav Poslavsky
*/
public class 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);
        }
        int hash = tensor.hashCode();
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

        DFromTo derivative = derivatives.get(orders);
        if (derivative == null) {
            int order, j;
            SimpleTensor var;
            int[] indices;
            SimpleIndices varIndices;
            TensorField __from = (TensorField) this.from;
            Tensor __to = this.to;
            IndexGenerator ig = null;
            for (int i = orders.length() - 1; i >= 0; --i) {
                order = orders.get(i) - this.orders.get(i);
                while (order > 0) {
                    var = (SimpleTensor) from.get(i);
                    indices = new int[var.getIndices().size()];

                    //lazy initialization
                    if (indices.length != 0 && ig == null) {
                        TIntHashSet forbidden = new TIntHashSet(iterator.getForbidden());
                        forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.from));
                        forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.to));
                        ig = new IndexGenerator(forbidden.toArray());

                    }

                    for (j = indices.length - 1; j >= 0; --j)
                        indices[j] = setRawState(getRawStateInt(var.getIndices().get(j)),
                                ig.generate(getType(var.getIndices().get(j))));
                    varIndices = UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, indices);
                    var = Tensors.setIndices(var, varIndices);
                    __from = Tensors.fieldDerivative(__from, varIndices.getInverted(), i);
                    __to = new DifferentiateTransformation(var).transform(__to);
                    --order;
                }
            }
            derivative = new DFromTo(__from, __to);
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

            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;
            IndexGenerator indexGenerator = new IndexGenerator(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);
            Tensor derivative = SymmetrizeSimpleTensorTransformation.symmetrize(
                    symmetric,
                    allFreeVarIndices,
                    varIndices.getSymmetries().getInnerSymmetries());
View Full Code Here

    }

    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

    private static TIntObjectHashMap<ParseToken> cachedLeviCivitaSelfContractions = new TIntObjectHashMap<>();
    private static TIntObjectHashMap<Map<Permutation, 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

            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;
            IndexGenerator indexGenerator = new IndexGenerator(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);
            Tensor derivative = SymmetrizeSimpleTensorTransformation.symmetrize(
                    symmetric,
                    allFreeVarIndices,
                    varIndices.getSymmetries().getInnerSymmetries());
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;
            if (t.getClass() == SimpleTensor.class)
                return Tensors.simpleTensor(t.getName(), newIndices);
            TensorField ff = (TensorField) t;
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) * 37));
            return HashFunctions.JenkinWang32shift(hash);
        }
        if (tensor instanceof ScalarFunction)
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.