/** * Tests whether specified mapping is a mapping from <i>{@code from}</i> tensor onto <i>{@code to}</i> tensor. * * @param mapping mapping * @param from tensor <i>{@code from}</i> * @param to tensor <i>{@code to}</i> * @return {@code true} if specified mapping is a mapping from <i>{@code from}</i> tensor onto * <i>{@code to}</i> tensor and {@code false} in other case. */ public static boolean testMapping(Mapping mapping, Tensor from, Tensor to) { return IndexMappingBufferTester.test(new IndexMappingBufferTester(mapping), from, to); }
@Override public IndexMappingBufferTester clone() { return new IndexMappingBufferTester(innerBuffer.clone(), from, to, signum); }
@Override public IndexMappingBuffer take() { OUTER: while (true) { final IndexMappingBuffer buffer = mainProvider.take(); if (buffer == null) return null; buffer.removeContracted(); //buffer.addSignum(cache.lastReturned.sign); final IndexMappingBufferTester tester = new IndexMappingBufferTester(buffer.export().mergeWith(cache.lastReturned)); for (Tester t : testers) if (!t.test(tester)) continue OUTER; //buffer.addSignum(cache.lastReturned.sign); return buffer; } }
/** * Returns {@code true} if specified tensor is zero in consequence of its symmetries: is both symmetric and * asymmetric with respect to some permutation at the same time. * * @param t tensor * @return {@code true} if specified tensor is zero in consequence of its symmetries */ public static boolean isZeroDueToSymmetry(Tensor t) { int[] indices = IndicesUtils.getIndicesNames(t.getIndices().getFree()); IndexMappingBufferTester bufferTester = new IndexMappingBufferTester(indices, false); OutputPort<IndexMappingBuffer> mp = IndexMappings.createPortOfBuffers(bufferTester, t, t); IndexMappingBuffer buffer; while ((buffer = mp.take()) != null) if (buffer.getSign()) return true; return false; }
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v, * {@code false} if they they differ only in the sign and {@code null} otherwise. * * @param u tensor * @param v tensor * @return {@code true} {@code false} if tensor u mathematically (not programming) equals to tensor v, * {@code true} if they they differ only in the sign and {@code null} otherwise */ public static Boolean compare1(Tensor u, Tensor v) { Indices freeIndices = u.getIndices().getFree(); if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree())) return null; int[] free = freeIndices.getAllIndices().copy(); IndexMappingBuffer tester = new IndexMappingBufferTester(free, false); IndexMappingBuffer buffer = IndexMappings.createPortOfBuffers(tester, u, v).take(); if (buffer == null) return null; return buffer.getSign(); }
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v. * * @param u tensor * @param v tensor * @return {@code true} if specified tensors are mathematically (not programming) equal */ public static boolean equals(Tensor u, Tensor v) { if (u == v) return true; Indices freeIndices = u.getIndices().getFree(); if (!freeIndices.equalsRegardlessOrder(v.getIndices().getFree())) return false; int[] free = freeIndices.getAllIndices().copy(); IndexMappingBuffer tester = new IndexMappingBufferTester(free, false); OutputPort<IndexMappingBuffer> mp = IndexMappings.createPortOfBuffers(tester, u, v); IndexMappingBuffer buffer; while ((buffer = mp.take()) != null) if (!buffer.getSign()) return true; return false; }