[ https://issues.apache.org/jira/browse/SPARK-9003?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14623704#comment-14623704 ]
Yanbo Liang edited comment on SPARK-9003 at 7/12/15 8:19 AM: ------------------------------------------------------------- Yes, I can provide an example which may be benefit of these function. For example: val originalPrediction = Vectors.dense(Array(1, 2, 3)) val expected = Vectors.dense(Array(10, 20, 30)) In some cases, we can use "~==" to compare two Vector/Matrix which is defined in org.apache.spark.mllib.util.TestingUtils. So currently we can only code as following: val prediction = Vectors.dense(originalPrediction.toArray.map(x => x*10)) assert(prediction ~== expected absTol 0.01, "prediction error") If we support map/update for Vector, we can code as: assert(originalPrediction.map(x => x*10) ~== expected absTol 0.01, "prediction error") was (Author: yanboliang): Yes, I can provide an example which may be benefit of these function. For example: val originalPrediction = Vectors.dense(Array(1, 2, 3)) val expected = Vectors.dense(Array(10, 20, 30)) In some cases, we can use "~==" to compare two Vector/Matrix which is defined in org.apache.spark.mllib.util.TestingUtils. So currently we can only code as following: val prediction = Vectors.dense(originalPrediction.toArry.map(x => x*10)) assert(prediction ~== expected absTol 0.01, "prediction error") If we support map/update for Vector, we can code as: assert(originalPrediction.map(x => x*10) ~== expected absTol 0.01, "prediction error") > Add map/update function to MLlib/Vector > --------------------------------------- > > Key: SPARK-9003 > URL: https://issues.apache.org/jira/browse/SPARK-9003 > Project: Spark > Issue Type: Improvement > Components: MLlib > Reporter: Yanbo Liang > Priority: Minor > > MLlib/Vector is short of map/update function which is inconvenience for some > Vector operations. > For example: > val a = Vectors.dense(...) > If we want to compute math.log for each elements of a and get Vector as > return value, we can only code as: > val b = Vectors.dense(a.toArray.map(math.log)) > The code snippet is not elegant, we want it can implement: > val c = a.map(math.log) > Also currently MLlib/Matrix has implemented map/update function. I think > Vector should also has map/update. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org