giraph-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apre...@apache.org
Subject [2/3] GIRAPH-753: Efficient dense matrix aggregators (herald via apresta)
Date Wed, 11 Sep 2013 23:42:36 GMT
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);
+  }
+}


Mime
View raw message