@Override public TensorBuilder getBuilder() { TensorBuilder builder = new ComplexSumBuilder(); builder.put(summand); return builder; } }
public PrimitiveProductSubstitution(Tensor from, Tensor to) { super(from, to); Product product = (Product) from; this.fromFactor = product.getFactor(); this.fromIndexless = product.getIndexless(); this.fromContent = product.getContent(); this.fromData = fromContent.getDataCopy(); }
private static Tensor multiplyWithBuilder(Sum sum, Tensor factor, Transformation... transformations) { SumBuilder sb = new SumBuilder(sum.size()); for (Tensor t : sum) sb.put(Transformation.Util.applySequentially(multiply(t, factor), transformations)); return sb.build(); }
private int calculateHash() { int result; if (factor == Complex.ONE || factor == Complex.MINUS_ONE) result = 0; //important for -a.hash() == a.hash() else result = factor.hashCode(); for (Tensor t : indexlessData) result = result * 31 + t.hashCode(); for (Tensor t : data) result = result * 17 + t.hashCode(); if (factor == Complex.MINUS_ONE && size() == 2) return result; return result - 79 * getContent().getStructureOfContractionsHashed().hashCode(); }
/** * Multiplies each element in specified sum on some factor. * * @param sum sum * @param factor factor * @return resulting sum */ public static Tensor multiplySumElementsOnFactorAndResolveDummies(Sum sum, Tensor factor) { Tensor[] pair = resolveDummy(sum, factor); int i = pair[0] instanceof Sum ? 0 : 1; return multiplySumElementsOnFactor((Sum) pair[i], pair[1 - i], new Transformation[0]); }
@Override public Tensor create(Tensor... tensors) { if (tensors.length == 0) return Complex.ZERO; if (tensors.length == 1) return tensors[0]; TensorBuilder builder = new SumBuilder(tensors.length); for (Tensor t : tensors) builder.put(t); return builder.build(); } }
private static Tensor renameDummyWithSign(Tensor tensor, int[] forbidden, boolean sign) { Tensor result = renameDummy(tensor, forbidden); return sign ? Tensors.negate(result) : result; }
/** * Returns a kind of sum builder. * * @return a kind of sum builder */ public TensorBuilder getBuilder() { TensorBuilder builder = new SumBuilder(); builder.put(summand); return builder; }
/** * Makes simple tensor antisymmetric. * * @param tensor string representation of simple tensor * @throws java.lang.IllegalStateException if this tensor is already in use (it's permutation group calculated) */ public static void setAntiSymmetric(String tensor) { setAntiSymmetric(parseSimple(tensor)); }
@Override public FactorNode clone() { //factorForbiddenIndices are immutable return new FactorNode(factor, builder.clone(), factorForbiddenIndices); } }
/** * Returns reciprocal of the specified tensor, i.e. one divided by it. * * @param tensor tensor * @return reciprocal of the specified tensor * @throws IllegalArgumentException if specified tensor is not scalar */ public static Tensor reciprocal(Tensor tensor) { return pow(tensor, Complex.MINUS_ONE); }
@Override public Tensor create(Tensor... tensors) { checkWithException(tensors); return power(tensors[0], tensors[1]); }
/** * Applies specified mapping of indices to tensor. * * @param tensor tensor * @param mapping mapping of indices * @return tensor with renamed indices */ public static Tensor applyIndexMapping(Tensor tensor, Mapping mapping) { return applyIndexMapping(tensor, mapping, new int[0]); }
static boolean includes(int[] l, int[] s) { if (s.length > l.length) return includes(s, l); int p = 0; for (int v : s) { while (p < l.length && l[p] != v) ++p; if (p == l.length) return false; } return true; }
public boolean containsFreeIndex() { for (long contraction : indexContractions) if (getToTensorId(contraction) == -1) return true; return false; }
@Override public Tensor transform(Tensor t) { return optimizeDummies(t); } });