You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sm...@apache.org on 2015/08/01 05:26:50 UTC
[03/37] mahout git commit: MAHOUT-1693: FunctionalMatrixView
materializes row vectors in scala shell closes apache/mahout#123
MAHOUT-1693: FunctionalMatrixView materializes row vectors in scala shell closes apache/mahout#123
Project: http://git-wip-us.apache.org/repos/asf/mahout/repo
Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/2f4a51b4
Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/2f4a51b4
Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/2f4a51b4
Branch: refs/heads/mahout-0.10.x
Commit: 2f4a51b46c3e5bbee788ff26781f396a61ab0f64
Parents: 72764cf
Author: Andrew Palumbo <ap...@apache.org>
Authored: Wed Apr 22 01:01:25 2015 -0400
Committer: Andrew Palumbo <ap...@apache.org>
Committed: Wed Apr 22 01:01:25 2015 -0400
----------------------------------------------------------------------
.../org/apache/mahout/math/AbstractMatrix.java | 30 ++++++++++++++++---
.../apache/mahout/math/SparseColumnMatrix.java | 31 ++++++++++++++++++--
2 files changed, 54 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mahout/blob/2f4a51b4/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
----------------------------------------------------------------------
diff --git a/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java b/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
index 0dd084e..69dbf94 100644
--- a/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
+++ b/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
@@ -782,13 +782,35 @@ public abstract class AbstractMatrix implements Matrix {
@Override
public String toString() {
+
+ int row = 0;
+ int maxRowsToDisplay = 10;
+ int maxColsToDisplay = 20;
+ int colsToDisplay = maxColsToDisplay;
+
+ if(maxColsToDisplay > columnSize()){
+ colsToDisplay = columnSize();
+ }
+
StringBuilder s = new StringBuilder("{\n");
Iterator<MatrixSlice> it = iterator();
- while (it.hasNext()) {
+ while ((it.hasNext()) && (row < maxRowsToDisplay)) {
MatrixSlice next = it.next();
- s.append(" ").append(next.index()).append(" =>\t").append(next.vector()).append('\n');
+ s.append(" ").append(next.index())
+ .append(" =>\t")
+ .append(new VectorView(next.vector(), 0, colsToDisplay))
+ .append('\n');
+ row ++;
+ }
+
+ String returnString = s.toString();
+ if (maxColsToDisplay <= columnSize()) {
+ returnString = returnString.replace("}", " ... } ");
+ }
+ if(maxRowsToDisplay <= rowSize())
+ return returnString + ("... }");
+ else{
+ return returnString + ("}");
}
- s.append("}");
- return s.toString();
}
}
http://git-wip-us.apache.org/repos/asf/mahout/blob/2f4a51b4/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
----------------------------------------------------------------------
diff --git a/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java b/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
index b852026..f62d553 100644
--- a/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
+++ b/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
@@ -172,12 +172,37 @@ public class SparseColumnMatrix extends AbstractMatrix {
@Override
public String toString() {
+ int row = 0;
+ int maxRowsToDisplay = 10;
+ int maxColsToDisplay = 20;
+ int colsToDisplay = maxColsToDisplay;
+
+ if(maxColsToDisplay > columnSize()){
+ colsToDisplay = columnSize();
+ }
+
StringBuilder s = new StringBuilder("{\n");
for (MatrixSlice next : this.transpose()) {
- s.append(" ").append(next.index()).append(" =>\t").append(next.vector()).append('\n');
+ if (row < maxRowsToDisplay) {
+ s.append(" ")
+ .append(next.index())
+ .append(" =>\t")
+ .append(new VectorView(next.vector(), 0, colsToDisplay))
+ .append('\n');
+ row++;
+ }
+ }
+
+ String returnString = s.toString();
+ if (maxColsToDisplay <= columnSize()) {
+ returnString = returnString.replace("}", " ... }");
+ }
+
+ if (maxRowsToDisplay <= rowSize()) {
+ return returnString + "... }";
+ } else {
+ return returnString + "}";
}
- s.append("}");
- return s.toString();
}
}