commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [math] MATH-1265
Date Fri, 04 Sep 2015 14:12:52 GMT
Repository: commons-math
Updated Branches:
  refs/heads/master 1f7b1c12f -> 18a027b1f


MATH-1265

Implement "Iterable".


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/18a027b1
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/18a027b1
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/18a027b1

Branch: refs/heads/master
Commit: 18a027b1f04e420c18ae57aebe8fd031b5ff251c
Parents: 1f7b1c1
Author: Gilles <erans@apache.org>
Authored: Fri Sep 4 16:11:41 2015 +0200
Committer: Gilles <erans@apache.org>
Committed: Fri Sep 4 16:11:41 2015 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  3 +++
 .../ml/neuralnet/twod/NeuronSquareMesh2D.java   |  9 ++++++-
 .../neuralnet/twod/NeuronSquareMesh2DTest.java  | 26 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/18a027b1/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 75cad4e..ee4b64c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
     </release>
 
     <release version="4.0" date="XXXX-XX-XX" description="">
+      <action dev="erans" type="add" issue="MATH-1265"> <!-- backported to 3.6 -->
+        "NeuronSquareMesh2D" (package "o.a.c.m.ml.neuralnet.twod") implements "Iterable".
+      </action>
       <action dev="erans" type="add" issue="MATH-1264"> <!-- backported to 3.6 -->
         "MapUtils" (package "o.a.c.m.ml.neuralnet"): Method to sort units according to distance
         from a given vector.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/18a027b1/src/main/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2D.java
b/src/main/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2D.java
index d3c233b..17c7a26 100644
--- a/src/main/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2D.java
+++ b/src/main/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2D.java
@@ -41,7 +41,9 @@ import org.apache.commons.math4.ml.neuralnet.SquareNeighbourhood;
  * @see org.apache.commons.math4.ml.neuralnet.sofm
  * @since 3.3
  */
-public class NeuronSquareMesh2D implements Serializable {
+public class NeuronSquareMesh2D
+    implements Iterable<Neuron>,
+               Serializable {
     /** Serial version ID */
     private static final long serialVersionUID = 1L;
     /** Underlying network. */
@@ -195,6 +197,11 @@ public class NeuronSquareMesh2D implements Serializable {
         createLinks();
     }
 
+    /** {@inheritDoc} */
+    public Iterator<Neuron> iterator() {
+        return network.iterator();
+    }
+
     /**
      * Retrieves the underlying network.
      * A reference is returned (enabling, for example, the network to be

http://git-wip-us.apache.org/repos/asf/commons-math/blob/18a027b1/src/test/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2DTest.java
b/src/test/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2DTest.java
index a48a1ce..646ecf6 100644
--- a/src/test/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2DTest.java
+++ b/src/test/java/org/apache/commons/math4/ml/neuralnet/twod/NeuronSquareMesh2DTest.java
@@ -845,4 +845,30 @@ public class NeuronSquareMesh2DTest {
                                              NeuronSquareMesh2D.HorizontalDirection.RIGHT,
                                              NeuronSquareMesh2D.VerticalDirection.DOWN).getIdentifier());
     }
+
+    @Test
+    public void testIterator() {
+        final FeatureInitializer[] initArray = { init };
+        final NeuronSquareMesh2D map = new NeuronSquareMesh2D(3, true,
+                                                              3, true,
+                                                              SquareNeighbourhood.VON_NEUMANN,
+                                                              initArray);
+        final Set<Neuron> fromMap = new HashSet<Neuron>();
+        for (Neuron n : map) {
+            fromMap.add(n);
+        }
+
+        final Network net = map.getNetwork();
+        final Set<Neuron> fromNet = new HashSet<Neuron>();
+        for (Neuron n : net) {
+            fromNet.add(n);
+        }
+
+        for (Neuron n : fromMap) {
+            Assert.assertTrue(fromNet.contains(n));
+        }
+        for (Neuron n : fromNet) {
+            Assert.assertTrue(fromMap.contains(n));
+        }
+    }
 }


Mime
View raw message