if (!inited) { for (int i = 0; i < providers.length; ++i) providers[i].tick(); inited = true; IndexMappingBuffer buffer = providers[i].take(); if (buffer != null) return buffer; while (true) { boolean r; while ((r = !(providers[i--].tick())) && i >= 0) ; if (i == -1 && r) return null; i += 2; for (; i < providers.length; ++i) if (!providers[i].tick()) { i--; continue OUTER; buffer = providers[i].take(); if (buffer != null) return buffer;
@Override public boolean tick() { return provider.tick(); } }
@Override public IndexMappingBuffer take() { IndexMappingBuffer buffer = provider.take(); if (buffer == null) return null; lastReturned = buffer.export(); return buffer; } }
@Override public boolean tick() { return mainProvider.tick(); }
@Override public IndexMappingBuffer take() { IndexMappingBuffer currentBuffer = provider.take(); if (currentBuffer == null) return null; currentBuffer.addSign(true); return currentBuffer; }
@Override public boolean tick() { return provider.tick(); }
@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; } }
/** * Tests whether specified {@link IndexMappingBufferTester} is a real mapping of tensor {@code from} * on tensor {@code to}. * * @param tester tester of mappings * @param from from tensor * @param to to tensor * @return {@code true} if there is mapping of tensor {@code from} on tensor {@code to} equal * to specified mapping */ public static boolean test(IndexMappingBufferTester tester, Tensor from, Tensor to) { tester.reset(); final IndexMappingProvider provider = IndexMappings.createPort(IndexMappingProvider.Util.singleton(tester), from, to); provider.tick(); IndexMappingBuffer buffer; while ((buffer = provider.take()) != null) if (!buffer.getSign()) return true; return false; }
/** * Creates output port of mappings of tensor {@code from} on tensor {@code to} with specified * mappings rules defined in specified {@link IndexMappingBuffer}. * * @param buffer initial mapping rules * @param from from tensor * @param to to tensor * @return output port of mapping */ static OutputPort<IndexMappingBuffer> createPortOfBuffers(final IndexMappingBuffer buffer, final Tensor from, final Tensor to) { final IndexMappingProvider provider = createPort(IndexMappingProvider.Util.singleton(buffer), from, to); provider.tick(); return new MappingsPortRemovingContracted(provider); }
/** * Creates output port of mappings of two simple tensors and does not take into account the arguments of fields. * * @param from from tensor * @param to to tensor * @return port of mappings of indices */ public static MappingsPort simpleTensorsPort(SimpleTensor from, SimpleTensor to) { final IndexMappingProvider provider = ProviderSimpleTensor.FACTORY_SIMPLETENSOR.create(IndexMappingProvider.Util.singleton(new IndexMappingBufferImpl()), from, to); provider.tick(); return new MappingsPort(new MappingsPortRemovingContracted(provider)); }