You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/06/16 17:00:03 UTC
[jira] [Commented] (MAHOUT-1691) iterable of vectors to matrix
[ https://issues.apache.org/jira/browse/MAHOUT-1691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14588156#comment-14588156 ]
ASF GitHub Bot commented on MAHOUT-1691:
----------------------------------------
GitHub user alexeygrigorev opened a pull request:
https://github.com/apache/mahout/pull/138
MAHOUT-1691: iterable of vectors to matrix
Some syntactic sugar for writing
```
val res = drmX.mapBlock(drmX.ncol) {
case (keys, block) => {
keys -> block.map(row => (row - mean) / std)
}
}
```
Instead of writing
```
val res = drmX.mapBlock(drmX.ncol) {
case (keys, block) => {
val copy = block.like
copy := block.map(row => (row - mean) / std)
(keys, copy)
}
}
```
When having side effects is not desirable
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/alexeygrigorev/mahout it2vec
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/mahout/pull/138.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #138
----
commit 1adf6e3e2cdb4ae0dfb25525c61412474bdab8d6
Author: Alexey Grigorev <al...@gmail.com>
Date: 2015-06-16T14:12:50Z
MAHOUT-1691: iterable of vectors to matrix
----
> iterable of vectors to matrix
> ------------------------------
>
> Key: MAHOUT-1691
> URL: https://issues.apache.org/jira/browse/MAHOUT-1691
> Project: Mahout
> Issue Type: Improvement
> Components: Math
> Affects Versions: 0.10.1
> Reporter: Alexey Grigorev
> Priority: Minor
> Labels: math, scala
>
> In Mahout scala bindings, instead of writing
> {code}
> val res = drmX.mapBlock(drmX.ncol) {
> case (keys, block) => {
> val copy = block.like
> copy := block.map(row => (row - mean) / std)
> (keys, copy)
> }
> }
> {code}
> I would like to be able to write
> {code}
> val res = drmX.mapBlock(drmX.ncol) {
> case (keys, block) => {
> keys -> block.map(row => (row - mean) / std)
> }
> }
> {code}
> Solution: add a method for implicit conversion from iterable to Matrix:
> {code}
> implicit def iterable2Matrix(that: Iterable[Vector]): Matrix = {
> val first = that.head
> val nrow = that.size
> val ncol = first.size
> val m = if (first.isDense) {
> new DenseMatrix(nrow, ncol)
> } else {
> new SparseRowMatrix(nrow, ncol)
> }
> that.zipWithIndex.foreach { case (row, idx) =>
> m.assignRow(idx.toInt, row)
> }
> m
> }
> {code}
> If it sounds nice, I can send a pull request with this implemented
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)