@Override public SimpleIndices getInverted() { int[] dataInv = new int[data.length]; for (int i = 0; i < data.length; ++i) dataInv[i] = data[i] ^ 0x80000000; return create(dataInv, symmetries); }
/** * Construct {@code SimpleIndicesOfTensor} instance from specified indices * array and with specified symmetries. * * @param data array of indices * @param symmetries symmetries of this indices */ AbstractSimpleIndices(int[] data, IndicesSymmetries symmetries) { super(data); assert data.length != 0; int[] toSort = new int[data.length]; for (int i = 0; i < data.length; ++i) toSort[i] = data[i] & 0x7F000000; ArraysUtils.stableSort(toSort, data); this.symmetries = symmetries; testConsistentWithException(); }
@Override public SimpleIndices getUpper() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.upper.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.upper, new UpperLowerIndices(ul.upper, new int[0])); }
@Override public boolean equalsWithSymmetries(SimpleIndices indices) { if (indices.getClass() != this.getClass()) return false; if (data.length != indices.size()) return false; int[] permutation = new int[data.length]; out: for (int i = 0; i < data.length; ++i) { int from = data[i]; for (int j = 0; j < data.length; ++j) if (indices.get(j) == from) { permutation[j] = i; continue out; } return false; } if (!Permutations.testPermutationCorrectness(permutation)) return false; return this.getSymmetries().getPermutationGroup().membershipTest( Permutations.createPermutation(permutation)); }
@Override public SimpleIndices getLower() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.lower.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.lower, new UpperLowerIndices(new int[0], ul.lower)); }
@Override public SimpleIndices applyIndexMapping(IndexMapping mapping) { boolean changed = false; int newIndex; int[] data_ = data.clone(); for (int i = 0; i < data.length; ++i) if (data_[i] != (newIndex = mapping.map(data_[i]))) { data_[i] = newIndex; changed = true; } if (!changed) return this; SimpleIndices si = create(data_, symmetries); //FUTURE we really need this check? si.testConsistentWithException(); return si; }