Index: src/java/org/apache/hama/io/VectorUpdate.java =================================================================== --- src/java/org/apache/hama/io/VectorUpdate.java (revision 915255) +++ src/java/org/apache/hama/io/VectorUpdate.java (working copy) @@ -1,92 +0,0 @@ -/** - * Copyright 2007 The Apache Software Foundation - * - * 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.hama.io; - -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.io.DoubleWritable; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.MapWritable; -import org.apache.hadoop.io.Writable; -import org.apache.hama.Constants; -import org.apache.hama.util.BytesUtil; - -public class VectorUpdate { - private Put put; - - public VectorUpdate(int i) { - this.put = new Put(BytesUtil.getRowIndex(i)); - } - - public VectorUpdate(String row) { - this.put = new Put(Bytes.toBytes(row)); - } - - public VectorUpdate(byte[] row) { - this.put = new Put(row); - } - - public void put(int j, double value) { - this.put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(j)), - Bytes.toBytes(value)); - } - - public void put(String cfName, int j, double value) { - this.put.add(Bytes.toBytes(cfName), Bytes.toBytes(String.valueOf(j)), Bytes - .toBytes(value)); - } - - public void put(String column, String qualifier, String val) { - this.put.add(Bytes.toBytes(column), Bytes.toBytes(qualifier), Bytes - .toBytes(val)); - } - - public void put(String column, String qualifier, double val) { - this.put.add(Bytes.toBytes(column), Bytes.toBytes(qualifier), Bytes - .toBytes(val)); - } - - public void putAll(Map buffer) { - for (Map.Entry f : buffer.entrySet()) { - put(f.getKey(), f.getValue()); - } - } - - public void putAll(Set> entrySet) { - for (Map.Entry e : entrySet) { - put(e.getKey(), e.getValue().get()); - } - } - - public void putAll(MapWritable entries) { - for (Map.Entry e : entries.entrySet()) { - put(((IntWritable) e.getKey()).get(), ((DoubleWritable) e.getValue()) - .get()); - } - } - - public Put getPut() { - return this.put; - } -} Index: src/java/org/apache/hama/mapreduce/RandomMatrixReducer.java =================================================================== --- src/java/org/apache/hama/mapreduce/RandomMatrixReducer.java (revision 915255) +++ src/java/org/apache/hama/mapreduce/RandomMatrixReducer.java (working copy) @@ -1,13 +1,17 @@ package org.apache.hama.mapreduce; import java.io.IOException; +import java.util.Map; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hama.io.VectorUpdate; +import org.apache.hama.Constants; import org.apache.hama.util.BytesUtil; import org.apache.log4j.Logger; @@ -17,9 +21,14 @@ public void reduce(IntWritable key, Iterable values, Context context) throws IOException, InterruptedException { - VectorUpdate update = new VectorUpdate(key.get()); - update.putAll(values.iterator().next()); + Put put = new Put(BytesUtil.getRowIndex(key.get())); + for (Map.Entry e : values.iterator().next().entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } + context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - update.getPut()); + put); } } Index: src/java/org/apache/hama/mapreduce/RotationInputFormat.java =================================================================== --- src/java/org/apache/hama/mapreduce/RotationInputFormat.java (revision 915255) +++ src/java/org/apache/hama/mapreduce/RotationInputFormat.java (working copy) @@ -12,6 +12,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; @@ -25,7 +26,6 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext; import org.apache.hadoop.util.StringUtils; import org.apache.hama.Constants; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.util.BytesUtil; public class RotationInputFormat extends @@ -169,7 +169,8 @@ } double s1, s2; - VectorUpdate bu; + Put put; + boolean hasMore = vv != null && vv.size() > 0; if (hasMore) { byte[] row = vv.getRow(); @@ -183,13 +184,15 @@ Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(pivotcol)))); - bu = new VectorUpdate(rowId); - bu.put(Constants.EICOL, pivotrow, pivotcos * s1 - - pivotsin * s2); - bu.put(Constants.EICOL, pivotcol, pivotsin * s1 - + pivotcos * s2); + put = new Put(BytesUtil.getRowIndex(rowId)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(pivotrow)), Bytes.toBytes(new Double(pivotcos * s1 + - pivotsin * s2))); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(pivotcol)), Bytes.toBytes(new Double(pivotsin * s1 + + pivotcos * s2))); - htable.put(bu.getPut()); + htable.put(put); } else if (rowId == pivotrow) { return true; } else if (rowId < pivotcol) { @@ -203,15 +206,17 @@ Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(pivotcol)))); - bu = new VectorUpdate(rowId); - bu.put(Constants.EICOL, pivotcol, pivotsin * s1 - + pivotcos * s2); - htable.put(bu.getPut()); + put = new Put(BytesUtil.getRowIndex(rowId)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(pivotcol)), Bytes.toBytes(new Double(pivotsin * s1 + + pivotcos * s2))); + htable.put(put); - bu = new VectorUpdate(pivotrow); - bu.put(Constants.EICOL, rowId, pivotcos * s1 - pivotsin - * s2); - htable.put(bu.getPut()); + put = new Put(BytesUtil.getRowIndex(pivotrow)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(rowId)), Bytes.toBytes(new Double(pivotcos * s1 + - pivotsin * s2))); + htable.put(put); } else if (rowId == pivotcol) { for (int i = pivotcol + 1; i < size; i++) { @@ -226,15 +231,18 @@ Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(i)))); - bu = new VectorUpdate(pivotcol); - bu.put(Constants.EICOL, i, pivotsin * s1 + pivotcos - * s2); - htable.put(bu.getPut()); + put = new Put(BytesUtil.getRowIndex(pivotcol)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(i)), Bytes.toBytes(new Double(pivotsin * s1 + pivotcos + * s2))); + htable.put(put); - bu = new VectorUpdate(pivotrow); - bu.put(Constants.EICOL, i, pivotcos * s1 - pivotsin - * s2); - htable.put(bu.getPut()); + put = new Put(BytesUtil.getRowIndex(pivotrow)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String + .valueOf(i)), Bytes.toBytes(new Double(pivotcos * s1 - pivotsin + * s2))); + htable.put(put); + } } else { // rowId > pivotcol return false; Index: src/java/org/apache/hama/matrix/AbstractMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/AbstractMatrix.java (revision 915255) +++ src/java/org/apache/hama/matrix/AbstractMatrix.java (working copy) @@ -53,7 +53,6 @@ import org.apache.hama.HamaAdmin; import org.apache.hama.HamaAdminImpl; import org.apache.hama.HamaConfiguration; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.matrix.algebra.MatrixNormMapReduce; import org.apache.hama.matrix.algebra.TransposeMap; import org.apache.hama.matrix.algebra.TransposeReduce; @@ -381,9 +380,10 @@ /** {@inheritDoc} */ public void setRowLabel(int row, String name) throws IOException { - VectorUpdate update = new VectorUpdate(row); - update.put(Bytes.toString(Constants.ATTRIBUTE), "string", name); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(row)); + put.add(Constants.ATTRIBUTE, Bytes.toBytes("string"), Bytes + .toBytes(name)); + table.put(put); } /** {@inheritDoc} */ @@ -397,9 +397,10 @@ /** {@inheritDoc} */ public void add(int i, int j, double value) throws IOException { - VectorUpdate update = new VectorUpdate(i); - update.put(j, value + this.get(i, j)); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(i)); + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(j)), + Bytes.toBytes(value + this.get(i, j))); + table.put(put); } Index: src/java/org/apache/hama/matrix/DenseMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/DenseMatrix.java (revision 915255) +++ src/java/org/apache/hama/matrix/DenseMatrix.java (working copy) @@ -57,7 +57,6 @@ import org.apache.hama.HamaConfiguration; import org.apache.hama.io.BlockID; import org.apache.hama.io.Pair; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.mapreduce.CollectBlocksMapper; import org.apache.hama.mapreduce.DummyMapper; import org.apache.hama.mapreduce.PivotInputFormat; @@ -91,7 +90,7 @@ * @param m the number of rows. * @param n the number of columns. * @throws IOException throw the exception to let the user know what happend, - * if we didn't create the matrix successfully. + * if we didn't create the matrix successfully. */ public DenseMatrix(HamaConfiguration conf, int m, int n) throws IOException { setConfiguration(conf); @@ -107,8 +106,8 @@ * @param conf configuration object * @param matrixName the name of the matrix * @param force if force is true, a new matrix will be created no matter - * 'matrixName' has aliased to an existed matrix; otherwise, - * just try to load an existed matrix alised 'matrixName'. + * 'matrixName' has aliased to an existed matrix; otherwise, just try + * to load an existed matrix alised 'matrixName'. * @throws IOException */ public DenseMatrix(HamaConfiguration conf, String matrixName, boolean force) @@ -153,8 +152,8 @@ } /** - * Load a matrix from an existed matrix table whose tablename is 'matrixpath' !! - * It is an internal used for map/reduce. + * Load a matrix from an existed matrix table whose tablename is 'matrixpath' + * !! It is an internal used for map/reduce. * * @param conf configuration object * @param matrixpath @@ -182,7 +181,7 @@ * @param n the number of columns. * @param s fill the matrix with this scalar value. * @throws IOException throw the exception to let the user know what happend, - * if we didn't create the matrix successfully. + * if we didn't create the matrix successfully. */ public DenseMatrix(HamaConfiguration conf, int m, int n, double s) throws IOException { @@ -392,9 +391,10 @@ if (this.getRows() < i || this.getColumns() < j) throw new ArrayIndexOutOfBoundsException(this.getRows() + ", " + this.getColumns() + ": " + i + ", " + j); - VectorUpdate update = new VectorUpdate(i); - update.put(j, value); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(i)); + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(j)), Bytes + .toBytes(value)); + table.put(put); } /** @@ -407,10 +407,13 @@ public void setRow(int row, Vector vector) throws IOException { if (this.getRows() < row || this.getColumns() < vector.size()) throw new ArrayIndexOutOfBoundsException(row); - - VectorUpdate update = new VectorUpdate(row); - update.putAll(vector.getEntries()); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(row)); + for (Map.Entry e : vector.getEntries().entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } + table.put(put); } /** @@ -427,9 +430,10 @@ for (Map.Entry e : vector.getEntries().entrySet()) { int key = ((IntWritable) e.getKey()).get(); double value = ((DoubleWritable) e.getValue()).get(); - VectorUpdate update = new VectorUpdate(key); - update.put(column, value); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(key)); + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(column)), + Bytes.toBytes(value)); + table.put(put); } } @@ -599,8 +603,7 @@ String collectionTable = "collect_" + RandomVariable.randMatrixPath(); HTableDescriptor desc = new HTableDescriptor(collectionTable); - desc - .addFamily(new HColumnDescriptor(Bytes.toBytes(Constants.BLOCK))); + desc.addFamily(new HColumnDescriptor(Bytes.toBytes(Constants.BLOCK))); this.admin.createTable(desc); LOG.info("Collect Blocks"); @@ -798,7 +801,7 @@ final FileSystem fs = FileSystem.get(config); Pair pivotPair = new Pair(); DoubleWritable pivotWritable = new DoubleWritable(); - VectorUpdate vu; + Put put; // loop int size = this.getRows(); @@ -860,29 +863,25 @@ } fs.delete(outDir, true); fs.delete(outDir.getParent(), true); - - if(pivot_row == 0 && pivot_col == 0) + + if (pivot_row == 0 && pivot_col == 0) break; // stop the iterations - + /* - * Calculation - * - * Compute the rotation parameters of next rotation. + * Calculation Compute the rotation parameters of next rotation. */ Get get = new Get(BytesUtil.getRowIndex(pivot_row)); get.addFamily(Bytes.toBytes(Constants.EI)); Result r = table.get(get); - double e1 = Bytes.toDouble(r.getValue(Bytes - .toBytes(Constants.EI), Bytes + double e1 = Bytes.toDouble(r.getValue(Bytes.toBytes(Constants.EI), Bytes .toBytes(Constants.EIVAL))); get = new Get(BytesUtil.getRowIndex(pivot_col)); get.addFamily(Bytes.toBytes(Constants.EI)); r = table.get(get); - double e2 = Bytes.toDouble(r.getValue(Bytes - .toBytes(Constants.EI), Bytes + double e2 = Bytes.toDouble(r.getValue(Bytes.toBytes(Constants.EI), Bytes .toBytes(Constants.EIVAL))); - + y = (e2 - e1) / 2; t = Math.abs(y) + Math.sqrt(pivot * pivot + y * y); s = Math.sqrt(pivot * pivot + t * t); @@ -897,10 +896,11 @@ /* * Upate the pivot and the eigen values indexed by the pivot */ - vu = new VectorUpdate(pivot_row); - vu.put(Constants.EICOL, pivot_col, 0); - table.put(vu.getPut()); - + put = new Put(BytesUtil.getRowIndex(pivot_row)); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(pivot_col)), Bytes + .toBytes(0.0)); + table.put(put); + state = update(pivot_row, -t, state); state = update(pivot_col, t, state); @@ -939,21 +939,21 @@ for (int i = 0; i < size; i++) { get = new Get(BytesUtil.getRowIndex(pivot_row)); e1 = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EIVEC), - Bytes.toBytes(String.valueOf(i)))); + Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(i)))); get = new Get(BytesUtil.getRowIndex(pivot_col)); e2 = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EIVEC), - Bytes.toBytes(String.valueOf(i)))); + Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(i)))); - vu = new VectorUpdate(pivot_row); - vu.put(Constants.EIVEC, i, c * e1 - s * e2); - table.put(vu.getPut()); - - vu = new VectorUpdate(pivot_col); - vu.put(Constants.EIVEC, i, s * e1 + c * e2); - table.put(vu.getPut()); + put = new Put(BytesUtil.getRowIndex(pivot_row)); + put.add(Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(i)), Bytes + .toBytes(new Double(c * e1 - s * e2))); + table.put(put); + + put = new Put(BytesUtil.getRowIndex(pivot_col)); + put.add(Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(i)), Bytes + .toBytes(new Double(s * e1 + c * e2))); + table.put(put); } LOG.info("update index..."); @@ -970,14 +970,12 @@ get = new Get(BytesUtil.getRowIndex(row)); double max = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EICOL), - Bytes.toBytes(String.valueOf(m)))); + Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(m)))); double val; for (int i = row + 2; i < size; i++) { get = new Get(BytesUtil.getRowIndex(row)); val = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EICOL), - Bytes.toBytes(String.valueOf(i)))); + Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(i)))); if (Math.abs(val) > Math.abs(max)) { m = i; max = val; @@ -985,39 +983,39 @@ } } - VectorUpdate vu = new VectorUpdate(row); - vu.put(Constants.EI, "ind", String.valueOf(m)); - table.put(vu.getPut()); + Put put = new Put(BytesUtil.getRowIndex(row)); + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes("ind"), Bytes + .toBytes(String.valueOf(m))); + table.put(put); } int update(int row, double value, int state) throws IOException { Get get = new Get(BytesUtil.getRowIndex(row)); double e = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EI), - Bytes.toBytes(Constants.EIVAL))); + Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EIVAL))); int changed = BytesUtil.bytesToInt(table.get(get).getValue( - Bytes.toBytes(Constants.EI), - Bytes.toBytes("changed"))); + Bytes.toBytes(Constants.EI), Bytes.toBytes("changed"))); double y = e; e += value; - - VectorUpdate vu = new VectorUpdate(row); - vu.put(Constants.EI, Constants.EIVAL, e); + Put put = new Put(BytesUtil.getRowIndex(row)); + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EIVAL), Bytes + .toBytes(e)); + if (changed == 1 && (Math.abs(y - e) < .0000001)) { // y == e) { changed = 0; - vu.put(Constants.EI, - Constants.EICHANGED, String.valueOf(changed)); - + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EICHANGED), Bytes + .toBytes(String.valueOf(changed))); + state--; } else if (changed == 0 && (Math.abs(y - e) > .0000001)) { changed = 1; - vu.put(Constants.EI, - Constants.EICHANGED, String.valueOf(changed)); - + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EICHANGED), Bytes + .toBytes(String.valueOf(changed))); + state++; } - table.put(vu.getPut()); + table.put(put); return state; } @@ -1028,8 +1026,7 @@ Get get = null; for (int i = 0; i < e.length; i++) { get = new Get(BytesUtil.getRowIndex(i)); - e1 = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EI), + e1 = Bytes.toDouble(table.get(get).getValue(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EIVAL))); success &= ((Math.abs(e1 - e[i]) < .0000001)); if (!success) @@ -1038,8 +1035,7 @@ for (int j = 0; j < E[i].length; j++) { get = new Get(BytesUtil.getRowIndex(i)); ev = Bytes.toDouble(table.get(get).getValue( - Bytes.toBytes(Constants.EIVEC), - Bytes.toBytes(String.valueOf(j)))); + Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(j)))); success &= ((Math.abs(ev - E[i][j]) < .0000001)); if (!success) return success; Index: src/java/org/apache/hama/matrix/SparseMatrix.java =================================================================== --- src/java/org/apache/hama/matrix/SparseMatrix.java (revision 915255) +++ src/java/org/apache/hama/matrix/SparseMatrix.java (working copy) @@ -22,18 +22,21 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Random; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; import org.apache.hadoop.hbase.mapreduce.TableOutputFormat; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.SequenceFile; @@ -44,7 +47,6 @@ import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat; import org.apache.hama.Constants; import org.apache.hama.HamaConfiguration; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.mapreduce.RandomMatrixMapper; import org.apache.hama.mapreduce.RandomMatrixReducer; import org.apache.hama.matrix.algebra.SparseMatrixVectorMultMap; @@ -227,9 +229,10 @@ /** {@inheritDoc} */ public void set(int i, int j, double value) throws IOException { if (value != 0) { - VectorUpdate update = new VectorUpdate(i); - update.put(j, value); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(i)); + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(j)), + Bytes.toBytes(value)); + table.put(put); } } @@ -326,9 +329,12 @@ throw new ArrayIndexOutOfBoundsException(row); if (vector.size() > 0) { // stores if size > 0 - VectorUpdate update = new VectorUpdate(row); - update.putAll(((SparseVector) vector).getEntries()); - table.put(update.getPut()); + Put put = new Put(BytesUtil.getRowIndex(row)); + for (Map.Entry e : ((SparseVector) vector).getEntries().entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(((IntWritable) e.getKey()).get())), + Bytes.toBytes(((DoubleWritable) e.getValue()).get())); + } + table.put(put); } } Index: src/java/org/apache/hama/matrix/algebra/BlockMultReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/BlockMultReduce.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/BlockMultReduce.java (working copy) @@ -2,12 +2,14 @@ import java.io.IOException; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.Writable; +import org.apache.hama.Constants; import org.apache.hama.io.BlockID; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.matrix.SubMatrix; import org.apache.hama.util.BytesUtil; @@ -31,13 +33,14 @@ int startColumn = key.getColumn() * s.getColumns(); for (int i = 0; i < s.getRows(); i++) { - VectorUpdate update = new VectorUpdate(i + startRow); + Put put = new Put(BytesUtil.getRowIndex(i + startRow)); for (int j = 0; j < s.getColumns(); j++) { - update.put(j + startColumn, s.get(i, j)); + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String.valueOf(j + startColumn)), + Bytes.toBytes(s.get(i, j))); } context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key - .getRow())), update.getPut()); + .getRow())), put); } } } Index: src/java/org/apache/hama/matrix/algebra/DenseMatrixVectorMultReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/DenseMatrixVectorMultReduce.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/DenseMatrixVectorMultReduce.java (working copy) @@ -20,13 +20,17 @@ package org.apache.hama.matrix.algebra; import java.io.IOException; +import java.util.Map; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hama.io.VectorUpdate; +import org.apache.hama.Constants; import org.apache.hama.matrix.DenseVector; import org.apache.hama.util.BytesUtil; @@ -40,8 +44,8 @@ for (MapWritable value : values) { DenseVector nVector = new DenseVector(value); - - if(sum.size() == 0) { + + if (sum.size() == 0) { sum.zeroFill(nVector.size()); sum.add(nVector); } else { @@ -49,10 +53,14 @@ } } - VectorUpdate update = new VectorUpdate(key.get()); - update.putAll(sum.getEntries()); + Put put = new Put(BytesUtil.getRowIndex(key.get())); + for (Map.Entry e : sum.getEntries().entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - update.getPut()); + put); } -} \ No newline at end of file +} Index: src/java/org/apache/hama/matrix/algebra/JacobiInitMap.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/JacobiInitMap.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/JacobiInitMap.java (working copy) @@ -10,7 +10,6 @@ import org.apache.hadoop.hbase.mapreduce.TableMapper; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hama.Constants; -import org.apache.hama.io.VectorUpdate; import org.apache.hama.util.BytesUtil; /** @@ -32,7 +31,7 @@ throws IOException, InterruptedException { int row, col; row = BytesUtil.getRowIndex(key.get()); - VectorUpdate vu = new VectorUpdate(row); + Put put = new Put(BytesUtil.getRowIndex(row)); double val; double maxVal = Double.MIN_VALUE; @@ -46,11 +45,15 @@ val = Bytes.toDouble(e.getValue()); col = BytesUtil.bytesToInt(e.getKey()); // copy the original matrix to "EICOL" family - vu.put(Constants.EICOL, col, val); + put.add(Bytes.toBytes(Constants.EICOL), Bytes.toBytes(String.valueOf(col)), Bytes + .toBytes(val)); // make the "EIVEC" a dialog matrix - vu.put(Constants.EIVEC, col, col == row ? 1 : 0); + put.add(Bytes.toBytes(Constants.EIVEC), Bytes.toBytes(String.valueOf(col)), Bytes + .toBytes(col == row ? new Double(1) : new Double(0))); + if (col == row) { - vu.put(Constants.EI, Constants.EIVAL, val); + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EIVAL), Bytes + .toBytes(val)); } // find the max index if (col > row) { @@ -68,9 +71,12 @@ } // index array - vu.put(Constants.EI, Constants.EIIND, String.valueOf(maxInd)); + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EIIND), Bytes + .toBytes(String.valueOf(maxInd))); // Changed Array set to be true during initialization - vu.put(Constants.EI, Constants.EICHANGED, String.valueOf(1)); - context.write(key, vu.getPut()); + put.add(Bytes.toBytes(Constants.EI), Bytes.toBytes(Constants.EICHANGED), Bytes + .toBytes(String.valueOf(1))); + + context.write(key, put); } } Index: src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/MatrixAdditionReduce.java (working copy) @@ -1,28 +1,37 @@ package org.apache.hama.matrix.algebra; import java.io.IOException; +import java.util.Map; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hama.io.VectorUpdate; +import org.apache.hama.Constants; import org.apache.hama.util.BytesUtil; public class MatrixAdditionReduce extends -TableReducer { - + TableReducer { + @Override public void reduce(IntWritable key, Iterable values, Context context) throws IOException, InterruptedException { - VectorUpdate update = new VectorUpdate(key.get()); + Put put = new Put(BytesUtil.getRowIndex(key.get())); for (MapWritable value : values) { - update.putAll(value); + for (Map.Entry e : value.entrySet()) { + + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } } - + context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - update.getPut()); + put); } } Index: src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/SparseMatrixVectorMultReduce.java (working copy) @@ -20,13 +20,17 @@ package org.apache.hama.matrix.algebra; import java.io.IOException; +import java.util.Map; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hama.io.VectorUpdate; +import org.apache.hama.Constants; import org.apache.hama.matrix.SparseVector; import org.apache.hama.util.BytesUtil; @@ -42,10 +46,14 @@ sum.add(new SparseVector(value)); } - VectorUpdate update = new VectorUpdate(key.get()); - update.putAll(sum.getEntries()); + Put put = new Put(BytesUtil.getRowIndex(key.get())); + for (Map.Entry e : sum.getEntries().entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - update.getPut()); + put); } } Index: src/java/org/apache/hama/matrix/algebra/TransposeReduce.java =================================================================== --- src/java/org/apache/hama/matrix/algebra/TransposeReduce.java (revision 915255) +++ src/java/org/apache/hama/matrix/algebra/TransposeReduce.java (working copy) @@ -22,15 +22,18 @@ import java.io.IOException; import java.util.Map; +import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableReducer; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; -import org.apache.hama.io.VectorUpdate; +import org.apache.hama.Constants; import org.apache.hama.util.BytesUtil; -public class TransposeReduce extends +public class TransposeReduce extends TableReducer { @Override @@ -44,11 +47,15 @@ } } - VectorUpdate update = new VectorUpdate(key.get()); - update.putAll(sum); + Put put = new Put(BytesUtil.getRowIndex(key.get())); + for (Map.Entry e : sum.entrySet()) { + put.add(Constants.COLUMNFAMILY, Bytes.toBytes(String + .valueOf(((IntWritable) e.getKey()).get())), Bytes + .toBytes(((DoubleWritable) e.getValue()).get())); + } context.write(new ImmutableBytesWritable(BytesUtil.getRowIndex(key.get())), - update.getPut()); + put); } -} \ No newline at end of file +}