/** * Connect up a new named input port node to the first child of the terminal * node. If the terminal node doesn't have any children then create a new * cross product node, connect it to the terminal and connect the new input * port node to the cross product (saneish default behaviour) * * @param nipn */ public synchronized void connectDefault(NamedInputPortNode nipn) { if (terminal.getChildCount() == 0) { CrossProduct cp = new CrossProduct(); cp.setParent(terminal); nipn.setParent(cp); } else { AbstractIterationStrategyNode node = (AbstractIterationStrategyNode) (terminal .getChildAt(0)); nipn.setParent(node); } }
if (!ownerToCache.containsKey(newJob.getOwningProcess())) { List<Set<Job>> perInputCache = new ArrayList<Set<Job>>(); for (int i = 0; i < getChildCount(); i++) { perInputCache.add(new HashSet<Job>()); workingSet.add(newJob); for (int i = 1; i < getChildCount(); i++) { Set<Job> thisSet = perInputCache.get(i); if (i == inputIndex) { thisSet.add(newJob); workingSet = merge(workingSet, thisSet); pushJob(outputJob);
public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { if (isLeaf()) { // No children! throw new IterationTypeMismatchException("Cross product with no children"); } int temp = 0; for (IterationStrategyNode child : getChildren()) { temp += child.getIterationDepth(inputDepths); } return temp; }
if (getChildCount() == 1) { pushJob(newJob); return; for (int i = 0; i < getChildCount(); i++) { perInputCache.add(new HashSet<Job>()); workingSet.add(newJob); for (int i = 1; i < getChildCount(); i++) { Set<Job> thisSet = perInputCache.get(i); if (i == inputIndex) { thisSet.add(newJob); workingSet = merge(workingSet, thisSet); pushJob(outputJob); if (canClearCache(inputIndex, newJob.getOwningProcess())) {
@Test public void addCrossProduct() throws Exception { assertNull(crossProduct1.getParent()); crossProduct1.setParent(root); assertEquals(root, crossProduct1.getParent()); assertEquals(1, root.getChildCount()); assertEquals(crossProduct1, root.getChildAt(0)); assertEquals(Arrays.asList(crossProduct1), root.getChildren()); assertEquals(0, crossProduct1.getChildCount()); crossProduct1.insert(input1); assertEquals(input1, crossProduct1.getChildAt(0)); crossProduct1.insert(input2, 0); assertEquals(input2, crossProduct1.getChildAt(0)); assertEquals(input1, crossProduct1.getChildAt(1)); assertEquals(2, crossProduct1.getChildCount()); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); // A re-insert should move it crossProduct1.insert(input2, 2); assertEquals(2, crossProduct1.getChildCount()); assertEquals(Arrays.asList(input1, input2), crossProduct1.getChildren()); crossProduct1.insert(input2, 0); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); crossProduct1.insert(input1, 1); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); }
@Test public void addCrossProductMany() { crossProduct1.insert(dotProduct1); crossProduct1.insert(dotProduct2); crossProduct1.insert(input1); crossProduct1.insert(input2); crossProduct1.insert(crossProduct2); assertEquals(5, crossProduct1.getChildCount()); assertEquals(Arrays.asList(dotProduct1, dotProduct2, input1, input2, crossProduct2), crossProduct1.getChildren()); Enumeration<IterationStrategyNode> enumeration = crossProduct1 .children(); assertTrue(enumeration.hasMoreElements()); assertEquals(dotProduct1, enumeration.nextElement()); assertEquals(dotProduct2, enumeration.nextElement()); assertEquals(input1, enumeration.nextElement()); assertEquals(input2, enumeration.nextElement()); assertEquals(crossProduct2, enumeration.nextElement()); assertFalse(enumeration.hasMoreElements()); }
@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()); }
private static 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")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(1, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode);
public synchronized int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { int temp = 0; for (IterationStrategyNode child : getChildren()) { temp += child.getIterationDepth(inputDepths); } return temp; }
@Test public void addCrossProduct() throws Exception { assertNull(crossProduct1.getParent()); crossProduct1.setParent(root); assertEquals(root, crossProduct1.getParent()); assertEquals(1, root.getChildCount()); assertEquals(crossProduct1, root.getChildAt(0)); assertEquals(Arrays.asList(crossProduct1), root.getChildren()); assertEquals(0, crossProduct1.getChildCount()); crossProduct1.insert(input1); assertEquals(input1, crossProduct1.getChildAt(0)); crossProduct1.insert(input2, 0); assertEquals(input2, crossProduct1.getChildAt(0)); assertEquals(input1, crossProduct1.getChildAt(1)); assertEquals(2, crossProduct1.getChildCount()); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); // A re-insert should move it crossProduct1.insert(input2, 2); assertEquals(2, crossProduct1.getChildCount()); assertEquals(Arrays.asList(input1, input2), crossProduct1.getChildren()); crossProduct1.insert(input2, 0); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); crossProduct1.insert(input1, 1); assertEquals(Arrays.asList(input2, input1), crossProduct1.getChildren()); }
@Test public void addCrossProductMany() { crossProduct1.insert(dotProduct1); crossProduct1.insert(dotProduct2); crossProduct1.insert(input1); crossProduct1.insert(input2); crossProduct1.insert(crossProduct2); assertEquals(5, crossProduct1.getChildCount()); assertEquals(Arrays.asList(dotProduct1, dotProduct2, input1, input2, crossProduct2), crossProduct1.getChildren()); Enumeration<IterationStrategyNode> enumeration = crossProduct1 .children(); assertTrue(enumeration.hasMoreElements()); assertEquals(dotProduct1, enumeration.nextElement()); assertEquals(dotProduct2, enumeration.nextElement()); assertEquals(input1, enumeration.nextElement()); assertEquals(input2, enumeration.nextElement()); assertEquals(crossProduct2, enumeration.nextElement()); assertFalse(enumeration.hasMoreElements()); }
@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()); }
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")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode);
public synchronized int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { int temp = 0; for (IterationStrategyNode child : getChildren()) { temp += child.getIterationDepth(inputDepths); } return temp; }
/** * Connect up a new named input port node to the first child of the terminal * node. If the terminal node doesn't have any children then create a new * cross product node, connect it to the terminal and connect the new input * port node to the cross product (saneish default behaviour) * * @param nipn */ public synchronized void connectDefault(NamedInputPortNode nipn) { if (terminal.getChildCount() == 0) { CrossProduct cp = new CrossProduct(); cp.setParent(terminal); nipn.setParent(cp); } else { AbstractIterationStrategyNode node = (AbstractIterationStrategyNode) (terminal .getChildAt(0)); nipn.setParent(node); } }
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")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
if (!ownerToCache.containsKey(newJob.getOwningProcess())) { List<Set<Job>> perInputCache = new ArrayList<Set<Job>>(); for (int i = 0; i < getChildCount(); i++) { perInputCache.add(new HashSet<Job>()); workingSet.add(newJob); for (int i = 1; i < getChildCount(); i++) { Set<Job> thisSet = perInputCache.get(i); if (i == inputIndex) { thisSet.add(newJob); workingSet = merge(workingSet, thisSet); pushJob(outputJob);
assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(1, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode);