You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@giraph.apache.org by ap...@apache.org on 2013/09/12 01:42:35 UTC

[1/3] GIRAPH-753: Efficient dense matrix aggregators (herald via apresta)

Updated Branches:
  refs/heads/trunk 96968fdca -> af21be3b7


http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/package-info.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/package-info.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/package-info.java
new file mode 100644
index 0000000..dfba3de
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Package of sparce matrix aggregator.
+ */
+package org.apache.giraph.aggregators.matrix.sparse;

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestDoubleMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestDoubleMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestDoubleMatrix.java
deleted file mode 100644
index d67eda1..0000000
--- a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestDoubleMatrix.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.giraph.utils.WritableUtils;
-import org.junit.Test;
-
-public class TestDoubleMatrix {
-  private static double E = 0.0001f;
-
-  @Test
-  public void testVectorAdd() {
-    // The default value should be 0
-    DoubleVector vec1 = new DoubleVector();
-    assertEquals(0.0, vec1.get(0), E);
-
-    // Basic get/set
-    vec1.set(0, 0.1);
-    vec1.set(10, 1.4);
-    assertEquals(0.1, vec1.get(0), E);
-    assertEquals(0.0, vec1.get(5), E);
-    assertEquals(1.4, vec1.get(10), E);
-
-    // Add another vector
-    DoubleVector vec2 = new DoubleVector();
-    vec2.set(0, 0.5);
-    vec2.set(5, 1.7);
-
-    vec1.add(vec2);
-    assertEquals(0.6, vec1.get(0), E);
-    assertEquals(1.7, vec1.get(5), E);
-    assertEquals(1.4, vec1.get(10), E);
-    assertEquals(0.0, vec1.get(15), E);
-  }
-
-  @Test
-  public void testVectorSerialize() throws Exception {
-    int size = 100;
-
-    // Serialize from
-    DoubleVector from = new DoubleVector(size);
-    from.set(0, 10.0);
-    from.set(10, 5.0);
-    from.set(12, 1.0);
-    byte[] data = WritableUtils.writeToByteArray(from);
-
-    // De-serialize to
-    DoubleVector to = new DoubleVector();
-    WritableUtils.readFieldsFromByteArray(data, to);
-
-    // The vectors should be equal
-    for (int i = 0; i < size; ++i) {
-      assertEquals(from.get(i), to.get(i), E);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestFloatMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestFloatMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestFloatMatrix.java
deleted file mode 100644
index d0f9bb0..0000000
--- a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestFloatMatrix.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.giraph.utils.WritableUtils;
-import org.junit.Test;
-
-public class TestFloatMatrix {
-  private static float E = 0.0001f;
-
-  @Test
-  public void testVectorAdd() {
-    // The default value should be 0
-    FloatVector vec1 = new FloatVector();
-    assertEquals(0.0, vec1.get(0), E);
-
-    // Basic get/set
-    vec1.set(0, 0.1f);
-    vec1.set(10, 1.4f);
-    assertEquals(0.1, vec1.get(0), E);
-    assertEquals(0.0, vec1.get(5), E);
-    assertEquals(1.4, vec1.get(10), E);
-
-    // Add another vector
-    FloatVector vec2 = new FloatVector();
-    vec2.set(0, 0.5f);
-    vec2.set(5, 1.7f);
-
-    vec1.add(vec2);
-    assertEquals(0.6, vec1.get(0), E);
-    assertEquals(1.7, vec1.get(5), E);
-    assertEquals(1.4, vec1.get(10), E);
-    assertEquals(0.0, vec1.get(15), E);
-  }
-
-  @Test
-  public void testVectorSerialize() throws Exception {
-    int size = 100;
-
-    // Serialize from
-    FloatVector from = new FloatVector(size);
-    from.set(0, 10.0f);
-    from.set(10, 5.0f);
-    from.set(12, 1.0f);
-    byte[] data = WritableUtils.writeToByteArray(from);
-
-    // De-serialize to
-    FloatVector to = new FloatVector();
-    WritableUtils.readFieldsFromByteArray(data, to);
-
-    // The vectors should be equal
-    for (int i = 0; i < size; ++i) {
-      assertEquals(from.get(i), to.get(i), E);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestIntMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestIntMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestIntMatrix.java
deleted file mode 100644
index e8d3561..0000000
--- a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestIntMatrix.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.giraph.utils.WritableUtils;
-import org.junit.Test;
-
-public class TestIntMatrix {
-
-  @Test
-  public void testVectorAdd() {
-    // The default value should be 0
-    IntVector vec1 = new IntVector();
-    assertEquals(0, vec1.get(0));
-
-    // Basic get/set
-    vec1.set(0, 1);
-    vec1.set(10, 14);
-    assertEquals(1, vec1.get(0));
-    assertEquals(0, vec1.get(5));
-    assertEquals(14, vec1.get(10));
-
-    // Add another vector
-    IntVector vec2 = new IntVector();
-    vec2.set(0, 5);
-    vec2.set(5, 17);
-
-    vec1.add(vec2);
-    assertEquals(6, vec1.get(0));
-    assertEquals(17, vec1.get(5));
-    assertEquals(14, vec1.get(10));
-    assertEquals(0, vec1.get(15));
-  }
-
-  @Test
-  public void testVectorSerialize() throws Exception {
-    int size = 100;
-
-    // Serialize from
-    IntVector from = new IntVector(size);
-    from.set(0, 10);
-    from.set(10, 5);
-    from.set(12, 1);
-    byte[] data = WritableUtils.writeToByteArray(from);
-
-    // De-serialize to
-    IntVector to = new IntVector();
-    WritableUtils.readFieldsFromByteArray(data, to);
-
-    // The vectors should be equal
-    for (int i = 0; i < size; ++i) {
-      assertEquals(from.get(i), to.get(i));
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestLongMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestLongMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestLongMatrix.java
deleted file mode 100644
index a0a7000..0000000
--- a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/TestLongMatrix.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.giraph.utils.WritableUtils;
-import org.junit.Test;
-
-public class TestLongMatrix {
-
-  @Test
-  public void testVectorAdd() {
-    // The default value should be 0
-    LongVector vec1 = new LongVector();
-    assertEquals(0, vec1.get(0));
-
-    // Basic get/set
-    vec1.set(0, 1);
-    vec1.set(10, 14);
-    assertEquals(1, vec1.get(0));
-    assertEquals(0, vec1.get(5));
-    assertEquals(14, vec1.get(10));
-
-    // Add another vector
-    LongVector vec2 = new LongVector();
-    vec2.set(0, 5);
-    vec2.set(5, 17);
-
-    vec1.add(vec2);
-    assertEquals(6, vec1.get(0));
-    assertEquals(17, vec1.get(5));
-    assertEquals(14, vec1.get(10));
-    assertEquals(0, vec1.get(15));
-  }
-
-  @Test
-  public void testVectorSerialize() throws Exception {
-    int size = 100;
-
-    // Serialize from
-    LongVector from = new LongVector(size);
-    from.set(0, 10);
-    from.set(10, 5);
-    from.set(12, 1);
-    byte[] data = WritableUtils.writeToByteArray(from);
-
-    // De-serialize to
-    LongVector to = new LongVector();
-    WritableUtils.readFieldsFromByteArray(data, to);
-
-    // The vectors should be equal
-    for (int i = 0; i < size; ++i) {
-      assertEquals(from.get(i), to.get(i));
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestDoubleDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestDoubleDenseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestDoubleDenseMatrix.java
new file mode 100644
index 0000000..289390c
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestDoubleDenseMatrix.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.matrix.dense.DoubleDenseVector;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestDoubleDenseMatrix {
+  private static double E = 0.0001f;
+
+  @Test
+  public void testVectorSingleton() {
+    DoubleDenseVector vec1 = new DoubleDenseVector(10);
+    vec1.set(0, 0.1);
+    vec1.set(6, 1.4);
+
+    DoubleDenseVector vec2 = new DoubleDenseVector();
+    vec2.setSingleton(6, 1.0);
+    vec1.add(vec2);
+    assertEquals(2.4, vec1.get(6), E);
+
+    vec2.setSingleton(15, 1.5);
+    vec1.add(vec2);
+    assertEquals(1.5, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    DoubleDenseVector vec1 = new DoubleDenseVector(10);
+    assertEquals(0.0, vec1.get(0), E);
+
+    // Basic get/set
+    vec1.set(0, 0.1);
+    vec1.set(6, 1.4);
+    assertEquals(0.1, vec1.get(0), E);
+    assertEquals(0.0, vec1.get(4), E);
+    assertEquals(1.4, vec1.get(6), E);
+    assertEquals(0.0, vec1.get(15), E);
+
+    // Add another vector
+    DoubleDenseVector vec2 = new DoubleDenseVector(20);
+    vec2.set(0, 0.5);
+    vec2.set(5, 1.7);
+
+    vec1.add(vec2);
+    assertEquals(0.6, vec1.get(0), E);
+    assertEquals(1.7, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(6), E);
+    assertEquals(0.0, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    DoubleDenseVector from = new DoubleDenseVector(size);
+    from.set(0, 10.0);
+    from.set(10, 5.0);
+    from.set(12, 1.0);
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    // De-serialize to
+    DoubleDenseVector to1 = new DoubleDenseVector();
+    DoubleDenseVector to2 = new DoubleDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to1.get(i), E);
+      assertEquals(from.get(i), to2.get(i), E);
+    }
+  }
+
+  @Test
+  public void testVectorSerializeSingleton() throws Exception {
+    DoubleDenseVector from = new DoubleDenseVector();
+    from.setSingleton(3, 10.0);
+
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    DoubleDenseVector to1 = new DoubleDenseVector();
+    DoubleDenseVector to2 = new DoubleDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    assertEquals(from.getSingletonIndex(), to1.getSingletonIndex());
+    assertEquals(from.getSingletonIndex(), to2.getSingletonIndex());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue(), E);
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue(), E);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestFloatDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestFloatDenseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestFloatDenseMatrix.java
new file mode 100644
index 0000000..170701f
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestFloatDenseMatrix.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.matrix.dense.FloatDenseVector;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestFloatDenseMatrix {
+  private static double E = 0.0001f;
+
+  @Test
+  public void testVectorSingleton() {
+    FloatDenseVector vec1 = new FloatDenseVector(10);
+    vec1.set(0, 0.1f);
+    vec1.set(6, 1.4f);
+
+    FloatDenseVector vec2 = new FloatDenseVector();
+    vec2.setSingleton(6, 1.0f);
+    vec1.add(vec2);
+    assertEquals(2.4, vec1.get(6), E);
+
+    vec2.setSingleton(15, 1.5f);
+    vec1.add(vec2);
+    assertEquals(1.5, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    FloatDenseVector vec1 = new FloatDenseVector(10);
+    assertEquals(0.0, vec1.get(0), E);
+
+    // Basic get/set
+    vec1.set(0, 0.1f);
+    vec1.set(6, 1.4f);
+    assertEquals(0.1, vec1.get(0), E);
+    assertEquals(0.0, vec1.get(4), E);
+    assertEquals(1.4, vec1.get(6), E);
+    assertEquals(0.0, vec1.get(15), E);
+
+    // Add another vector
+    FloatDenseVector vec2 = new FloatDenseVector(20);
+    vec2.set(0, 0.5f);
+    vec2.set(5, 1.7f);
+
+    vec1.add(vec2);
+    assertEquals(0.6, vec1.get(0), E);
+    assertEquals(1.7, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(6), E);
+    assertEquals(0.0, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    FloatDenseVector from = new FloatDenseVector(size);
+    from.set(0, 10.0f);
+    from.set(10, 5.0f);
+    from.set(12, 1.0f);
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    // De-serialize to
+    FloatDenseVector to1 = new FloatDenseVector();
+    FloatDenseVector to2 = new FloatDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to1.get(i), E);
+      assertEquals(from.get(i), to2.get(i), E);
+    }
+  }
+
+  @Test
+  public void testVectorSerializeSingleton() throws Exception {
+    FloatDenseVector from = new FloatDenseVector();
+    from.setSingleton(3, 10.0f);
+
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    FloatDenseVector to1 = new FloatDenseVector();
+    FloatDenseVector to2 = new FloatDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    assertEquals(from.getSingletonIndex(), to1.getSingletonIndex());
+    assertEquals(from.getSingletonIndex(), to2.getSingletonIndex());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue(), E);
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue(), E);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestIntDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestIntDenseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestIntDenseMatrix.java
new file mode 100644
index 0000000..d2fee0f
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestIntDenseMatrix.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.matrix.dense.IntDenseVector;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestIntDenseMatrix {
+
+  @Test
+  public void testVectorSingleton() {
+    IntDenseVector vec1 = new IntDenseVector(10);
+    vec1.set(0, 0);
+    vec1.set(6, 14);
+
+    IntDenseVector vec2 = new IntDenseVector();
+    vec2.setSingleton(6, 10);
+    vec1.add(vec2);
+    assertEquals(24, vec1.get(6));
+
+    vec2.setSingleton(15, 15);
+    vec1.add(vec2);
+    assertEquals(15, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    IntDenseVector vec1 = new IntDenseVector(10);
+    assertEquals(0, vec1.get(0));
+
+    // Basic get/set
+    vec1.set(0, 1);
+    vec1.set(6, 14);
+    assertEquals(1, vec1.get(0));
+    assertEquals(0, vec1.get(4));
+    assertEquals(14, vec1.get(6));
+    assertEquals(0, vec1.get(15));
+
+    // Add another vector
+    IntDenseVector vec2 = new IntDenseVector(20);
+    vec2.set(0, 5);
+    vec2.set(5, 17);
+
+    vec1.add(vec2);
+    assertEquals(6, vec1.get(0));
+    assertEquals(17, vec1.get(5));
+    assertEquals(14, vec1.get(6));
+    assertEquals(0, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    IntDenseVector from = new IntDenseVector(size);
+    from.set(0, 100);
+    from.set(10, 50);
+    from.set(12, 10);
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    // De-serialize to
+    IntDenseVector to1 = new IntDenseVector();
+    IntDenseVector to2 = new IntDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to1.get(i));
+      assertEquals(from.get(i), to2.get(i));
+    }
+  }
+
+  @Test
+  public void testVectorSerializeSingleton() throws Exception {
+    IntDenseVector from = new IntDenseVector();
+    from.setSingleton(3, 100);
+
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    IntDenseVector to1 = new IntDenseVector();
+    IntDenseVector to2 = new IntDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    assertEquals(from.getSingletonIndex(), to1.getSingletonIndex());
+    assertEquals(from.getSingletonIndex(), to2.getSingletonIndex());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue());
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestLongDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestLongDenseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestLongDenseMatrix.java
new file mode 100644
index 0000000..39e2e6e
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/dense/TestLongDenseMatrix.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.matrix.dense.LongDenseVector;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestLongDenseMatrix {
+
+  @Test
+  public void testVectorSingleton() {
+    LongDenseVector vec1 = new LongDenseVector(10);
+    vec1.set(0, 1);
+    vec1.set(6, 14);
+
+    LongDenseVector vec2 = new LongDenseVector();
+    vec2.setSingleton(6, 10);
+    vec1.add(vec2);
+    assertEquals(24, vec1.get(6));
+
+    vec2.setSingleton(15, 15);
+    vec1.add(vec2);
+    assertEquals(15, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    LongDenseVector vec1 = new LongDenseVector(10);
+    assertEquals(0, vec1.get(0));
+
+    // Basic get/set
+    vec1.set(0, 1);
+    vec1.set(6, 14);
+    assertEquals(1, vec1.get(0));
+    assertEquals(0, vec1.get(4));
+    assertEquals(14, vec1.get(6));
+    assertEquals(0, vec1.get(15));
+
+    // Add another vector
+    LongDenseVector vec2 = new LongDenseVector(20);
+    vec2.set(0, 5);
+    vec2.set(5, 17);
+
+    vec1.add(vec2);
+    assertEquals(6, vec1.get(0));
+    assertEquals(17, vec1.get(5));
+    assertEquals(14, vec1.get(6));
+    assertEquals(0, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    LongDenseVector from = new LongDenseVector(size);
+    from.set(0, 100);
+    from.set(10, 50);
+    from.set(12, 10);
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    // De-serialize to
+    LongDenseVector to1 = new LongDenseVector();
+    LongDenseVector to2 = new LongDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to1.get(i));
+      assertEquals(from.get(i), to2.get(i));
+    }
+  }
+
+  @Test
+  public void testVectorSerializeSingleton() throws Exception {
+    LongDenseVector from = new LongDenseVector();
+    from.setSingleton(3, 10);
+
+    byte[] data = WritableUtils.writeToByteArray(from, from);
+
+    LongDenseVector to1 = new LongDenseVector();
+    LongDenseVector to2 = new LongDenseVector();
+    WritableUtils.readFieldsFromByteArray(data, to1, to2);
+
+    assertEquals(from.getSingletonIndex(), to1.getSingletonIndex());
+    assertEquals(from.getSingletonIndex(), to2.getSingletonIndex());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue());
+    assertEquals(from.getSingletonValue(), to2.getSingletonValue());
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestDoubleSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestDoubleSparseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestDoubleSparseMatrix.java
new file mode 100644
index 0000000..2f04982
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestDoubleSparseMatrix.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestDoubleSparseMatrix {
+  private static double E = 0.0001f;
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    DoubleSparseVector vec1 = new DoubleSparseVector();
+    assertEquals(0.0, vec1.get(0), E);
+
+    // Basic get/set
+    vec1.set(0, 0.1);
+    vec1.set(10, 1.4);
+    assertEquals(0.1, vec1.get(0), E);
+    assertEquals(0.0, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(10), E);
+
+    // Add another vector
+    DoubleSparseVector vec2 = new DoubleSparseVector();
+    vec2.set(0, 0.5);
+    vec2.set(5, 1.7);
+
+    vec1.add(vec2);
+    assertEquals(0.6, vec1.get(0), E);
+    assertEquals(1.7, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(10), E);
+    assertEquals(0.0, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    DoubleSparseVector from = new DoubleSparseVector(size);
+    from.set(0, 10.0);
+    from.set(10, 5.0);
+    from.set(12, 1.0);
+    byte[] data = WritableUtils.writeToByteArray(from);
+
+    // De-serialize to
+    DoubleSparseVector to = new DoubleSparseVector();
+    WritableUtils.readFieldsFromByteArray(data, to);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to.get(i), E);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestFloatSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestFloatSparseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestFloatSparseMatrix.java
new file mode 100644
index 0000000..b0abb86
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestFloatSparseMatrix.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestFloatSparseMatrix {
+  private static float E = 0.0001f;
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    FloatSparseVector vec1 = new FloatSparseVector();
+    assertEquals(0.0, vec1.get(0), E);
+
+    // Basic get/set
+    vec1.set(0, 0.1f);
+    vec1.set(10, 1.4f);
+    assertEquals(0.1, vec1.get(0), E);
+    assertEquals(0.0, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(10), E);
+
+    // Add another vector
+    FloatSparseVector vec2 = new FloatSparseVector();
+    vec2.set(0, 0.5f);
+    vec2.set(5, 1.7f);
+
+    vec1.add(vec2);
+    assertEquals(0.6, vec1.get(0), E);
+    assertEquals(1.7, vec1.get(5), E);
+    assertEquals(1.4, vec1.get(10), E);
+    assertEquals(0.0, vec1.get(15), E);
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    FloatSparseVector from = new FloatSparseVector(size);
+    from.set(0, 10.0f);
+    from.set(10, 5.0f);
+    from.set(12, 1.0f);
+    byte[] data = WritableUtils.writeToByteArray(from);
+
+    // De-serialize to
+    FloatSparseVector to = new FloatSparseVector();
+    WritableUtils.readFieldsFromByteArray(data, to);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to.get(i), E);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestIntSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestIntSparseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestIntSparseMatrix.java
new file mode 100644
index 0000000..79575ce
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestIntSparseMatrix.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestIntSparseMatrix {
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    IntSparseVector vec1 = new IntSparseVector();
+    assertEquals(0, vec1.get(0));
+
+    // Basic get/set
+    vec1.set(0, 1);
+    vec1.set(10, 14);
+    assertEquals(1, vec1.get(0));
+    assertEquals(0, vec1.get(5));
+    assertEquals(14, vec1.get(10));
+
+    // Add another vector
+    IntSparseVector vec2 = new IntSparseVector();
+    vec2.set(0, 5);
+    vec2.set(5, 17);
+
+    vec1.add(vec2);
+    assertEquals(6, vec1.get(0));
+    assertEquals(17, vec1.get(5));
+    assertEquals(14, vec1.get(10));
+    assertEquals(0, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    IntSparseVector from = new IntSparseVector(size);
+    from.set(0, 10);
+    from.set(10, 5);
+    from.set(12, 1);
+    byte[] data = WritableUtils.writeToByteArray(from);
+
+    // De-serialize to
+    IntSparseVector to = new IntSparseVector();
+    WritableUtils.readFieldsFromByteArray(data, to);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to.get(i));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestLongSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestLongSparseMatrix.java b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestLongSparseMatrix.java
new file mode 100644
index 0000000..45664d1
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/aggregators/matrix/sparse/TestLongSparseMatrix.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.giraph.utils.WritableUtils;
+import org.junit.Test;
+
+public class TestLongSparseMatrix {
+
+  @Test
+  public void testVectorAdd() {
+    // The default value should be 0
+    LongSparseVector vec1 = new LongSparseVector();
+    assertEquals(0, vec1.get(0));
+
+    // Basic get/set
+    vec1.set(0, 1);
+    vec1.set(10, 14);
+    assertEquals(1, vec1.get(0));
+    assertEquals(0, vec1.get(5));
+    assertEquals(14, vec1.get(10));
+
+    // Add another vector
+    LongSparseVector vec2 = new LongSparseVector();
+    vec2.set(0, 5);
+    vec2.set(5, 17);
+
+    vec1.add(vec2);
+    assertEquals(6, vec1.get(0));
+    assertEquals(17, vec1.get(5));
+    assertEquals(14, vec1.get(10));
+    assertEquals(0, vec1.get(15));
+  }
+
+  @Test
+  public void testVectorSerialize() throws Exception {
+    int size = 100;
+
+    // Serialize from
+    LongSparseVector from = new LongSparseVector(size);
+    from.set(0, 10);
+    from.set(10, 5);
+    from.set(12, 1);
+    byte[] data = WritableUtils.writeToByteArray(from);
+
+    // De-serialize to
+    LongSparseVector to = new LongSparseVector();
+    WritableUtils.readFieldsFromByteArray(data, to);
+
+    // The vectors should be equal
+    for (int i = 0; i < size; ++i) {
+      assertEquals(from.get(i), to.get(i));
+    }
+  }
+}


[3/3] git commit: updated refs/heads/trunk to af21be3

Posted by ap...@apache.org.
GIRAPH-753: Efficient dense matrix aggregators (herald via apresta)


Project: http://git-wip-us.apache.org/repos/asf/giraph/repo
Commit: http://git-wip-us.apache.org/repos/asf/giraph/commit/af21be3b
Tree: http://git-wip-us.apache.org/repos/asf/giraph/tree/af21be3b
Diff: http://git-wip-us.apache.org/repos/asf/giraph/diff/af21be3b

Branch: refs/heads/trunk
Commit: af21be3b77c10a27e7598d358a6162550b5cb6de
Parents: 96968fd
Author: Alessandro Presta <al...@fb.com>
Authored: Wed Sep 11 16:40:56 2013 -0700
Committer: Alessandro Presta <al...@fb.com>
Committed: Wed Sep 11 16:42:14 2013 -0700

----------------------------------------------------------------------
 .../giraph/aggregators/matrix/DoubleMatrix.java | 104 ------------
 .../matrix/DoubleMatrixSumAggregator.java       | 101 -----------
 .../giraph/aggregators/matrix/DoubleVector.java | 123 --------------
 .../matrix/DoubleVectorSumAggregator.java       |  37 ----
 .../giraph/aggregators/matrix/FloatMatrix.java  | 104 ------------
 .../matrix/FloatMatrixSumAggregator.java        | 100 -----------
 .../giraph/aggregators/matrix/FloatVector.java  | 123 --------------
 .../matrix/FloatVectorSumAggregator.java        |  37 ----
 .../giraph/aggregators/matrix/IntMatrix.java    | 104 ------------
 .../matrix/IntMatrixSumAggregator.java          | 100 -----------
 .../giraph/aggregators/matrix/IntVector.java    | 123 --------------
 .../matrix/IntVectorSumAggregator.java          |  37 ----
 .../giraph/aggregators/matrix/LongMatrix.java   | 104 ------------
 .../matrix/LongMatrixSumAggregator.java         | 100 -----------
 .../giraph/aggregators/matrix/LongVector.java   | 123 --------------
 .../matrix/LongVectorSumAggregator.java         |  37 ----
 .../aggregators/matrix/MatrixSumAggregator.java |  16 +-
 .../matrix/dense/DoubleDenseMatrix.java         | 127 ++++++++++++++
 .../dense/DoubleDenseMatrixSumAggregator.java   | 106 ++++++++++++
 .../matrix/dense/DoubleDenseVector.java         | 170 +++++++++++++++++++
 .../dense/DoubleDenseVectorSumAggregator.java   |  38 +++++
 .../matrix/dense/FloatDenseMatrix.java          | 127 ++++++++++++++
 .../dense/FloatDenseMatrixSumAggregator.java    | 105 ++++++++++++
 .../matrix/dense/FloatDenseVector.java          | 168 ++++++++++++++++++
 .../dense/FloatDenseVectorSumAggregator.java    |  38 +++++
 .../matrix/dense/IntDenseMatrix.java            | 127 ++++++++++++++
 .../dense/IntDenseMatrixSumAggregator.java      | 104 ++++++++++++
 .../matrix/dense/IntDenseVector.java            | 168 ++++++++++++++++++
 .../dense/IntDenseVectorSumAggregator.java      |  39 +++++
 .../matrix/dense/LongDenseMatrix.java           | 127 ++++++++++++++
 .../dense/LongDenseMatrixSumAggregator.java     | 104 ++++++++++++
 .../matrix/dense/LongDenseVector.java           | 168 ++++++++++++++++++
 .../dense/LongDenseVectorSumAggregator.java     |  36 ++++
 .../aggregators/matrix/dense/package-info.java  |  21 +++
 .../matrix/sparse/DoubleSparseMatrix.java       | 104 ++++++++++++
 .../sparse/DoubleSparseMatrixSumAggregator.java | 104 ++++++++++++
 .../matrix/sparse/DoubleSparseVector.java       | 123 ++++++++++++++
 .../sparse/DoubleSparseVectorSumAggregator.java |  38 +++++
 .../matrix/sparse/FloatSparseMatrix.java        | 104 ++++++++++++
 .../sparse/FloatSparseMatrixSumAggregator.java  | 103 +++++++++++
 .../matrix/sparse/FloatSparseVector.java        | 123 ++++++++++++++
 .../sparse/FloatSparseVectorSumAggregator.java  |  38 +++++
 .../matrix/sparse/IntSparseMatrix.java          | 104 ++++++++++++
 .../sparse/IntSparseMatrixSumAggregator.java    | 102 +++++++++++
 .../matrix/sparse/IntSparseVector.java          | 123 ++++++++++++++
 .../sparse/IntSparseVectorSumAggregator.java    |  38 +++++
 .../matrix/sparse/LongSparseMatrix.java         | 104 ++++++++++++
 .../sparse/LongSparseMatrixSumAggregator.java   | 103 +++++++++++
 .../matrix/sparse/LongSparseVector.java         | 123 ++++++++++++++
 .../sparse/LongSparseVectorSumAggregator.java   |  38 +++++
 .../aggregators/matrix/sparse/package-info.java |  21 +++
 .../aggregators/matrix/TestDoubleMatrix.java    |  74 --------
 .../aggregators/matrix/TestFloatMatrix.java     |  74 --------
 .../aggregators/matrix/TestIntMatrix.java       |  73 --------
 .../aggregators/matrix/TestLongMatrix.java      |  73 --------
 .../matrix/dense/TestDoubleDenseMatrix.java     | 111 ++++++++++++
 .../matrix/dense/TestFloatDenseMatrix.java      | 111 ++++++++++++
 .../matrix/dense/TestIntDenseMatrix.java        | 110 ++++++++++++
 .../matrix/dense/TestLongDenseMatrix.java       | 110 ++++++++++++
 .../matrix/sparse/TestDoubleSparseMatrix.java   |  74 ++++++++
 .../matrix/sparse/TestFloatSparseMatrix.java    |  74 ++++++++
 .../matrix/sparse/TestIntSparseMatrix.java      |  73 ++++++++
 .../matrix/sparse/TestLongSparseMatrix.java     |  73 ++++++++
 63 files changed, 4014 insertions(+), 1755 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrix.java
deleted file mode 100644
index d86dc4b..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrix.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-
-/**
- * A double matrix holds the values of the entries in double vectors. It keeps
- * one double aggregator per matrix row.
- */
-public class DoubleMatrix {
-  /** The number of rows in the matrix */
-  private int numRows;
-  /** The rows of the matrix */
-  private Int2ObjectOpenHashMap<DoubleVector> rows;
-
-  /**
-   * Create a new matrix with the given number of rows.
-   *
-   * @param numRows the number of rows.
-   */
-  public DoubleMatrix(int numRows) {
-    this.numRows = numRows;
-    rows = new Int2ObjectOpenHashMap<DoubleVector>(numRows);
-    rows.defaultReturnValue(null);
-  }
-
-  /**
-   * Create a empty matrix with all values set to 0.0
-   */
-  public void initialize() {
-    rows.clear();
-    for (int i = 0; i < numRows; ++i) {
-      setRow(i, new DoubleVector());
-    }
-  }
-
-  /**
-   * Get the number of rows in the matrix.
-   *
-   * @return the number of rows.
-   */
-  public int getNumRows() {
-    return numRows;
-  }
-
-  /**
-   * Get a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @return the value of the entry
-   */
-  public double get(int i, int j) {
-    return rows.get(i).get(j);
-  }
-
-  /**
-   * Set a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value of the entry
-   */
-  public void set(int i, int j, double v) {
-    rows.get(i).set(j, v);
-  }
-
-  /**
-   * Get a specific row of the matrix.
-   *
-   * @param i the row number
-   * @return the row of the matrix
-   */
-  DoubleVector getRow(int i) {
-    return rows.get(i);
-  }
-
-  /**
-   * Set the double vector as the row specified.
-   *
-   * @param i the row
-   * @param vec the vector to set as the row
-   */
-  void setRow(int i, DoubleVector vec) {
-    rows.put(i, vec);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrixSumAggregator.java
deleted file mode 100644
index 0a1dafb..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleMatrixSumAggregator.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.AggregatorUsage;
-import org.apache.giraph.master.MasterAggregatorUsage;
-import org.apache.giraph.worker.WorkerAggregatorUsage;
-
-/**
- * The double matrix aggregator is used to register and aggregate double
- * matrices.
- */
-public class DoubleMatrixSumAggregator extends MatrixSumAggregator {
-  /** sparse vector with single entry */
-  private DoubleVector singletonVector = new DoubleVector();
-
-  /**
-   * Create a new matrix aggregator with the given prefix name for the vector
-   * aggregators.
-   *
-   * @param name the prefix for the row vector aggregators
-   */
-  public DoubleMatrixSumAggregator(String name) {
-    super(name);
-  }
-
-  /**
-   * Register the double vector aggregators, one for each row of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param master the master to register the aggregators
-   */
-  public void register(int numRows, MasterAggregatorUsage master)
-    throws InstantiationException, IllegalAccessException {
-    for (int i = 0; i < numRows; ++i) {
-      master.registerAggregator(getRowAggregatorName(i),
-          DoubleVectorSumAggregator.class);
-    }
-  }
-
-  /**
-   * Add the given value to the entry specified.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value
-   * @param worker the worker to aggregate
-   */
-  public void aggregate(int i, int j, double v, WorkerAggregatorUsage worker) {
-    singletonVector.clear();
-    singletonVector.set(j, v);
-    worker.aggregate(getRowAggregatorName(i), singletonVector);
-  }
-
-  /**
-   * Set the values of the matrix to the master specified. This is typically
-   * used in the master, to build an external DoubleMatrix and only set it at
-   * the end.
-   *
-   * @param matrix the matrix to set the values
-   * @param master the master
-   */
-  public void setMatrix(DoubleMatrix matrix, MasterAggregatorUsage master) {
-    int numRows = matrix.getNumRows();
-    for (int i = 0; i < numRows; ++i) {
-      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
-    }
-  }
-
-  /**
-   * Read the aggregated values of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param aggUser the master or worker
-   * @return the double matrix
-   */
-  public DoubleMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
-    DoubleMatrix matrix = new DoubleMatrix(numRows);
-    for (int i = 0; i < numRows; ++i) {
-      DoubleVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
-      matrix.setRow(i, vec);
-    }
-    return matrix;
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVector.java
deleted file mode 100644
index 288be93..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVector.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Map.Entry;
-
-import it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap;
-
-import org.apache.hadoop.io.Writable;
-
-/**
- * The double vector holds the values of a particular row.
- */
-public class DoubleVector implements Writable {
-  /**
-   * The entries of the vector are (key, value) pairs of the form (row, value)
-   */
-  private Int2DoubleOpenHashMap entries = null;
-
-  /**
-   * Create a new vector with default size.
-   */
-  public DoubleVector() {
-    initialize(Int2DoubleOpenHashMap.DEFAULT_INITIAL_SIZE);
-  }
-
-  /**
-   * Create a new vector with given size.
-   *
-   * @param size the size of the vector
-   */
-  public DoubleVector(int size) {
-    initialize(size);
-  }
-
-  /**
-   * Initialize the values of the vector. The default value is 0.0
-   *
-   * @param size the size of the vector
-   */
-  private void initialize(int size) {
-    entries = new Int2DoubleOpenHashMap(size);
-    entries.defaultReturnValue(0.0f);
-  }
-
-  /**
-   * Get a particular entry of the vector.
-   *
-   * @param i the entry
-   * @return the value of the entry.
-   */
-  double get(int i) {
-    return entries.get(i);
-  }
-
-  /**
-   * Set the given value to the entry specified.
-   *
-   * @param i the entry
-   * @param value the value to set to the entry
-   */
-  void set(int i, double value) {
-    entries.put(i, value);
-  }
-
-  /**
-   * Clear the contents of the vector.
-   */
-  void clear() {
-    entries.clear();
-  }
-
-  /**
-   * Add the vector specified. This is a vector addition that does an
-   * element-by-element addition.
-   *
-   * @param other the vector to add.
-   */
-  void add(DoubleVector other) {
-    for (Entry<Integer, Double> entry : other.entries.entrySet()) {
-      entries.addTo(entry.getKey(), entry.getValue());
-    }
-  }
-
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.writeInt(entries.size());
-    for (Entry<Integer, Double> entry : entries.entrySet()) {
-      out.writeInt(entry.getKey());
-      out.writeDouble(entry.getValue());
-    }
-  }
-
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    int size = in.readInt();
-    initialize(size);
-    for (int i = 0; i < size; ++i) {
-      int row = in.readInt();
-      double value = in.readDouble();
-      entries.put(row, value);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVectorSumAggregator.java
deleted file mode 100644
index 3318554..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/DoubleVectorSumAggregator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.BasicAggregator;
-
-/**
- * The double vector aggregator is used to aggregate double vectors.
- */
-public class DoubleVectorSumAggregator extends BasicAggregator<DoubleVector> {
-
-  @Override
-  public DoubleVector createInitialValue() {
-    return new DoubleVector();
-  }
-
-  @Override
-  public void aggregate(DoubleVector vector) {
-    getAggregatedValue().add(vector);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrix.java
deleted file mode 100644
index 67bad5c..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrix.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-
-/**
- * A float matrix holds the values of the entries in float vectors. It keeps one
- * float aggregator per matrix row.
- */
-public class FloatMatrix {
-  /** The number of rows in the matrix */
-  private int numRows;
-  /** The rows of the matrix */
-  private Int2ObjectOpenHashMap<FloatVector> rows;
-
-  /**
-   * Create a new matrix with the given number of rows.
-   *
-   * @param numRows the number of rows.
-   */
-  public FloatMatrix(int numRows) {
-    this.numRows = numRows;
-    rows = new Int2ObjectOpenHashMap<FloatVector>(numRows);
-    rows.defaultReturnValue(null);
-  }
-
-  /**
-   * Create a empty matrix with all values set to 0.0
-   */
-  public void initialize() {
-    rows.clear();
-    for (int i = 0; i < numRows; ++i) {
-      setRow(i, new FloatVector());
-    }
-  }
-
-  /**
-   * Get the number of rows in the matrix.
-   *
-   * @return the number of rows.
-   */
-  public int getNumRows() {
-    return numRows;
-  }
-
-  /**
-   * Get a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @return the value of the entry
-   */
-  public float get(int i, int j) {
-    return rows.get(i).get(j);
-  }
-
-  /**
-   * Set a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value of the entry
-   */
-  public void set(int i, int j, float v) {
-    rows.get(i).set(j, v);
-  }
-
-  /**
-   * Get a specific row of the matrix.
-   *
-   * @param i the row number
-   * @return the row of the matrix
-   */
-  FloatVector getRow(int i) {
-    return rows.get(i);
-  }
-
-  /**
-   * Set the float vector as the row specified.
-   *
-   * @param i the row
-   * @param vec the vector to set as the row
-   */
-  void setRow(int i, FloatVector vec) {
-    rows.put(i, vec);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrixSumAggregator.java
deleted file mode 100644
index 54406ed..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatMatrixSumAggregator.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.AggregatorUsage;
-import org.apache.giraph.master.MasterAggregatorUsage;
-import org.apache.giraph.worker.WorkerAggregatorUsage;
-
-/**
- * The float matrix aggregator is used to register and aggregate float matrices.
- */
-public class FloatMatrixSumAggregator extends MatrixSumAggregator {
-  /** sparse vector with single entry */
-  private FloatVector singletonVector = new FloatVector();
-
-  /**
-   * Create a new matrix aggregator with the given prefix name for the vector
-   * aggregators.
-   *
-   * @param name the prefix for the row vector aggregators
-   */
-  public FloatMatrixSumAggregator(String name) {
-    super(name);
-  }
-
-  /**
-   * Register the float vector aggregators, one for each row of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param master the master to register the aggregators
-   */
-  public void register(int numRows, MasterAggregatorUsage master)
-    throws InstantiationException, IllegalAccessException {
-    for (int i = 0; i < numRows; ++i) {
-      master.registerAggregator(getRowAggregatorName(i),
-          FloatVectorSumAggregator.class);
-    }
-  }
-
-  /**
-   * Add the given value to the entry specified.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value
-   * @param worker the worker to aggregate
-   */
-  public void aggregate(int i, int j, float v, WorkerAggregatorUsage worker) {
-    singletonVector.clear();
-    singletonVector.set(j, v);
-    worker.aggregate(getRowAggregatorName(i), singletonVector);
-  }
-
-  /**
-   * Set the values of the matrix to the master specified. This is typically
-   * used in the master, to build an external FloatMatrix and only set it at
-   * the end.
-   *
-   * @param matrix the matrix to set the values
-   * @param master the master
-   */
-  public void setMatrix(FloatMatrix matrix, MasterAggregatorUsage master) {
-    int numRows = matrix.getNumRows();
-    for (int i = 0; i < numRows; ++i) {
-      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
-    }
-  }
-
-  /**
-   * Read the aggregated values of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param aggUser the master or worker
-   * @return the float matrix
-   */
-  public FloatMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
-    FloatMatrix matrix = new FloatMatrix(numRows);
-    for (int i = 0; i < numRows; ++i) {
-      FloatVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
-      matrix.setRow(i, vec);
-    }
-    return matrix;
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVector.java
deleted file mode 100644
index 6efe81e..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVector.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Map.Entry;
-
-import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
-
-import org.apache.hadoop.io.Writable;
-
-/**
- * The float vector holds the values of a particular row.
- */
-public class FloatVector implements Writable {
-  /**
-   * The entries of the vector are (key, value) pairs of the form (row, value)
-   */
-  private Int2FloatOpenHashMap entries = null;
-
-  /**
-   * Create a new vector with default size.
-   */
-  public FloatVector() {
-    initialize(Int2FloatOpenHashMap.DEFAULT_INITIAL_SIZE);
-  }
-
-  /**
-   * Create a new vector with given size.
-   *
-   * @param size the size of the vector
-   */
-  public FloatVector(int size) {
-    initialize(size);
-  }
-
-  /**
-   * Initialize the values of the vector. The default value is 0.0
-   *
-   * @param size the size of the vector
-   */
-  private void initialize(int size) {
-    entries = new Int2FloatOpenHashMap(size);
-    entries.defaultReturnValue(0.0f);
-  }
-
-  /**
-   * Get a particular entry of the vector.
-   *
-   * @param i the entry
-   * @return the value of the entry.
-   */
-  float get(int i) {
-    return entries.get(i);
-  }
-
-  /**
-   * Set the given value to the entry specified.
-   *
-   * @param i the entry
-   * @param value the value to set to the entry
-   */
-  void set(int i, float value) {
-    entries.put(i, value);
-  }
-
-  /**
-   * Clear the contents of the vector.
-   */
-  void clear() {
-    entries.clear();
-  }
-
-  /**
-   * Add the vector specified. This is a vector addition that does an
-   * element-by-element addition.
-   *
-   * @param other the vector to add.
-   */
-  void add(FloatVector other) {
-    for (Entry<Integer, Float> entry : other.entries.entrySet()) {
-      entries.addTo(entry.getKey(), entry.getValue());
-    }
-  }
-
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.writeInt(entries.size());
-    for (Entry<Integer, Float> entry : entries.entrySet()) {
-      out.writeInt(entry.getKey());
-      out.writeFloat(entry.getValue());
-    }
-  }
-
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    int size = in.readInt();
-    initialize(size);
-    for (int i = 0; i < size; ++i) {
-      int row = in.readInt();
-      float value = in.readFloat();
-      entries.put(row, value);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVectorSumAggregator.java
deleted file mode 100644
index b152395..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/FloatVectorSumAggregator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.BasicAggregator;
-
-/**
- * The float vector aggregator is used to aggregate float vectors.
- */
-public class FloatVectorSumAggregator extends BasicAggregator<FloatVector> {
-
-  @Override
-  public FloatVector createInitialValue() {
-    return new FloatVector();
-  }
-
-  @Override
-  public void aggregate(FloatVector vector) {
-    getAggregatedValue().add(vector);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrix.java
deleted file mode 100644
index 624c793..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrix.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-
-/**
- * A int matrix holds the values of the entries in int vectors. It keeps one
- * int aggregator per matrix row.
- */
-public class IntMatrix {
-  /** The number of rows in the matrix */
-  private int numRows;
-  /** The rows of the matrix */
-  private Int2ObjectOpenHashMap<IntVector> rows;
-
-  /**
-   * Create a new matrix with the given number of rows.
-   *
-   * @param numRows the number of rows.
-   */
-  public IntMatrix(int numRows) {
-    this.numRows = numRows;
-    rows = new Int2ObjectOpenHashMap<IntVector>(numRows);
-    rows.defaultReturnValue(null);
-  }
-
-  /**
-   * Create a empty matrix with all values set to 0.0
-   */
-  public void initialize() {
-    rows.clear();
-    for (int i = 0; i < numRows; ++i) {
-      setRow(i, new IntVector());
-    }
-  }
-
-  /**
-   * Get the number of rows in the matrix.
-   *
-   * @return the number of rows.
-   */
-  public int getNumRows() {
-    return numRows;
-  }
-
-  /**
-   * Get a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @return the value of the entry
-   */
-  public int get(int i, int j) {
-    return rows.get(i).get(j);
-  }
-
-  /**
-   * Set a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value of the entry
-   */
-  public void set(int i, int j, int v) {
-    rows.get(i).set(j, v);
-  }
-
-  /**
-   * Get a specific row of the matrix.
-   *
-   * @param i the row number
-   * @return the row of the matrix
-   */
-  IntVector getRow(int i) {
-    return rows.get(i);
-  }
-
-  /**
-   * Set the int vector as the row specified.
-   *
-   * @param i the row
-   * @param vec the vector to set as the row
-   */
-  void setRow(int i, IntVector vec) {
-    rows.put(i, vec);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrixSumAggregator.java
deleted file mode 100644
index b7afa60..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntMatrixSumAggregator.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.AggregatorUsage;
-import org.apache.giraph.master.MasterAggregatorUsage;
-import org.apache.giraph.worker.WorkerAggregatorUsage;
-
-/**
- * The int matrix aggregator is used to register and aggregate int matrices.
- */
-public class IntMatrixSumAggregator extends MatrixSumAggregator {
-  /** sparse vector with single entry */
-  private IntVector singletonVector = new IntVector();
-
-  /**
-   * Create a new matrix aggregator with the given prefix name for the vector
-   * aggregators.
-   *
-   * @param name the prefix for the row vector aggregators
-   */
-  public IntMatrixSumAggregator(String name) {
-    super(name);
-  }
-
-  /**
-   * Register the int vector aggregators, one for each row of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param master the master to register the aggregators
-   */
-  public void register(int numRows, MasterAggregatorUsage master)
-    throws InstantiationException, IllegalAccessException {
-    for (int i = 0; i < numRows; ++i) {
-      master.registerAggregator(getRowAggregatorName(i),
-          IntVectorSumAggregator.class);
-    }
-  }
-
-  /**
-   * Add the given value to the entry specified.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value
-   * @param worker the worker to aggregate
-   */
-  public void aggregate(int i, int j, int v, WorkerAggregatorUsage worker) {
-    singletonVector.clear();
-    singletonVector.set(j, v);
-    worker.aggregate(getRowAggregatorName(i), singletonVector);
-  }
-
-  /**
-   * Set the values of the matrix to the master specified. This is typically
-   * used in the master, to build an external IntMatrix and only set it at
-   * the end.
-   *
-   * @param matrix the matrix to set the values
-   * @param master the master
-   */
-  public void setMatrix(IntMatrix matrix, MasterAggregatorUsage master) {
-    int numRows = matrix.getNumRows();
-    for (int i = 0; i < numRows; ++i) {
-      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
-    }
-  }
-
-  /**
-   * Read the aggregated values of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param aggUser the master or worker
-   * @return the int matrix
-   */
-  public IntMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
-    IntMatrix matrix = new IntMatrix(numRows);
-    for (int i = 0; i < numRows; ++i) {
-      IntVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
-      matrix.setRow(i, vec);
-    }
-    return matrix;
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVector.java
deleted file mode 100644
index e5bb400..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVector.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Map.Entry;
-
-import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
-
-import org.apache.hadoop.io.Writable;
-
-/**
- * The int vector holds the values of a particular row.
- */
-public class IntVector implements Writable {
-  /**
-   * The entries of the vector are (key, value) pairs of the form (row, value)
-   */
-  private Int2IntOpenHashMap entries = null;
-
-  /**
-   * Create a new vector with default size.
-   */
-  public IntVector() {
-    initialize(Int2IntOpenHashMap.DEFAULT_INITIAL_SIZE);
-  }
-
-  /**
-   * Create a new vector with given size.
-   *
-   * @param size the size of the vector
-   */
-  public IntVector(int size) {
-    initialize(size);
-  }
-
-  /**
-   * Initialize the values of the vector. The default value is 0.0
-   *
-   * @param size the size of the vector
-   */
-  private void initialize(int size) {
-    entries = new Int2IntOpenHashMap(size);
-    entries.defaultReturnValue(0);
-  }
-
-  /**
-   * Get a particular entry of the vector.
-   *
-   * @param i the entry
-   * @return the value of the entry.
-   */
-  int get(int i) {
-    return entries.get(i);
-  }
-
-  /**
-   * Set the given value to the entry specified.
-   *
-   * @param i the entry
-   * @param value the value to set to the entry
-   */
-  void set(int i, int value) {
-    entries.put(i, value);
-  }
-
-  /**
-   * Clear the contents of the vector.
-   */
-  void clear() {
-    entries.clear();
-  }
-
-  /**
-   * Add the vector specified. This is a vector addition that does an
-   * element-by-element addition.
-   *
-   * @param other the vector to add.
-   */
-  void add(IntVector other) {
-    for (Entry<Integer, Integer> entry : other.entries.entrySet()) {
-      entries.addTo(entry.getKey(), entry.getValue());
-    }
-  }
-
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.writeInt(entries.size());
-    for (Entry<Integer, Integer> entry : entries.entrySet()) {
-      out.writeInt(entry.getKey());
-      out.writeInt(entry.getValue());
-    }
-  }
-
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    int size = in.readInt();
-    initialize(size);
-    for (int i = 0; i < size; ++i) {
-      int row = in.readInt();
-      int value = in.readInt();
-      entries.put(row, value);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVectorSumAggregator.java
deleted file mode 100644
index b588331..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/IntVectorSumAggregator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.BasicAggregator;
-
-/**
- * The float vector aggregator is used to aggregate float vectors.
- */
-public class IntVectorSumAggregator extends BasicAggregator<IntVector> {
-
-  @Override
-  public IntVector createInitialValue() {
-    return new IntVector();
-  }
-
-  @Override
-  public void aggregate(IntVector vector) {
-    getAggregatedValue().add(vector);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrix.java
deleted file mode 100644
index dbc3ecb..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrix.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-
-/**
- * A long matrix holds the values of the entries in long vectors. It keeps one
- * long aggregator per matrix row.
- */
-public class LongMatrix {
-  /** The number of rows in the matrix */
-  private int numRows;
-  /** The rows of the matrix */
-  private Int2ObjectOpenHashMap<LongVector> rows;
-
-  /**
-   * Create a new matrix with the given number of rows.
-   *
-   * @param numRows the number of rows.
-   */
-  public LongMatrix(int numRows) {
-    this.numRows = numRows;
-    rows = new Int2ObjectOpenHashMap<LongVector>(numRows);
-    rows.defaultReturnValue(null);
-  }
-
-  /**
-   * Create a empty matrix with all values set to 0.0
-   */
-  public void initialize() {
-    rows.clear();
-    for (int i = 0; i < numRows; ++i) {
-      setRow(i, new LongVector());
-    }
-  }
-
-  /**
-   * Get the number of rows in the matrix.
-   *
-   * @return the number of rows.
-   */
-  public int getNumRows() {
-    return numRows;
-  }
-
-  /**
-   * Get a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @return the value of the entry
-   */
-  public long get(int i, int j) {
-    return rows.get(i).get(j);
-  }
-
-  /**
-   * Set a specific entry of the matrix.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value of the entry
-   */
-  public void set(int i, int j, long v) {
-    rows.get(i).set(j, v);
-  }
-
-  /**
-   * Get a specific row of the matrix.
-   *
-   * @param i the row number
-   * @return the row of the matrix
-   */
-  LongVector getRow(int i) {
-    return rows.get(i);
-  }
-
-  /**
-   * Set the long vector as the row specified.
-   *
-   * @param i the row
-   * @param vec the vector to set as the row
-   */
-  void setRow(int i, LongVector vec) {
-    rows.put(i, vec);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrixSumAggregator.java
deleted file mode 100644
index a7dc186..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongMatrixSumAggregator.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.AggregatorUsage;
-import org.apache.giraph.master.MasterAggregatorUsage;
-import org.apache.giraph.worker.WorkerAggregatorUsage;
-
-/**
- * The long matrix aggregator is used to register and aggregate long matrices.
- */
-public class LongMatrixSumAggregator extends MatrixSumAggregator {
-  /** sparse vector with single entry */
-  private LongVector singletonVector = new LongVector();
-
-  /**
-   * Create a new matrix aggregator with the given prefix name for the vector
-   * aggregators.
-   *
-   * @param name the prefix for the row vector aggregators
-   */
-  public LongMatrixSumAggregator(String name) {
-    super(name);
-  }
-
-  /**
-   * Register the long vector aggregators, one for each row of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param master the master to register the aggregators
-   */
-  public void register(int numRows, MasterAggregatorUsage master)
-    throws InstantiationException, IllegalAccessException {
-    for (int i = 0; i < numRows; ++i) {
-      master.registerAggregator(getRowAggregatorName(i),
-          LongVectorSumAggregator.class);
-    }
-  }
-
-  /**
-   * Add the given value to the entry specified.
-   *
-   * @param i the row
-   * @param j the column
-   * @param v the value
-   * @param worker the worker to aggregate
-   */
-  public void aggregate(int i, int j, long v, WorkerAggregatorUsage worker) {
-    singletonVector.clear();
-    singletonVector.set(j, v);
-    worker.aggregate(getRowAggregatorName(i), singletonVector);
-  }
-
-  /**
-   * Set the values of the matrix to the master specified. This is typically
-   * used in the master, to build an external LongMatrix and only set it at
-   * the end.
-   *
-   * @param matrix the matrix to set the values
-   * @param master the master
-   */
-  public void setMatrix(LongMatrix matrix, MasterAggregatorUsage master) {
-    int numRows = matrix.getNumRows();
-    for (int i = 0; i < numRows; ++i) {
-      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
-    }
-  }
-
-  /**
-   * Read the aggregated values of the matrix.
-   *
-   * @param numRows the number of rows
-   * @param aggUser the master or worker
-   * @return the long matrix
-   */
-  public LongMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
-    LongMatrix matrix = new LongMatrix(numRows);
-    for (int i = 0; i < numRows; ++i) {
-      LongVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
-      matrix.setRow(i, vec);
-    }
-    return matrix;
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVector.java
deleted file mode 100644
index 6781b43..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVector.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Map.Entry;
-
-import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;
-
-import org.apache.hadoop.io.Writable;
-
-/**
- * The long vector holds the values of a particular row.
- */
-public class LongVector implements Writable {
-  /**
-   * The entries of the vector are (key, value) pairs of the form (row, value)
-   */
-  private Int2LongOpenHashMap entries = null;
-
-  /**
-   * Create a new vector with default size.
-   */
-  public LongVector() {
-    initialize(Int2LongOpenHashMap.DEFAULT_INITIAL_SIZE);
-  }
-
-  /**
-   * Create a new vector with given size.
-   *
-   * @param size the size of the vector
-   */
-  public LongVector(int size) {
-    initialize(size);
-  }
-
-  /**
-   * Initialize the values of the vector. The default value is 0.0
-   *
-   * @param size the size of the vector
-   */
-  private void initialize(int size) {
-    entries = new Int2LongOpenHashMap(size);
-    entries.defaultReturnValue(0L);
-  }
-
-  /**
-   * Get a particular entry of the vector.
-   *
-   * @param i the entry
-   * @return the value of the entry.
-   */
-  long get(int i) {
-    return entries.get(i);
-  }
-
-  /**
-   * Set the given value to the entry specified.
-   *
-   * @param i the entry
-   * @param value the value to set to the entry
-   */
-  void set(int i, long value) {
-    entries.put(i, value);
-  }
-
-  /**
-   * Clear the contents of the vector.
-   */
-  void clear() {
-    entries.clear();
-  }
-
-  /**
-   * Add the vector specified. This is a vector addition that does an
-   * element-by-element addition.
-   *
-   * @param other the vector to add.
-   */
-  void add(LongVector other) {
-    for (Entry<Integer, Long> kv : other.entries.entrySet()) {
-      entries.addTo(kv.getKey(), kv.getValue());
-    }
-  }
-
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.writeInt(entries.size());
-    for (Entry<Integer, Long> kv : entries.entrySet()) {
-      out.writeInt(kv.getKey());
-      out.writeLong(kv.getValue());
-    }
-  }
-
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    int size = in.readInt();
-    initialize(size);
-    for (int i = 0; i < size; ++i) {
-      int row = in.readInt();
-      long value = in.readLong();
-      entries.put(row, value);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVectorSumAggregator.java
deleted file mode 100644
index ed35e15..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/LongVectorSumAggregator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.giraph.aggregators.matrix;
-
-import org.apache.giraph.aggregators.BasicAggregator;
-
-/**
- * The long vector aggregator is used to aggregate long vectors.
- */
-public class LongVectorSumAggregator extends BasicAggregator<LongVector> {
-
-  @Override
-  public LongVector createInitialValue() {
-    return new LongVector();
-  }
-
-  @Override
-  public void aggregate(LongVector vector) {
-    getAggregatedValue().add(vector);
-  }
-}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/MatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/MatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/MatrixSumAggregator.java
index 3864472..8ed6bd8 100644
--- a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/MatrixSumAggregator.java
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/MatrixSumAggregator.java
@@ -18,16 +18,21 @@
 
 package org.apache.giraph.aggregators.matrix;
 
+import java.util.ArrayList;
+
 /**
  * The abstract matrix aggregator contains the prefix name of the vector
- * aggregators the have the values of the rows.
+ * aggregators that have the values of the rows. It also cashes the names to
+ * avoid creating the same string multiples times.
  */
 public abstract class MatrixSumAggregator {
   /**
-   * The prefix name of the double vector aggregators. The aggregator names are
-   * created as (name0, name1, ...).
+   * The prefix name of the vector aggregators. The aggregator names are created
+   * as (name0, name1, ...).
    */
   private String name;
+  /** Cache the names of the columns */
+  private ArrayList<String> names = new ArrayList<String>();
 
   /**
    * Create a new matrix aggregator with the given prefix name for the vector
@@ -46,6 +51,9 @@ public abstract class MatrixSumAggregator {
    * @return the name of the aggregator
    */
   protected String getRowAggregatorName(int i) {
-    return name + i;
+    for (int n = names.size(); n <= i; ++n) {
+      names.add(name + n);
+    }
+    return names.get(i);
   }
 }

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrix.java
new file mode 100644
index 0000000..bfdf373
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrix.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.util.ArrayList;
+
+/**
+ * A double matrix holds the values of the entries in double vectors. It keeps
+ * one double aggregator per matrix row.
+ */
+public class DoubleDenseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The number of columns in the matrix */
+  private int numColumns;
+  /** The rows of the matrix */
+  private ArrayList<DoubleDenseVector> rows = null;
+
+  /**
+   * Create a new matrix with the same number of rows and columns.
+   *
+   * @param size the number of rows and columns
+   */
+  public DoubleDenseMatrix(int size) {
+    this(size, size);
+  }
+
+  /**
+   * Create a new matrix with the given number of rows and columns.
+   *
+   * @param numRows the number of rows
+   * @param numColumns the number of columns
+   */
+  public DoubleDenseMatrix(int numRows, int numColumns) {
+    this.numRows = numRows;
+    this.numColumns = numColumns;
+    rows = new ArrayList<DoubleDenseVector>();
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      rows.add(new DoubleDenseVector(numColumns));
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get the number of the columns in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumColumns() {
+    return numColumns;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public double get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, double v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  DoubleDenseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Add the double vector as a row in the matrix.
+   *
+   * @param vec the vector to add
+   */
+  void addRow(DoubleDenseVector vec) {
+    if (rows.size() >= numRows) {
+      throw new RuntimeException("Cannot add more rows!");
+    }
+    rows.add(vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrixSumAggregator.java
new file mode 100644
index 0000000..2c2c078
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseMatrixSumAggregator.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The double dense matrix aggregator is used to register and aggregate double
+ * dense matrices.
+ */
+public class DoubleDenseMatrixSumAggregator extends MatrixSumAggregator {
+  /** Dense vector with a single entry */
+  private DoubleDenseVector singletonVector = new DoubleDenseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public DoubleDenseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the double vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      boolean success = master.registerAggregator(getRowAggregatorName(i),
+          DoubleDenseVectorSumAggregator.class);
+      if (!success) {
+        throw new RuntimeException("Aggregator already registered");
+      }
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, double v, WorkerAggregatorUsage worker) {
+    singletonVector.setSingleton(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external DoubleMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(DoubleDenseMatrix matrix,
+      MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the double matrix
+   */
+  public DoubleDenseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    DoubleDenseMatrix matrix = new DoubleDenseMatrix(numRows, 1);
+    for (int i = 0; i < numRows; ++i) {
+      DoubleDenseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.addRow(vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVector.java
new file mode 100644
index 0000000..88b8a9b
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVector.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The double dense vector holds the values of a particular row. The singleton
+ * is used to avoid creating too many objects by compactly represent vectors
+ * with a single nonzero coordinate. This way we perform aggregations
+ * efficiently.
+ */
+public class DoubleDenseVector implements Writable {
+  /** The entries of the vector. */
+  private DoubleArrayList entries = new DoubleArrayList();
+  /** If true, this vector is singleton */
+  private boolean isSingleton = false;
+  /** The index of the singleton */
+  private int singletonIndex;
+  /** The value of the singleton */
+  private double singletonValue;
+
+  /** Create a new vector with default size. */
+  public DoubleDenseVector() { }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public DoubleDenseVector(int size) {
+    ensureCapacity(size);
+  }
+
+  /**
+   * Set the singleton index and value.
+   *
+   * @param index the index
+   * @param value the value
+   */
+  public void setSingleton(int index, double value) {
+    isSingleton = true;
+    this.singletonIndex = index;
+    this.singletonValue = value;
+  }
+
+  /**
+   * Get the singleton index.
+   *
+   * @return the singleton index
+   */
+  public int getSingletonIndex() {
+    return singletonIndex;
+  }
+
+  /**
+   * Get the singleton value.
+   *
+   * @return the singleton value
+   */
+  public double getSingletonValue() {
+    return singletonValue;
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public double get(int i) {
+    // The default value is 0.0
+    if (i >= entries.size()) {
+      return 0.0;
+    }
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry with the index specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, double value) {
+    entries.set(i, value);
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(DoubleDenseVector other) {
+    if (isSingleton) {
+      throw new RuntimeException("Cannot add to singleton vector");
+    }
+    if (other.isSingleton) {
+      ensureCapacity(other.singletonIndex + 1);
+      entries.set(other.singletonIndex, entries.get(other.singletonIndex) +
+          other.singletonValue);
+    } else {
+      ensureCapacity(other.entries.size());
+      for (int i = 0; i < other.entries.size(); ++i) {
+        entries.set(i, entries.get(i) + other.entries.get(i));
+      }
+    }
+  }
+
+  /**
+   * Resize the array to be at least the size specified.
+   *
+   * @param size the size of the array
+   */
+  private void ensureCapacity(int size) {
+    if (entries.size() < size) {
+      entries.size(size);
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeBoolean(isSingleton);
+    if (isSingleton) {
+      out.writeInt(singletonIndex);
+      out.writeDouble(singletonValue);
+    } else {
+      out.writeInt(entries.size());
+      for (int i = 0; i < entries.size(); ++i) {
+        out.writeDouble(entries.get(i));
+      }
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    isSingleton = in.readBoolean();
+    if (isSingleton) {
+      singletonIndex = in.readInt();
+      singletonValue = in.readDouble();
+    } else {
+      int size = in.readInt();
+      for (int i = 0; i < size; ++i) {
+        entries.add(in.readDouble());
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVectorSumAggregator.java
new file mode 100644
index 0000000..953f146
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/DoubleDenseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The double dense vector aggregator is used to aggregate double dense vectors.
+ */
+public class DoubleDenseVectorSumAggregator extends
+    BasicAggregator<DoubleDenseVector> {
+
+  @Override
+  public DoubleDenseVector createInitialValue() {
+    return new DoubleDenseVector();
+  }
+
+  @Override
+  public void aggregate(DoubleDenseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrix.java
new file mode 100644
index 0000000..ce75d6d
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrix.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.util.ArrayList;
+
+/**
+ * A float matrix holds the values of the entries in float vectors. It keeps one
+ * float aggregator per matrix row.
+ */
+public class FloatDenseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The number of columns in the matrix */
+  private int numColumns;
+  /** The rows of the matrix */
+  private ArrayList<FloatDenseVector> rows = null;
+
+  /**
+   * Create a new matrix with the same number of rows and columns.
+   *
+   * @param size the number of rows and columns
+   */
+  public FloatDenseMatrix(int size) {
+    this(size, size);
+  }
+
+  /**
+   * Create a new matrix with the given number of rows and columns.
+   *
+   * @param numRows the number of rows
+   * @param numColumns the number of columns
+   */
+  public FloatDenseMatrix(int numRows, int numColumns) {
+    this.numRows = numRows;
+    this.numColumns = numColumns;
+    rows = new ArrayList<FloatDenseVector>();
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      rows.add(new FloatDenseVector(numColumns));
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get the number of the columns in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumColumns() {
+    return numColumns;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public float get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, float v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  FloatDenseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Add the float vector as a row in the matrix.
+   *
+   * @param vec the vector to add
+   */
+  void addRow(FloatDenseVector vec) {
+    if (rows.size() >= numRows) {
+      throw new RuntimeException("Cannot add more rows!");
+    }
+    rows.add(vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrixSumAggregator.java
new file mode 100644
index 0000000..61fbd0b
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseMatrixSumAggregator.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The float dense matrix aggregator is used to register and aggregate float
+ * dense matrices.
+ */
+public class FloatDenseMatrixSumAggregator extends MatrixSumAggregator {
+  /** Dense vector with a single entry */
+  private FloatDenseVector singletonVector = new FloatDenseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public FloatDenseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the float vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      boolean success = master.registerAggregator(getRowAggregatorName(i),
+          FloatDenseVectorSumAggregator.class);
+      if (!success) {
+        throw new RuntimeException("Aggregator already registered");
+      }
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, float v, WorkerAggregatorUsage worker) {
+    singletonVector.setSingleton(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external FloatMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(FloatDenseMatrix matrix, MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the float matrix
+   */
+  public FloatDenseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    FloatDenseMatrix matrix = new FloatDenseMatrix(numRows, 1);
+    for (int i = 0; i < numRows; ++i) {
+      FloatDenseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.addRow(vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVector.java
new file mode 100644
index 0000000..140bd1e
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVector.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.floats.FloatArrayList;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The float dense vector holds the values of a particular row.
+ * See DoubleDenseVector for explanation on why the singleton is needed.
+ */
+public class FloatDenseVector implements Writable {
+  /** The entries of the vector. */
+  private FloatArrayList entries = new FloatArrayList();
+  /** If true, this vector is singleton */
+  private boolean isSingleton = false;
+  /** The index of the singleton */
+  private int singletonIndex;
+  /** The value of the singleton */
+  private float singletonValue;
+
+  /** Create a new vector with default size. */
+  public FloatDenseVector() { }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public FloatDenseVector(int size) {
+    ensureCapacity(size);
+  }
+
+  /**
+   * Set the singleton index and value.
+   *
+   * @param index the index
+   * @param value the value
+   */
+  public void setSingleton(int index, float value) {
+    isSingleton = true;
+    this.singletonIndex = index;
+    this.singletonValue = value;
+  }
+
+  /**
+   * Get the singleton index.
+   *
+   * @return the singleton index
+   */
+  public int getSingletonIndex() {
+    return singletonIndex;
+  }
+
+  /**
+   * Get the singleton value.
+   *
+   * @return the singleton value
+   */
+  public float getSingletonValue() {
+    return singletonValue;
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public float get(int i) {
+    // The default value is 0.0
+    if (i >= entries.size()) {
+      return 0.0f;
+    }
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry with the index specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, float value) {
+    entries.set(i, value);
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(FloatDenseVector other) {
+    if (isSingleton) {
+      throw new RuntimeException("Cannot add to singleton vector");
+    }
+    if (other.isSingleton) {
+      ensureCapacity(other.singletonIndex + 1);
+      entries.set(other.singletonIndex, entries.get(other.singletonIndex) +
+          other.singletonValue);
+    } else {
+      ensureCapacity(other.entries.size());
+      for (int i = 0; i < other.entries.size(); ++i) {
+        entries.set(i, entries.get(i) + other.entries.get(i));
+      }
+    }
+  }
+
+  /**
+   * Resize the array to be at least the size specified.
+   *
+   * @param size the size of the array
+   */
+  private void ensureCapacity(int size) {
+    if (entries.size() < size) {
+      entries.size(size);
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeBoolean(isSingleton);
+    if (isSingleton) {
+      out.writeInt(singletonIndex);
+      out.writeFloat(singletonValue);
+    } else {
+      out.writeInt(entries.size());
+      for (int i = 0; i < entries.size(); ++i) {
+        out.writeFloat(entries.get(i));
+      }
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    isSingleton = in.readBoolean();
+    if (isSingleton) {
+      singletonIndex = in.readInt();
+      singletonValue = in.readFloat();
+    } else {
+      int size = in.readInt();
+      for (int i = 0; i < size; ++i) {
+        entries.add(in.readFloat());
+      }
+    }
+  }
+}


[2/3] GIRAPH-753: Efficient dense matrix aggregators (herald via apresta)

Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVectorSumAggregator.java
new file mode 100644
index 0000000..554ef48
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/FloatDenseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The float dense vector aggregator is used to aggregate float dense vectors.
+ */
+public class FloatDenseVectorSumAggregator extends
+    BasicAggregator<FloatDenseVector> {
+
+  @Override
+  public FloatDenseVector createInitialValue() {
+    return new FloatDenseVector();
+  }
+
+  @Override
+  public void aggregate(FloatDenseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrix.java
new file mode 100644
index 0000000..ed85574
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrix.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.util.ArrayList;
+
+/**
+ * A int matrix holds the values of the entries in int vectors. It keeps one int
+ * aggregator per matrix row.
+ */
+public class IntDenseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The number of columns in the matrix */
+  private int numColumns;
+  /** The rows of the matrix */
+  private ArrayList<IntDenseVector> rows = null;
+
+  /**
+   * Create a new matrix with the same number of rows and columns.
+   *
+   * @param size the number of rows and columns
+   */
+  public IntDenseMatrix(int size) {
+    this(size, size);
+  }
+
+  /**
+   * Create a new matrix with the given number of rows and columns.
+   *
+   * @param numRows the number of rows
+   * @param numColumns the number of columns
+   */
+  public IntDenseMatrix(int numRows, int numColumns) {
+    this.numRows = numRows;
+    this.numColumns = numColumns;
+    rows = new ArrayList<IntDenseVector>();
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      rows.add(new IntDenseVector(numColumns));
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get the number of the columns in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumColumns() {
+    return numColumns;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public int get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, int v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  IntDenseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Add the int vector as a row in the matrix.
+   *
+   * @param vec the vector to add
+   */
+  void addRow(IntDenseVector vec) {
+    if (rows.size() >= numRows) {
+      throw new RuntimeException("Cannot add more rows!");
+    }
+    rows.add(vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrixSumAggregator.java
new file mode 100644
index 0000000..3466545
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseMatrixSumAggregator.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The int dense matrix aggregator is used to register and aggregate int dense
+ * matrices.
+ */
+public class IntDenseMatrixSumAggregator extends MatrixSumAggregator {
+  /** Dense vector with a single entry */
+  private IntDenseVector singletonVector = new IntDenseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public IntDenseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the int vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      boolean success = master.registerAggregator(getRowAggregatorName(i),
+          IntDenseVectorSumAggregator.class);
+      if (!success) {
+        throw new RuntimeException("Aggregator already registered");
+      }
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, int v, WorkerAggregatorUsage worker) {
+    singletonVector.setSingleton(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external IntMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(IntDenseMatrix matrix, MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the int matrix
+   */
+  public IntDenseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    IntDenseMatrix matrix = new IntDenseMatrix(numRows, 1);
+    for (int i = 0; i < numRows; ++i) {
+      IntDenseVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
+      matrix.addRow(vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVector.java
new file mode 100644
index 0000000..9e74f9e
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVector.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The int dense vector holds the values of a particular row.
+ * See DoubleDenseVector for explanation on why the singleton is needed.
+ */
+public class IntDenseVector implements Writable {
+  /** The entries of the vector. */
+  private IntArrayList entries = new IntArrayList();
+  /** If true, this vector is singleton */
+  private boolean isSingleton = false;
+  /** The index of the singleton */
+  private int singletonIndex;
+  /** The value of the singleton */
+  private int singletonValue;
+
+  /** Create a new vector with default size. */
+  public IntDenseVector() { }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public IntDenseVector(int size) {
+    ensureCapacity(size);
+  }
+
+  /**
+   * Set the singleton index and value.
+   *
+   * @param index the index
+   * @param value the value
+   */
+  public void setSingleton(int index, int value) {
+    isSingleton = true;
+    this.singletonIndex = index;
+    this.singletonValue = value;
+  }
+
+  /**
+   * Get the singleton index.
+   *
+   * @return the singleton index
+   */
+  public int getSingletonIndex() {
+    return singletonIndex;
+  }
+
+  /**
+   * Get the singleton value.
+   *
+   * @return the singleton value
+   */
+  public int getSingletonValue() {
+    return singletonValue;
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public int get(int i) {
+    // The default value is 0
+    if (i >= entries.size()) {
+      return 0;
+    }
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry with the index specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, int value) {
+    entries.set(i, value);
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(IntDenseVector other) {
+    if (isSingleton) {
+      throw new RuntimeException("Cannot add to singleton vector");
+    }
+    if (other.isSingleton) {
+      ensureCapacity(other.singletonIndex + 1);
+      entries.set(other.singletonIndex, entries.get(other.singletonIndex) +
+          other.singletonValue);
+    } else {
+      ensureCapacity(other.entries.size());
+      for (int i = 0; i < other.entries.size(); ++i) {
+        entries.set(i, entries.get(i) + other.entries.get(i));
+      }
+    }
+  }
+
+  /**
+   * Resize the array to be at least the size specified.
+   *
+   * @param size the size of the array
+   */
+  private void ensureCapacity(int size) {
+    if (entries.size() < size) {
+      entries.size(size);
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeBoolean(isSingleton);
+    if (isSingleton) {
+      out.writeInt(singletonIndex);
+      out.writeInt(singletonValue);
+    } else {
+      out.writeInt(entries.size());
+      for (int i = 0; i < entries.size(); ++i) {
+        out.writeInt(entries.get(i));
+      }
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    isSingleton = in.readBoolean();
+    if (isSingleton) {
+      singletonIndex = in.readInt();
+      singletonValue = in.readInt();
+    } else {
+      int size = in.readInt();
+      for (int i = 0; i < size; ++i) {
+        entries.add(in.readInt());
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVectorSumAggregator.java
new file mode 100644
index 0000000..eeb3bed
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/IntDenseVectorSumAggregator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The double dense vector aggregator is used to aggregate double dense
+ * vectors.
+ */
+public class IntDenseVectorSumAggregator extends
+    BasicAggregator<IntDenseVector> {
+
+  @Override
+  public IntDenseVector createInitialValue() {
+    return new IntDenseVector();
+  }
+
+  @Override
+  public void aggregate(IntDenseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrix.java
new file mode 100644
index 0000000..0f15fb2
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrix.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.util.ArrayList;
+
+/**
+ * A long matrix holds the values of the entries in long vectors. It keeps one
+ * long aggregator per matrix row.
+ */
+public class LongDenseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The number of columns in the matrix */
+  private int numColumns;
+  /** The rows of the matrix */
+  private ArrayList<LongDenseVector> rows = null;
+
+  /**
+   * Create a new matrix with the same number of rows and columns.
+   *
+   * @param size the number of rows and columns
+   */
+  public LongDenseMatrix(int size) {
+    this(size, size);
+  }
+
+  /**
+   * Create a new matrix with the given number of rows and columns.
+   *
+   * @param numRows the number of rows
+   * @param numColumns the number of columns
+   */
+  public LongDenseMatrix(int numRows, int numColumns) {
+    this.numRows = numRows;
+    this.numColumns = numColumns;
+    rows = new ArrayList<LongDenseVector>();
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      rows.add(new LongDenseVector(numColumns));
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get the number of the columns in the matrix.
+   *
+   * @return the number of rows
+   */
+  public int getNumColumns() {
+    return numColumns;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public long get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, long v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  LongDenseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Add the long vector as a row in the matrix.
+   *
+   * @param vec the vector to add
+   */
+  void addRow(LongDenseVector vec) {
+    if (rows.size() >= numRows) {
+      throw new RuntimeException("Cannot add more rows!");
+    }
+    rows.add(vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrixSumAggregator.java
new file mode 100644
index 0000000..0fb1aa8
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseMatrixSumAggregator.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The long dense matrix aggregator is used to register and aggregate long
+ * dense matrices.
+ */
+public class LongDenseMatrixSumAggregator extends MatrixSumAggregator {
+  /** Dense vector with a single entry */
+  private LongDenseVector singletonVector = new LongDenseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public LongDenseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the long vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      boolean success = master.registerAggregator(getRowAggregatorName(i),
+          LongDenseVectorSumAggregator.class);
+      if (!success) {
+        throw new RuntimeException("Aggregator already registered");
+      }
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, long v, WorkerAggregatorUsage worker) {
+    singletonVector.setSingleton(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external LongMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(LongDenseMatrix matrix, MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the long matrix
+   */
+  public LongDenseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    LongDenseMatrix matrix = new LongDenseMatrix(numRows, 1);
+    for (int i = 0; i < numRows; ++i) {
+      LongDenseVector vec = aggUser.getAggregatedValue(getRowAggregatorName(i));
+      matrix.addRow(vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVector.java
new file mode 100644
index 0000000..4cedc1f
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVector.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.longs.LongArrayList;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The long dense vector holds the values of a particular row.
+ * See DoubleDenseVector for explanation on why the singleton is needed.
+ */
+public class LongDenseVector implements Writable {
+  /** The entries of the vector. */
+  private LongArrayList entries = new LongArrayList();
+  /** If true, this vector is singleton */
+  private boolean isSingleton = false;
+  /** The index of the singleton */
+  private int singletonIndex;
+  /** The value of the singleton */
+  private long singletonValue;
+
+  /** Create a new vector with default size. */
+  public LongDenseVector() { }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public LongDenseVector(int size) {
+    ensureCapacity(size);
+  }
+
+  /**
+   * Set the singleton index and value.
+   *
+   * @param index the index
+   * @param value the value
+   */
+  public void setSingleton(int index, long value) {
+    isSingleton = true;
+    this.singletonIndex = index;
+    this.singletonValue = value;
+  }
+
+  /**
+   * Get the singleton index.
+   *
+   * @return the singleton index
+   */
+  public int getSingletonIndex() {
+    return singletonIndex;
+  }
+
+  /**
+   * Get the singleton value.
+   *
+   * @return the singleton value
+   */
+  public long getSingletonValue() {
+    return singletonValue;
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public long get(int i) {
+    // The default value is 0.0
+    if (i >= entries.size()) {
+      return 0L;
+    }
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry with the index specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, long value) {
+    entries.set(i, value);
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(LongDenseVector other) {
+    if (isSingleton) {
+      throw new RuntimeException("Cannot add to singleton vector");
+    }
+    if (other.isSingleton) {
+      ensureCapacity(other.singletonIndex + 1);
+      entries.set(other.singletonIndex, entries.get(other.singletonIndex) +
+          other.singletonValue);
+    } else {
+      ensureCapacity(other.entries.size());
+      for (int i = 0; i < other.entries.size(); ++i) {
+        entries.set(i, entries.get(i) + other.entries.get(i));
+      }
+    }
+  }
+
+  /**
+   * Resize the array to be at least the size specified.
+   *
+   * @param size the size of the array
+   */
+  private void ensureCapacity(int size) {
+    if (entries.size() < size) {
+      entries.size(size);
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeBoolean(isSingleton);
+    if (isSingleton) {
+      out.writeInt(singletonIndex);
+      out.writeLong(singletonValue);
+    } else {
+      out.writeInt(entries.size());
+      for (int i = 0; i < entries.size(); ++i) {
+        out.writeLong(entries.get(i));
+      }
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    isSingleton = in.readBoolean();
+    if (isSingleton) {
+      singletonIndex = in.readInt();
+      singletonValue = in.readLong();
+    } else {
+      int size = in.readInt();
+      for (int i = 0; i < size; ++i) {
+        entries.add(in.readLong());
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVectorSumAggregator.java
new file mode 100644
index 0000000..aa084c6
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/LongDenseVectorSumAggregator.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.dense;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/** The long dense vector aggregator is used to aggregate long dense vectors. */
+public class LongDenseVectorSumAggregator extends
+    BasicAggregator<LongDenseVector> {
+
+  @Override
+  public LongDenseVector createInitialValue() {
+    return new LongDenseVector();
+  }
+
+  @Override
+  public void aggregate(LongDenseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/package-info.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/package-info.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/package-info.java
new file mode 100644
index 0000000..dea26a1
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/dense/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Package of dense matrix aggregator.
+ */
+package org.apache.giraph.aggregators.matrix.dense;

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrix.java
new file mode 100644
index 0000000..5a8b8b5
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrix.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+/**
+ * A double matrix holds the values of the entries in double vectors. It keeps
+ * one double aggregator per matrix row.
+ */
+public class DoubleSparseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The rows of the matrix */
+  private Int2ObjectOpenHashMap<DoubleSparseVector> rows;
+
+  /**
+   * Create a new matrix with the given number of rows.
+   *
+   * @param numRows the number of rows.
+   */
+  public DoubleSparseMatrix(int numRows) {
+    this.numRows = numRows;
+    rows = new Int2ObjectOpenHashMap<DoubleSparseVector>(numRows);
+    rows.defaultReturnValue(null);
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      setRow(i, new DoubleSparseVector());
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows.
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public double get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, double v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  DoubleSparseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Set the double vector as the row specified.
+   *
+   * @param i the row
+   * @param vec the vector to set as the row
+   */
+  void setRow(int i, DoubleSparseVector vec) {
+    rows.put(i, vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrixSumAggregator.java
new file mode 100644
index 0000000..02a1c1e
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseMatrixSumAggregator.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The double matrix aggregator is used to register and aggregate double
+ * matrices.
+ */
+public class DoubleSparseMatrixSumAggregator extends MatrixSumAggregator {
+  /** sparse vector with single entry */
+  private DoubleSparseVector singletonVector = new DoubleSparseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public DoubleSparseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the double vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      master.registerAggregator(getRowAggregatorName(i),
+          DoubleSparseVectorSumAggregator.class);
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, double v, WorkerAggregatorUsage worker) {
+    singletonVector.clear();
+    singletonVector.set(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external DoubleMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(DoubleSparseMatrix matrix,
+      MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the double matrix
+   */
+  public DoubleSparseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    DoubleSparseMatrix matrix = new DoubleSparseMatrix(numRows);
+    for (int i = 0; i < numRows; ++i) {
+      DoubleSparseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.setRow(i, vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVector.java
new file mode 100644
index 0000000..de119fb
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVector.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2DoubleMap;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap;
+
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The double vector holds the values of a particular row.
+ */
+public class DoubleSparseVector implements Writable {
+  /**
+   * The entries of the vector are (key, value) pairs of the form (row, value)
+   */
+  private Int2DoubleOpenHashMap entries = null;
+
+  /**
+   * Create a new vector with default size.
+   */
+  public DoubleSparseVector() {
+    initialize(Int2DoubleOpenHashMap.DEFAULT_INITIAL_SIZE);
+  }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public DoubleSparseVector(int size) {
+    initialize(size);
+  }
+
+  /**
+   * Initialize the values of the vector. The default value is 0.0
+   *
+   * @param size the size of the vector
+   */
+  private void initialize(int size) {
+    entries = new Int2DoubleOpenHashMap(size);
+    entries.defaultReturnValue(0.0f);
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public double get(int i) {
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, double value) {
+    entries.put(i, value);
+  }
+
+  /**
+   * Clear the contents of the vector.
+   */
+  public void clear() {
+    entries.clear();
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(DoubleSparseVector other) {
+    for (Int2DoubleMap.Entry entry : other.entries.int2DoubleEntrySet()) {
+      entries.addTo(entry.getIntKey(), entry.getDoubleValue());
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(entries.size());
+    for (Int2DoubleMap.Entry entry : entries.int2DoubleEntrySet()) {
+      out.writeInt(entry.getIntKey());
+      out.writeDouble(entry.getDoubleValue());
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    int size = in.readInt();
+    initialize(size);
+    for (int i = 0; i < size; ++i) {
+      int row = in.readInt();
+      double value = in.readDouble();
+      entries.put(row, value);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVectorSumAggregator.java
new file mode 100644
index 0000000..252674a
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/DoubleSparseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The double vector aggregator is used to aggregate double vectors.
+ */
+public class DoubleSparseVectorSumAggregator extends
+    BasicAggregator<DoubleSparseVector> {
+
+  @Override
+  public DoubleSparseVector createInitialValue() {
+    return new DoubleSparseVector();
+  }
+
+  @Override
+  public void aggregate(DoubleSparseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrix.java
new file mode 100644
index 0000000..a54ae31
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrix.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+/**
+ * A float matrix holds the values of the entries in float vectors. It keeps one
+ * float aggregator per matrix row.
+ */
+public class FloatSparseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The rows of the matrix */
+  private Int2ObjectOpenHashMap<FloatSparseVector> rows;
+
+  /**
+   * Create a new matrix with the given number of rows.
+   *
+   * @param numRows the number of rows.
+   */
+  public FloatSparseMatrix(int numRows) {
+    this.numRows = numRows;
+    rows = new Int2ObjectOpenHashMap<FloatSparseVector>(numRows);
+    rows.defaultReturnValue(null);
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      setRow(i, new FloatSparseVector());
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows.
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public float get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, float v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  FloatSparseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Set the float vector as the row specified.
+   *
+   * @param i the row
+   * @param vec the vector to set as the row
+   */
+  void setRow(int i, FloatSparseVector vec) {
+    rows.put(i, vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrixSumAggregator.java
new file mode 100644
index 0000000..6e78360
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseMatrixSumAggregator.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The float matrix aggregator is used to register and aggregate float matrices.
+ */
+public class FloatSparseMatrixSumAggregator extends MatrixSumAggregator {
+  /** sparse vector with single entry */
+  private FloatSparseVector singletonVector = new FloatSparseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public FloatSparseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the float vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      master.registerAggregator(getRowAggregatorName(i),
+          FloatSparseVectorSumAggregator.class);
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, float v, WorkerAggregatorUsage worker) {
+    singletonVector.clear();
+    singletonVector.set(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external FloatMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(FloatSparseMatrix matrix,
+      MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the float matrix
+   */
+  public FloatSparseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    FloatSparseMatrix matrix = new FloatSparseMatrix(numRows);
+    for (int i = 0; i < numRows; ++i) {
+      FloatSparseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.setRow(i, vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVector.java
new file mode 100644
index 0000000..4e94217
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVector.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2FloatMap;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
+
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The float vector holds the values of a particular row.
+ */
+public class FloatSparseVector implements Writable {
+  /**
+   * The entries of the vector are (key, value) pairs of the form (row, value)
+   */
+  private Int2FloatOpenHashMap entries = null;
+
+  /**
+   * Create a new vector with default size.
+   */
+  public FloatSparseVector() {
+    initialize(Int2FloatOpenHashMap.DEFAULT_INITIAL_SIZE);
+  }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public FloatSparseVector(int size) {
+    initialize(size);
+  }
+
+  /**
+   * Initialize the values of the vector. The default value is 0.0
+   *
+   * @param size the size of the vector
+   */
+  private void initialize(int size) {
+    entries = new Int2FloatOpenHashMap(size);
+    entries.defaultReturnValue(0.0f);
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public float get(int i) {
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, float value) {
+    entries.put(i, value);
+  }
+
+  /**
+   * Clear the contents of the vector.
+   */
+  public void clear() {
+    entries.clear();
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(FloatSparseVector other) {
+    for (Int2FloatMap.Entry entry : other.entries.int2FloatEntrySet()) {
+      entries.addTo(entry.getIntKey(), entry.getFloatValue());
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(entries.size());
+    for (Int2FloatMap.Entry entry : entries.int2FloatEntrySet()) {
+      out.writeInt(entry.getIntKey());
+      out.writeFloat(entry.getFloatValue());
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    int size = in.readInt();
+    initialize(size);
+    for (int i = 0; i < size; ++i) {
+      int row = in.readInt();
+      float value = in.readFloat();
+      entries.put(row, value);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVectorSumAggregator.java
new file mode 100644
index 0000000..96b1fce
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/FloatSparseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The float vector aggregator is used to aggregate float vectors.
+ */
+public class FloatSparseVectorSumAggregator extends
+    BasicAggregator<FloatSparseVector> {
+
+  @Override
+  public FloatSparseVector createInitialValue() {
+    return new FloatSparseVector();
+  }
+
+  @Override
+  public void aggregate(FloatSparseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrix.java
new file mode 100644
index 0000000..b7cde77
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrix.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+/**
+ * A int matrix holds the values of the entries in int vectors. It keeps one
+ * int aggregator per matrix row.
+ */
+public class IntSparseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The rows of the matrix */
+  private Int2ObjectOpenHashMap<IntSparseVector> rows;
+
+  /**
+   * Create a new matrix with the given number of rows.
+   *
+   * @param numRows the number of rows.
+   */
+  public IntSparseMatrix(int numRows) {
+    this.numRows = numRows;
+    rows = new Int2ObjectOpenHashMap<IntSparseVector>(numRows);
+    rows.defaultReturnValue(null);
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      setRow(i, new IntSparseVector());
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows.
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public int get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, int v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  IntSparseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Set the int vector as the row specified.
+   *
+   * @param i the row
+   * @param vec the vector to set as the row
+   */
+  void setRow(int i, IntSparseVector vec) {
+    rows.put(i, vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrixSumAggregator.java
new file mode 100644
index 0000000..5299000
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseMatrixSumAggregator.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The int matrix aggregator is used to register and aggregate int matrices.
+ */
+public class IntSparseMatrixSumAggregator extends MatrixSumAggregator {
+  /** sparse vector with single entry */
+  private IntSparseVector singletonVector = new IntSparseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public IntSparseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the int vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      master.registerAggregator(getRowAggregatorName(i),
+          IntSparseVectorSumAggregator.class);
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, int v, WorkerAggregatorUsage worker) {
+    singletonVector.clear();
+    singletonVector.set(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external IntMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(IntSparseMatrix matrix, MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the int matrix
+   */
+  public IntSparseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    IntSparseMatrix matrix = new IntSparseMatrix(numRows);
+    for (int i = 0; i < numRows; ++i) {
+      IntSparseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.setRow(i, vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVector.java
new file mode 100644
index 0000000..2482bd2
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVector.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2IntMap;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
+
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The int vector holds the values of a particular row.
+ */
+public class IntSparseVector implements Writable {
+  /**
+   * The entries of the vector are (key, value) pairs of the form (row, value)
+   */
+  private Int2IntOpenHashMap entries = null;
+
+  /**
+   * Create a new vector with default size.
+   */
+  public IntSparseVector() {
+    initialize(Int2IntOpenHashMap.DEFAULT_INITIAL_SIZE);
+  }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public IntSparseVector(int size) {
+    initialize(size);
+  }
+
+  /**
+   * Initialize the values of the vector. The default value is 0.0
+   *
+   * @param size the size of the vector
+   */
+  private void initialize(int size) {
+    entries = new Int2IntOpenHashMap(size);
+    entries.defaultReturnValue(0);
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public int get(int i) {
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, int value) {
+    entries.put(i, value);
+  }
+
+  /**
+   * Clear the contents of the vector.
+   */
+  public void clear() {
+    entries.clear();
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(IntSparseVector other) {
+    for (Int2IntMap.Entry entry : other.entries.int2IntEntrySet()) {
+      entries.addTo(entry.getIntKey(), entry.getIntValue());
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(entries.size());
+    for (Int2IntMap.Entry entry : entries.int2IntEntrySet()) {
+      out.writeInt(entry.getIntKey());
+      out.writeInt(entry.getIntValue());
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    int size = in.readInt();
+    initialize(size);
+    for (int i = 0; i < size; ++i) {
+      int row = in.readInt();
+      int value = in.readInt();
+      entries.put(row, value);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVectorSumAggregator.java
new file mode 100644
index 0000000..090e695
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/IntSparseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The float vector aggregator is used to aggregate float vectors.
+ */
+public class IntSparseVectorSumAggregator extends
+    BasicAggregator<IntSparseVector> {
+
+  @Override
+  public IntSparseVector createInitialValue() {
+    return new IntSparseVector();
+  }
+
+  @Override
+  public void aggregate(IntSparseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrix.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrix.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrix.java
new file mode 100644
index 0000000..8faea07
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrix.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+/**
+ * A long matrix holds the values of the entries in long vectors. It keeps one
+ * long aggregator per matrix row.
+ */
+public class LongSparseMatrix {
+  /** The number of rows in the matrix */
+  private int numRows;
+  /** The rows of the matrix */
+  private Int2ObjectOpenHashMap<LongSparseVector> rows;
+
+  /**
+   * Create a new matrix with the given number of rows.
+   *
+   * @param numRows the number of rows.
+   */
+  public LongSparseMatrix(int numRows) {
+    this.numRows = numRows;
+    rows = new Int2ObjectOpenHashMap<LongSparseVector>(numRows);
+    rows.defaultReturnValue(null);
+  }
+
+  /**
+   * Create a empty matrix with all values set to 0.0
+   */
+  public void initialize() {
+    rows.clear();
+    for (int i = 0; i < numRows; ++i) {
+      setRow(i, new LongSparseVector());
+    }
+  }
+
+  /**
+   * Get the number of rows in the matrix.
+   *
+   * @return the number of rows.
+   */
+  public int getNumRows() {
+    return numRows;
+  }
+
+  /**
+   * Get a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @return the value of the entry
+   */
+  public long get(int i, int j) {
+    return rows.get(i).get(j);
+  }
+
+  /**
+   * Set a specific entry of the matrix.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value of the entry
+   */
+  public void set(int i, int j, long v) {
+    rows.get(i).set(j, v);
+  }
+
+  /**
+   * Get a specific row of the matrix.
+   *
+   * @param i the row number
+   * @return the row of the matrix
+   */
+  LongSparseVector getRow(int i) {
+    return rows.get(i);
+  }
+
+  /**
+   * Set the long vector as the row specified.
+   *
+   * @param i the row
+   * @param vec the vector to set as the row
+   */
+  void setRow(int i, LongSparseVector vec) {
+    rows.put(i, vec);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrixSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrixSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrixSumAggregator.java
new file mode 100644
index 0000000..7ccb8cb
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseMatrixSumAggregator.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.AggregatorUsage;
+import org.apache.giraph.aggregators.matrix.MatrixSumAggregator;
+import org.apache.giraph.master.MasterAggregatorUsage;
+import org.apache.giraph.worker.WorkerAggregatorUsage;
+
+/**
+ * The long matrix aggregator is used to register and aggregate long matrices.
+ */
+public class LongSparseMatrixSumAggregator extends MatrixSumAggregator {
+  /** sparse vector with single entry */
+  private LongSparseVector singletonVector = new LongSparseVector();
+
+  /**
+   * Create a new matrix aggregator with the given prefix name for the vector
+   * aggregators.
+   *
+   * @param name the prefix for the row vector aggregators
+   */
+  public LongSparseMatrixSumAggregator(String name) {
+    super(name);
+  }
+
+  /**
+   * Register the long vector aggregators, one for each row of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param master the master to register the aggregators
+   */
+  public void register(int numRows, MasterAggregatorUsage master)
+    throws InstantiationException, IllegalAccessException {
+    for (int i = 0; i < numRows; ++i) {
+      master.registerAggregator(getRowAggregatorName(i),
+          LongSparseVectorSumAggregator.class);
+    }
+  }
+
+  /**
+   * Add the given value to the entry specified.
+   *
+   * @param i the row
+   * @param j the column
+   * @param v the value
+   * @param worker the worker to aggregate
+   */
+  public void aggregate(int i, int j, long v, WorkerAggregatorUsage worker) {
+    singletonVector.clear();
+    singletonVector.set(j, v);
+    worker.aggregate(getRowAggregatorName(i), singletonVector);
+  }
+
+  /**
+   * Set the values of the matrix to the master specified. This is typically
+   * used in the master, to build an external LongMatrix and only set it at
+   * the end.
+   *
+   * @param matrix the matrix to set the values
+   * @param master the master
+   */
+  public void setMatrix(LongSparseMatrix matrix,
+      MasterAggregatorUsage master) {
+    int numRows = matrix.getNumRows();
+    for (int i = 0; i < numRows; ++i) {
+      master.setAggregatedValue(getRowAggregatorName(i), matrix.getRow(i));
+    }
+  }
+
+  /**
+   * Read the aggregated values of the matrix.
+   *
+   * @param numRows the number of rows
+   * @param aggUser the master or worker
+   * @return the long matrix
+   */
+  public LongSparseMatrix getMatrix(int numRows, AggregatorUsage aggUser) {
+    LongSparseMatrix matrix = new LongSparseMatrix(numRows);
+    for (int i = 0; i < numRows; ++i) {
+      LongSparseVector vec = aggUser.getAggregatedValue(
+          getRowAggregatorName(i));
+      matrix.setRow(i, vec);
+    }
+    return matrix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVector.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVector.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVector.java
new file mode 100644
index 0000000..8ab52a9
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVector.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import it.unimi.dsi.fastutil.ints.Int2LongMap;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;
+
+import org.apache.hadoop.io.Writable;
+
+/**
+ * The long vector holds the values of a particular row.
+ */
+public class LongSparseVector implements Writable {
+  /**
+   * The entries of the vector are (key, value) pairs of the form (row, value)
+   */
+  private Int2LongOpenHashMap entries = null;
+
+  /**
+   * Create a new vector with default size.
+   */
+  public LongSparseVector() {
+    initialize(Int2LongOpenHashMap.DEFAULT_INITIAL_SIZE);
+  }
+
+  /**
+   * Create a new vector with given size.
+   *
+   * @param size the size of the vector
+   */
+  public LongSparseVector(int size) {
+    initialize(size);
+  }
+
+  /**
+   * Initialize the values of the vector. The default value is 0.0
+   *
+   * @param size the size of the vector
+   */
+  private void initialize(int size) {
+    entries = new Int2LongOpenHashMap(size);
+    entries.defaultReturnValue(0L);
+  }
+
+  /**
+   * Get a particular entry of the vector.
+   *
+   * @param i the entry
+   * @return the value of the entry.
+   */
+  public long get(int i) {
+    return entries.get(i);
+  }
+
+  /**
+   * Set the given value to the entry specified.
+   *
+   * @param i the entry
+   * @param value the value to set to the entry
+   */
+  public void set(int i, long value) {
+    entries.put(i, value);
+  }
+
+  /**
+   * Clear the contents of the vector.
+   */
+  public void clear() {
+    entries.clear();
+  }
+
+  /**
+   * Add the vector specified. This is a vector addition that does an
+   * element-by-element addition.
+   *
+   * @param other the vector to add.
+   */
+  public void add(LongSparseVector other) {
+    for (Int2LongMap.Entry kv : other.entries.int2LongEntrySet()) {
+      entries.addTo(kv.getIntKey(), kv.getLongValue());
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(entries.size());
+    for (Int2LongMap.Entry kv : entries.int2LongEntrySet()) {
+      out.writeInt(kv.getIntKey());
+      out.writeLong(kv.getLongValue());
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    int size = in.readInt();
+    initialize(size);
+    for (int i = 0; i < size; ++i) {
+      int row = in.readInt();
+      long value = in.readLong();
+      entries.put(row, value);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/af21be3b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVectorSumAggregator.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVectorSumAggregator.java b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVectorSumAggregator.java
new file mode 100644
index 0000000..57fe119
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/aggregators/matrix/sparse/LongSparseVectorSumAggregator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph.aggregators.matrix.sparse;
+
+import org.apache.giraph.aggregators.BasicAggregator;
+
+/**
+ * The long vector aggregator is used to aggregate long vectors.
+ */
+public class LongSparseVectorSumAggregator extends
+    BasicAggregator<LongSparseVector> {
+
+  @Override
+  public LongSparseVector createInitialValue() {
+    return new LongSparseVector();
+  }
+
+  @Override
+  public void aggregate(LongSparseVector vector) {
+    getAggregatedValue().add(vector);
+  }
+}