Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.SimpleIndices


        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


                if (matrixTypes.isEmpty())
                    return toString0(mode);

                List<IndexType> traces = new ArrayList<>();
                for (IndexType type : matrixTypes) {
                    SimpleIndices ofType = indices.getOfType(type);
                    if (ofType.getFree().size() == 0) {
                        //trace
                        traces.add(type);
                    }
                }
                if (traces.size() != 0) {
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.getPositionsInOrbits();
            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

        String name = expression.substring(0, indicesBegin);
        if (name.isEmpty())
            throw new ParserException("Simple tensor with empty name.");

        SimpleIndices indices = ParserIndices.parseSimple(expression.substring(indicesBegin));
        return new ParseTokenSimpleTensor(indices, name);
    }
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

            //now we need to uncontract dummies and free

            Indices factorIndices = new IndicesBuilder().append(factors).getIndices();
            TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections(
                    factorIndices.getUpper().copy(), factorIndices.getLower().copy()));
            SimpleIndices currentFactorIndices;
            IntArrayList from = new IntArrayList(), to = new IntArrayList();
            ArrayList<Tensor> kroneckers = new ArrayList<>();
            int j, index, newIndex;
            IndexGenerator generator = new IndexGenerator(TensorUtils.getAllIndicesNamesT(tensor).toArray());
            for (int i = 0; i < factors.length; ++i) {
                from.clear();
                to.clear();
                currentFactorIndices = factors[i].getIndices();

                for (j = currentFactorIndices.size() - 1; j >= 0; --j) {
                    index = currentFactorIndices.get(j);
                    if (freeIndices.contains(getNameWithType(index))) {
                        newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                        from.add(index);
                        to.add(newIndex);
                        kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
View Full Code Here

                if (!IndexMappings.positiveMappingExists(a.get(i), b.get(i))) return false;
        return true;
    }

    private static SimpleTensor applyDirectMapping(SimpleTensor st, DirectIndexMapping mapping) {
        SimpleIndices newIndices = st.getIndices().applyIndexMapping(mapping);
        if (st instanceof TensorField)
            return Tensors.field(st.getName(), newIndices, ((TensorField) st).getArgIndices(), ((TensorField) st).getArguments());
        else
            return Tensors.simpleTensor(st.getName(), newIndices);
    }
View Full Code Here

            if ((length = from.length) != to.length)
                return null;
            Arrays.sort(from, IndicesComparator.INSTANCE);
            Arrays.sort(to, IndicesComparator.INSTANCE);
            final Transformation[] subs = new Transformation[length];
            SimpleIndices fromIndices, toIndices;
            for (int i = 0; i < length; ++i) {

                if (!(fromIndices = from[i].getIndices()).similarTypeStructure((toIndices = to[i].getIndices())))
                    return null;
                final IndexMappingDirect im = new IndexMappingDirect(fromIndices, toIndices);
View Full Code Here

        private static class IndicesComparator implements Comparator<SimpleTensor> {
            static IndicesComparator INSTANCE = new IndicesComparator();

            @Override
            public int compare(final SimpleTensor o1, final SimpleTensor o2) {
                final SimpleIndices i1 = o1.getIndices(), i2 = o2.getIndices();
                if (i1.size() < i2.size())
                    return -1;
                if (i1.size() > i2.size())
                    return 1;
                final IndicesTypeStructure s1 = new IndicesTypeStructure(i1), s2 = new IndicesTypeStructure(i2);
                return Integer.compare(s1.hashCode(), s2.hashCode());
            }
View Full Code Here

            if ((c == ',' && level == 0) || i == argsChars.length - 1) {
                String argument = argString.substring(beginIndex, i == argsChars.length - 1 ? i + 1 : i);
                String[] split = argument.split(":");
                if (split.length == 1) {
                    Tensor a = parser.parse(argument);
                    SimpleIndices aIndices = IndicesFactory.createSimple(a.getIndices().getFreeIndices());
                    argsList.add(a);
                    argIndices.add(aIndices);
                } else {
                    if (split.length != 2)
                        throw new ParserException(expression);
                    Tensor a = parser.parse(split[0]);
                    SimpleIndices aIndices = ParserIndices.parse(split[1]);
                    argsList.add(a);
                    argIndices.add(aIndices);
                    //TODO add assertion on indices compatability
                }
                beginIndex = i + 1;
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.