src/java/org/apache/hama/matrix/SparseVector.java
this(new MapWritable());
public SparseVector()
MapWritable m
src/java/org/apache/hama/matrix/SparseVector.java
this.entries = m;
public SparseVector(MapWritable m)
RowResult row
src/java/org/apache/hama/matrix/SparseVector.java
this.initMap(row);
public SparseVector(RowResult row)
double alpha  Vector v
src/java/org/apache/hama/matrix/SparseVector.java
if (alpha == 0)
      return this;

    for (Map.Entry<Writable, Writable> e : v.getEntries().entrySet()) {
      if (this.entries.containsKey(e.getKey())) {
        // add
        double value = alpha * ((DoubleEntry) e.getValue()).getValue()
            + this.get(((IntWritable) e.getKey()).get());
        this.entries.put(e.getKey(), new DoubleEntry(value));
Vector add(double alpha, Vector v)
Vector v2
src/java/org/apache/hama/matrix/SparseVector.java
for (Map.Entry<Writable, Writable> e : v2.getEntries().entrySet()) {
      int key = ((IntWritable) e.getKey()).get();
      if (this.entries.containsKey(e.getKey())) {
        this.add(key, ((DoubleEntry) e.getValue()).getValue());
SparseVector add(Vector v2)
Vector v
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return 0;
double dot(Vector v)
Norm type
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return 0;
double norm(Norm type)
double alpha
src/java/org/apache/hama/matrix/SparseVector.java
for (Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue())
          .getValue()
          * alpha));
SparseVector scale(double alpha)
int index
src/java/org/apache/hama/matrix/SparseVector.java
double value;
    try {
      value = ((DoubleEntry) this.entries.get(new IntWritable(index)))
          .getValue();
double get(int index)
int index  double value
src/java/org/apache/hama/matrix/SparseVector.java
// If entries are null, create new object
    if (this.entries == null) {
      this.entries = new MapWritable();
void set(int index, double value)
int index  double value
src/java/org/apache/hama/matrix/SparseVector.java
set(index, get(index) + value);
void add(int index, double value)
Vector v
src/java/org/apache/hama/matrix/SparseVector.java
return new SparseVector(v.getEntries());
SparseVector set(Vector v)
int i0  int i1
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return null;
Vector subVector(int i0, int i1)
double alpha  Vector v
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return null;
Vector set(double alpha, Vector v)
src/test/org/apache/hama/mapred/TestBlockMatrixMapReduce.java
super();
public TestBlockMatrixMapReduce()
src/test/org/apache/hama/matrix/TestDenseVector.java
v2.scale(0.5);

    for (int i = 0; i < v2.size(); i++) {
      assertEquals(values[1][i] * 0.5, v2.get(i));
void scalingTest()
src/test/org/apache/hama/matrix/TestDenseVector.java
v1.add(v2);
    int i = 0;
    Iterator<Writable> it = v1.iterator();
    while (it.hasNext()) {
      DoubleEntry c = (DoubleEntry) it.next();
      assertEquals(c.getValue(), values[0][i] + values[1][i]);
      i++;
void add()
src/test/org/apache/hama/matrix/TestDenseVector.java
v1.set(v2);

    for(int i = 0; i < v1.size(); i ++) {
      assertEquals(v2.get(i), v1.get(i));
void setTest()
src/test/org/apache/hama/matrix/TestDenseVector.java
int start = 2;
    Vector subVector = v1.subVector(start, v1.size() - 1);
    Iterator<Writable> it = subVector.iterator();

    int i = start;
    while (it.hasNext()) {
      assertEquals(v1.get(i), ((DoubleEntry) it.next()).getValue());
      i++;
void subVector()
src/test/org/apache/hama/matrix/TestDenseVector.java
((DenseVector) v1).clear();
    assertEquals(v1.size(), 0);
void clear()
src/java/org/apache/hama/matrix/SparseVector.java
this(new MapWritable());
public SparseVector()
MapWritable m
src/java/org/apache/hama/matrix/SparseVector.java
this.entries = m;
public SparseVector(MapWritable m)
RowResult row
src/java/org/apache/hama/matrix/SparseVector.java
this.initMap(row);
public SparseVector(RowResult row)
double alpha  Vector v
src/java/org/apache/hama/matrix/SparseVector.java
if (alpha == 0)
      return this;

    for (Map.Entry<Writable, Writable> e : v.getEntries().entrySet()) {
      if (this.entries.containsKey(e.getKey())) {
        // add
        double value = alpha * ((DoubleEntry) e.getValue()).getValue()
            + this.get(((IntWritable) e.getKey()).get());
        this.entries.put(e.getKey(), new DoubleEntry(value));
Vector add(double alpha, Vector v)
Vector v2
src/java/org/apache/hama/matrix/SparseVector.java
for (Map.Entry<Writable, Writable> e : v2.getEntries().entrySet()) {
      int key = ((IntWritable) e.getKey()).get();
      if (this.entries.containsKey(e.getKey())) {
        this.add(key, ((DoubleEntry) e.getValue()).getValue());
SparseVector add(Vector v2)
Vector v
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return 0;
double dot(Vector v)
Norm type
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return 0;
double norm(Norm type)
double alpha
src/java/org/apache/hama/matrix/SparseVector.java
for (Map.Entry<Writable, Writable> e : this.entries.entrySet()) {
      this.entries.put(e.getKey(), new DoubleEntry(((DoubleEntry) e.getValue())
          .getValue()
          * alpha));
SparseVector scale(double alpha)
int index
src/java/org/apache/hama/matrix/SparseVector.java
double value;
    try {
      value = ((DoubleEntry) this.entries.get(new IntWritable(index)))
          .getValue();
double get(int index)
int index  double value
src/java/org/apache/hama/matrix/SparseVector.java
// If entries are null, create new object
    if (this.entries == null) {
      this.entries = new MapWritable();
void set(int index, double value)
int index  double value
src/java/org/apache/hama/matrix/SparseVector.java
set(index, get(index) + value);
void add(int index, double value)
Vector v
src/java/org/apache/hama/matrix/SparseVector.java
return new SparseVector(v.getEntries());
SparseVector set(Vector v)
int i0  int i1
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return null;
Vector subVector(int i0, int i1)
double alpha  Vector v
src/java/org/apache/hama/matrix/SparseVector.java
// TODO Auto-generated method stub
    return null;
Vector set(double alpha, Vector v)
src/test/org/apache/hama/graph/TestGraph.java
TestSetup setup = new TestSetup(new TestSuite(TestGraph.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();
        conf = hCluster.getConf();
        adj = new SparseGraph(conf);
Test suite()
src/test/org/apache/hama/graph/TestGraph.java
void tearDown()
src/test/org/apache/hama/mapred/TestBlockMatrixMapReduce.java
super();
public TestBlockMatrixMapReduce()
src/test/org/apache/hama/matrix/TestDenseMatrix.java
TestSetup setup = new TestSetup(new TestSuite(TestDenseMatrix.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();

        conf = hCluster.getConf();
        admin = new HBaseAdmin(conf);
        hamaAdmin = new HamaAdminImpl(conf, admin);

        m1 = DenseMatrix.random(hCluster.getConf(), SIZE, SIZE);
        m2 = DenseMatrix.random(hCluster.getConf(), SIZE, SIZE);
        m3 = DenseMatrix.random(hCluster.getConf(), SIZE, SIZE);
        m4 = DenseMatrix.random(hCluster.getConf(), SIZE-2, SIZE-2);
        m5 = DenseMatrix.random(hCluster.getConf(), SIZE, SIZE);
Test suite()
src/test/org/apache/hama/matrix/TestDenseMatrix.java
try {
          closeTest();
void tearDown()
int i = 0; i < 3; i++
src/test/org/apache/hama/matrix/TestDenseMatrix.java
for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 4; k++) {
          C[i][j] += m1.get(i + 2, k + 2) * m2.get(k, j);
B
    for (int i = 0; i < 3; i++)
i=0; i<SIZE; i++
src/test/org/apache/hama/matrix/TestDenseMatrix.java
for(j=0; j<SIZE; j++) {
        E[i][j] = 0;
changed
    for(i=0; i<SIZE; i++)
state != 0 && loops > 0
src/test/org/apache/hama/matrix/TestDenseMatrix.java
// find index(k, l) for pivot p
      m = 0;
      for(k = 1; k <= SIZE-2; k++) {
        if(Math.abs(S[m][ind[m]]) < Math.abs(S[k][ind[k]])) {
          m = k;
rotation
    while(state != 0 && loops > 0)
i = 0; i < SIZE; i++
src/test/org/apache/hama/matrix/TestDenseMatrix.java
e1 = E[k][i];
        e2 = E[l][i];
        
        E[k][i] = c * e1 - s * e2;
        E[l][i] = s * e1 + c * e2;
eigenvectors
      for(i = 0; i < SIZE; i++)
src/test/org/apache/hama/matrix/TestDenseMatrix.java
try {
      m1.add(m4);
      fail("Matrix-Addition should be failed while rows and columns aren't same.");
void testEnsureForAddition()
src/test/org/apache/hama/matrix/TestDenseMatrix.java
try {
      m1.mult(m4);
      fail("Matrix-Mult should be failed while A.columns!=B.rows.");
void testEnsureForMultiplication()
double[][] S  int row  int size
src/test/org/apache/hama/matrix/TestDenseMatrix.java
int m = row + 1;
    for(int i=row + 2; i<size; i++) {
      if(Math.abs(S[row][i]) > Math.abs(S[row][m]))
        m = i;
int maxind(double[][] S, int row, int size)
double[] e  boolean[] changed  int row  double value  int state
src/test/org/apache/hama/matrix/TestDenseMatrix.java
double y = e[row];
    e[row] += value;
    
    if(changed[row] && y == e[row]) {
      changed[row] = false;
      return state - 1;
int update(double[] e, boolean[] changed, int row, double value, int state)
!changed[row] && y != e[row]
src/test/org/apache/hama/matrix/TestDenseMatrix.java
changed[row] = true;
      return state + 1;
else if(!changed[row] && y != e[row])
double[][] S  int k  int l  int i  int j  double c  double s
src/test/org/apache/hama/matrix/TestDenseMatrix.java
double s1 = S[k][l], s2 = S[i][j];
    S[k][l] = c * s1 - s * s2;
    S[i][j] = s * s1 + c * s2;
void rotate(double[][] S, int k, int l, int i, int j, double c, double s)
src/test/org/apache/hama/matrix/TestDenseVector.java
TestSetup setup = new TestSetup(new TestSuite(TestDenseVector.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();

        m1 = new DenseMatrix(hCluster.getConf(), 2, 4);

        for (int i = 0; i < 2; i++)
          for (int j = 0; j < 4; j++)
            m1.set(i, j, values[i][j]);

        v1 = m1.getRow(0);
        v2 = m1.getRow(1);
        smallSize.set(0, 0.5);
Test suite()
src/test/org/apache/hama/matrix/TestDenseVector.java
LOG.info("tearDown()");
void tearDown()
src/test/org/apache/hama/matrix/TestDenseVector.java
double cos = v1.dot(v2);
    assertEquals(cos, cosine);
    
    boolean except = false;
    try {
      v1.dot(smallSize);
void testDot()
src/test/org/apache/hama/matrix/TestDenseVector.java
int start = 2;
    Vector subVector = v1.subVector(start, v1.size() - 1);
    Iterator<Writable> it = subVector.iterator();

    int i = start;
    while (it.hasNext()) {
      assertEquals(v1.get(i), ((DoubleEntry) it.next()).getValue());
      i++;
void testSubVector()
src/test/org/apache/hama/matrix/TestDenseVector.java
assertEquals(norm1, v1.norm(Vector.Norm.One));
void testNom1()
src/test/org/apache/hama/matrix/TestDenseVector.java
assertEquals(norm2, v1.norm(Vector.Norm.Two));
void testNom2()
src/test/org/apache/hama/matrix/TestDenseVector.java
assertEquals(normInf, v1.norm(Vector.Norm.Infinity));
void testNormInf()
src/test/org/apache/hama/matrix/TestDenseVector.java
assertEquals(norm2Robust, v1.norm(Vector.Norm.TwoRobust));
void testNorm2Robust()
src/test/org/apache/hama/matrix/TestDenseVector.java
v2.scale(0.5);

    for (int i = 0; i < v2.size(); i++) {
      assertEquals(values[1][i] * 0.5, v2.get(i));
void scalingTest()
src/test/org/apache/hama/matrix/TestDenseVector.java
v1.add(v2);
    int i = 0;
    Iterator<Writable> it = v1.iterator();
    while (it.hasNext()) {
      DoubleEntry c = (DoubleEntry) it.next();
      assertEquals(c.getValue(), values[0][i] + values[1][i]);
      i++;
void testAdd()
src/test/org/apache/hama/matrix/TestDenseVector.java
v1.set(v2);
    
    for(int i = 0; i < v1.size(); i ++) {
      assertEquals(v2.get(i), v1.get(i));
void testSet()
src/test/org/apache/hama/matrix/TestDenseVector.java
((DenseVector) v1).clear();
    assertEquals(v1.size(), 0);
void testClear()
src/test/org/apache/hama/matrix/TestMatrixVectorMult.java
TestSetup setup = new TestSetup(new TestSuite(TestMatrixVectorMult.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();
        conf = hCluster.getConf();
        m1 = new DenseMatrix(conf, "A", true);
        m1.setDimension(2, 2);
        m1.set(0, 0, 1);
        m1.set(0, 1, 2);
        m1.set(1, 0, 3);
        m1.set(1, 1, 4);
        m2 = new DenseMatrix(conf, "B", true);
        m2.setDimension(2, 1);
        m2.set(0, 0, 1);
        m2.set(1, 0, 2);
Test suite()
src/test/org/apache/hama/matrix/TestMatrixVectorMult.java
try {
          closeTest();
void tearDown()
src/test/org/apache/hama/matrix/TestSingularValueDecomposition.java
TestSetup setup = new TestSetup(new TestSuite(TestSingularValueDecomposition.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();
        conf = hCluster.getConf();
        m1 = new DenseMatrix(conf, 2, 2);
        for (int i = 0; i < 2; i++)
          for (int j = 0; j < 2; j++)
            m1.set(i, j, matrixA[i][j]);
Test suite()
src/test/org/apache/hama/matrix/TestSingularValueDecomposition.java
// do nothing
void tearDown()
src/test/org/apache/hama/matrix/TestSparseMatrix.java
TestSetup setup = new TestSetup(new TestSuite(TestSparseMatrix.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();

        m1 = SparseMatrix.random(hCluster.getConf(), SIZE, SIZE);
        m2 = SparseMatrix.random(hCluster.getConf(), SIZE, SIZE);
Test suite()
src/test/org/apache/hama/matrix/TestSparseMatrix.java
try {
          closeTest();
void tearDown()
src/test/org/apache/hama/matrix/TestSparseVector.java
TestSetup setup = new TestSetup(new TestSuite(TestSparseVector.class)) {
      protected void setUp() throws Exception {
        HCluster hCluster = new HCluster();
        hCluster.setUp();
        m1 = new SparseMatrix(hCluster.getConf(), 2, 4);
        for (int i = 0; i < 2; i++)
          for (int j = 0; j < 4; j++)
            m1.set(i, j, values[i][j]);
        v1 = m1.getRow(0);
        v2 = m1.getRow(1);
Test suite()
src/test/org/apache/hama/matrix/TestSparseVector.java
LOG.info("tearDown()");
void tearDown()