private AbstractIterationStrategyNode nodeForElement(Element e) { AbstractIterationStrategyNode node = null; String eName = e.getName(); if (eName.equals("dot")) node = new DotProduct(); else if (eName.equals("cross")) node = new CrossProduct(); else if (eName.equals("prefix")) node = new PrefixDotProduct(); else if (eName.equals("port")) { NamedInputPortNode nipn = new NamedInputPortNode( e.getAttributeValue("name"), Integer.parseInt(e .getAttributeValue("depth"))); node = nipn; addInput(nipn); } for (Object child : e.getChildren()) nodeForElement((Element) child).setParent(node); return node; }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same if (isLeaf()) // No children! throw new IterationTypeMismatchException("Dot product with no children"); int depth = getChildAt(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) if (childNode.getIterationDepth(inputDepths) != depth) throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); return depth; } }
@Override public synchronized void innerReceiveJob(int inputIndex, Job newJob) { if (getChildCount() == 1) { pushJob(newJob); return; TreeCache[] caches = new TreeCache[getChildCount()]; for (int i = 0; i < getChildCount(); i++) caches[i] = new TreeCache(); ownerToCache.put(owningProcess, caches); pushJob(j);
private IterationStrategyImpl getISDot(int depthA, int depthB) { IterationStrategyImpl is1 = new IterationStrategyImpl(); NamedInputPortNode nipn1 = new NamedInputPortNode("a", depthA); NamedInputPortNode nipn2 = new NamedInputPortNode("b", depthB); is1.addInput(nipn1); is1.addInput(nipn2); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); dp.setParent(is1.getTerminalNode()); return is1; }
@Test public void cantAddSelf() throws Exception { dotProduct1.setParent(crossProduct1); try { dotProduct1.insert(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
@Test public void cantSetSelfParent() throws Exception { crossProduct1.insert(dotProduct1); try { dotProduct1.setParent(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
@Before public void makeNodes() throws Exception { root = new DummyTerminalNode(); input1 = new NamedInputPortNode("input1", 1); input2 = new NamedInputPortNode("input2", 2); crossProduct1 = new CrossProduct(); crossProduct2 = new CrossProduct(); dotProduct1 = new DotProduct(); dotProduct2 = new DotProduct(); }