Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.Indices


                assertIndicesConsistency(c, new HashSet<>(indices));
    }

    private static void appendAllIndices(Tensor t, Set<Integer> set) {
        if (t instanceof SimpleTensor) {
            Indices ind = t.getIndices();
            for (int i = ind.size() - 1; i >= 0; --i)
                set.add(ind.get(i));
        } else
            for (Tensor c : t)
                if (c instanceof ScalarFunction)
                    continue;
                else
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

    public static Tensor symmetrizeUpperLowerIndices(Tensor tensor) {
        return symmetrizeUpperLowerIndices(tensor, false);
    }

    public static Tensor symmetrizeUpperLowerIndices(Tensor tensor, boolean multiplyOnSymmetryFactor) {
        Indices indices = IndicesFactory.create(tensor.getIndices().getFree());
        int[] indicesArray = indices.getAllIndices().copy();
        Symmetries symmetries = TensorUtils.getIndicesSymmetriesForIndicesWithSameStates(indicesArray, tensor);
        int lowerCount = indices.getLower().length(), upperCount = indices.getUpper().length();

        IntPermutationsGenerator lowIndicesPermutationsGenerator,
                upperIndicesPermutationGenerator;
        SumBuilder sumBuilder = new SumBuilder();
        Tensor summand;
View Full Code Here

        } else
            putNonScalar(tensor);
    }

    private void putNonScalar(Tensor tensor) {
        Indices freeIndices = tensor.getIndices().getFree();
        TIntHashSet freeSet = new TIntHashSet(freeIndices.getAllIndices().copy());

        // Firstly we should check whether adding
        // specified tensor will merge some of the
        // existing components,
        // e.g. if component1 = F_mn*A^n
 
View Full Code Here

        assert pivot >= 0;

        final int[] links = {NOT_INITIALIZED, NOT_INITIALIZED};
        final long[] contractions = fcs.contractions[pivot];
        Indices indices = pc.get(pivot).getIndices();
        int index, toTensorIndex;
        for (int i = contractions.length - 1; i >= 0; --i) {
            index = indices.get(i);

            if (getType(index) != type.getType())
                continue;

            toTensorIndex = getToTensorIndex(contractions[i]);
View Full Code Here

    private TensorGeneratorUtils() {
    }

    public static Tensor[] allStatesCombinations(Tensor st) {

        Indices indices = st.getIndices().getFree();
        int[] indicesArray = indices.getAllIndices().copy();
        //lowering all indices
        IntArrayList metricIndices = new IntArrayList(),
                nonMetricIndices = new IntArrayList();

        for (int i = 0; i < indices.size(); ++i) {
            if (CC.isMetric(getType(indices.get(i))))
                metricIndices.add(getNameWithType(indices.get(i)));
            else
                nonMetricIndices.add(indices.get(i));
        }


        final int[] metricInds = metricIndices.toArray();
        ArrayList<Tensor> samples = new ArrayList<>(ArithmeticUtils.pow(2, metricInds.length));
View Full Code Here

        IntArrayList stack = new IntArrayList();
        stack.push(pivot);
        used.set(pivot);

        long[] contractions;
        Indices indices;

        int currentPivot, index, toTensorIndex;
        while (!stack.isEmpty()) {

            currentPivot = stack.pop();

            indices = pc.get(currentPivot).getIndices();
            contractions = fcs.contractions[currentPivot];
            for (int i = contractions.length - 1; i >= 0; --i) {
                index = indices.get(i);
                if (getType(index) != type.getType())
                    continue;

                toTensorIndex = getToTensorIndex(contractions[i]);
                if (toTensorIndex == -1 || used.get(toTensorIndex))
View Full Code Here

    private ProductContent calculateContent() {
        if (data.length == 0) {
            contentReference.resetReferent(ProductContent.EMPTY_INSTANCE);
            return ProductContent.EMPTY_INSTANCE;
        }
        final Indices freeIndices = indices.getFree();
        final int differentIndicesCount = (getIndices().size() + freeIndices.size()) / 2;

        //Names (names with type, see IndicesUtils.getNameWithType() ) of all indices in this multiplication
        //It will be used as index name -> index index [0,1,2,3...] mapping
        final int[] upperIndices = new int[differentIndicesCount], lowerIndices = new int[differentIndicesCount];
        //This is sorage for intermediate information about indices, used in the algorithm (see below)
        //Structure:
        //
        final long[] upperInfo = new long[differentIndicesCount], lowerInfo = new long[differentIndicesCount];

        //This is for generalization of algorithm
        //indices[0] == lowerIndices
        //indices[1] == lowerIndices
        final int[][] indices = new int[][]{lowerIndices, upperIndices};

        //This is for generalization of algorithm too
        //info[0] == lowerInfo
        //info[1] == lowerInfo
        final long[][] info = new long[][]{lowerInfo, upperInfo};

        //Pointers for lower and upper indices, used in algorithm
        //pointer[0] - pointer to lower
        //pointer[1] - pointer to upper
        final int[] pointer = new int[2];
        final short[] stretchIndices = calculateStretchIndices(); //for performance

        //Allocating array for results, one contraction for each tensor
        final TensorContraction[] contractions = new TensorContraction[data.length];
        //There is one dummy tensor with index -1, it represents fake
        //tensor contracting with whole Product to leave no contracting indices.
        //So, all "conractions" with this dummy "contraction" looks like a scalar
        //product. (sorry for English)
        final TensorContraction freeContraction = new TensorContraction((short) -1, new long[freeIndices.size()]);

        int state, index, i;

        //Processing free indices = creating contractions for dummy tensor
        for (i = 0; i < freeIndices.size(); ++i) {
            index = freeIndices.get(i);
            //Inverse state (because it is state of index at (??) dummy tensor,
            //contracted with this free index)
            state = 1 - IndicesUtils.getStateInt(index);
            //Important:
            info[state][pointer[state]] = dummyTensorInfo;
            indices[state][pointer[state]++] = IndicesUtils.getNameWithType(index);
        }

        int tensorIndex;
        for (tensorIndex = 0; tensorIndex < data.length; ++tensorIndex) {
            //Main algorithm
            Indices tInds = data[tensorIndex].getIndices();
            short[] diffIds = tInds.getDiffIds();
            for (i = 0; i < tInds.size(); ++i) {
                index = tInds.get(i);
                state = IndicesUtils.getStateInt(index);
                info[state][pointer[state]] = packToLong(tensorIndex, stretchIndices[tensorIndex], diffIds[i]);
                indices[state][pointer[state]++] = IndicesUtils.getNameWithType(index);
            }

            //Result allocation
            contractions[tensorIndex] = new TensorContraction(stretchIndices[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

    //            this.stretchIndices = stretchIndices;
    //        }
    //    }

    private static int hc(Tensor t, int[] inds) {
        Indices ind = t.getIndices().getFree();
        int h = 31;
        int ii;
        for (int i = ind.size() - 1; i >= 0; --i) {
            ii = IndicesUtils.getNameWithType(ind.get(i));
            if ((ii = Arrays.binarySearch(inds, ii)) >= 0)
                h ^= HashFunctions.JenkinWang32shift(ii);
        }
        return h;
    }
View Full Code Here

        return s;
    }

    private static void getAllIndices1(ParseToken node, Set<Integer> set) {
        if (node instanceof ParseTokenSimpleTensor) {
            Indices indices = node.getIndices();
            for (int i = indices.size() - 1; i >= 0; --i)
                set.add(IndicesUtils.getNameWithType(indices.get(i)));
        } else
            for (ParseToken pn : node.content)
                if (!(pn instanceof ParseTokenScalarFunction))
                    getAllIndices1(pn, set);
    }
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.