You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2008/08/13 03:57:38 UTC
svn commit: r685416 - in /incubator/hama/trunk: CHANGES.txt
src/java/org/apache/hama/Vector.java src/test/org/apache/hama/TestVector.java
Author: edwardyoon
Date: Tue Aug 12 18:57:37 2008
New Revision: 685416
URL: http://svn.apache.org/viewvc?rev=685416&view=rev
Log:
Add set() method
Modified:
incubator/hama/trunk/CHANGES.txt
incubator/hama/trunk/src/java/org/apache/hama/Vector.java
incubator/hama/trunk/src/test/org/apache/hama/TestVector.java
Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=685416&r1=685415&r2=685416&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Aug 12 18:57:37 2008
@@ -4,6 +4,7 @@
NEW FEATURES
+ HAMA-33: Add set() method (edwardyoon)
HAMA-30: Add scaling method to Vector (edwardyoon)
HAMA-25: Add matrix addition example (edwardyoon)
HAMA-23: Add Hama configuration files (edwardyoon)
Modified: incubator/hama/trunk/src/java/org/apache/hama/Vector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/Vector.java?rev=685416&r1=685415&r2=685416&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/Vector.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/Vector.java Tue Aug 12 18:57:37 2008
@@ -50,6 +50,17 @@
}
}
+ /**
+ * Get the row for this Vector
+ */
+ public byte [] getRow() {
+ return row;
+ }
+
+ public HbaseMapWritable<byte[], Cell> getCells() {
+ return cells;
+ }
+
public void add(int index, double value) {
// TODO Auto-generated method stub
@@ -98,7 +109,7 @@
}
public double get(int index) {
- return bytesToDouble(this.cells.get(getColumnIndex(index)).getValue());
+ return bytesToDouble(cells.get(getColumnIndex(index)).getValue());
}
public double norm(Norm type) {
@@ -113,13 +124,12 @@
}
public void set(int index, double value) {
- // TODO Auto-generated method stub
-
+ Cell cValue = new Cell(String.valueOf(value), System.currentTimeMillis());
+ cells.put(getColumnIndex(index), cValue);
}
public Vector set(Vector v) {
- // TODO Auto-generated method stub
- return null;
+ return new Vector(v.getRow(), v.getCells());
}
public double getNorm1() {
Modified: incubator/hama/trunk/src/test/org/apache/hama/TestVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestVector.java?rev=685416&r1=685415&r2=685416&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestVector.java Tue Aug 12 18:57:37 2008
@@ -20,9 +20,9 @@
package org.apache.hama;
public class TestVector extends HamaTestCase {
- final double cosine = 0.6978227007909176;
- final double norm1 = 12.0;
- final double norm2 = 6.782329983125268;
+ private final double cosine = 0.6978227007909176;
+ private final double norm1 = 12.0;
+ private final double norm2 = 6.782329983125268;
private double[][] values = { { 2, 5, 1, 4 }, { 4, 1, 3, 3 } };
/**
@@ -46,16 +46,16 @@
scalingTest(v2);
}
- public void dotTest(Vector v1, Vector v2) {
+ private void dotTest(Vector v1, Vector v2) {
double cos = v1.dot(v2);
assertEquals(cos, cosine);
}
- public void norm1Test(Vector v1, Vector v2) {
+ private void norm1Test(Vector v1, Vector v2) {
assertEquals(norm1, v1.getNorm1());
}
- public void norm2Test(Vector v1, Vector v2) {
+ private void norm2Test(Vector v1, Vector v2) {
assertEquals(norm2, v1.getNorm2());
}
@@ -66,4 +66,10 @@
assertEquals(values[1][i] * 0.5, v2.get(i));
}
}
+
+ public void testGetSet() {
+ Vector v1 = new Vector();
+ v1.set(0, 0.2);
+ assertEquals(v1.get(0), 0.2);
+ }
}