You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by mengxr <gi...@git.apache.org> on 2014/08/08 08:04:26 UTC

[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

GitHub user mengxr opened a pull request:

    https://github.com/apache/spark/pull/1849

    [SPARK-2923][MLLIB] Implement some basic BLAS routines

    Having some basic BLAS operations implemented in MLlib can help simplify the current implementation and improve some performance.
    
    Tested on my local machine:
    
    ~~~
    bin/spark-submit --class org.apache.spark.examples.mllib.BinaryClassification \
    examples/target/scala-*/spark-examples-*.jar --algorithm LR --regType L2 \
    --regParam 1.0 --numIterations 1000 ~/share/data/rcv1.binary/rcv1_train.binary
    ~~~ 
    
    1. before: ~1m
    2. after: ~30s
    
    CC: @jkbradley

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mengxr/spark ml-blas

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/1849.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 #1849
    
----
commit e8c326ddb5697ca06e901a600b2287578214b161
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-07-15T20:16:22Z

    axpy

commit 07db0bb4d25bf26411310259f4bed376a0057d85
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-07T17:18:43Z

    Merge branch 'master' into ml-blas

commit cbb8273e27ca1c25326b24a54ffb49bc1909885f
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-07T19:24:03Z

    add daxpy test

commit 14e664595ce6adfa21a8085b8fd13a21b88a07d6
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T02:21:07Z

    add ddot

commit 7f78186335a4e0d8ecee0319de5f7deda1a011c8
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T03:26:19Z

    add zeros to Vectors; add dscal and dcopy to BLAS

commit d2d7d3c2fb6a6fad2848bce413e8f83e4a2281ce
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T03:28:21Z

    update gradient and lbfgs

commit 735eb23fa3f4f9a364c4fb35139db03add7db45d
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T04:52:15Z

    remove d from BLAS routines

commit 3b882b1d23456636fb76bd67e41008d8d808c043
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T05:03:35Z

    use blas.scal in gradient

commit 48d01d20787cf98b892963ee0d3fbb4f6633d063
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T05:16:30Z

    add tests for zeros and copy

commit 4cfaac46cf0f1a40919af6e7935f4c734ab6625c
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T05:18:07Z

    add apache header

commit c2a38bcccc95b5fbbae4d022857746252e65006d
Author: Xiangrui Meng <me...@databricks.com>
Date:   2014-08-08T05:23:25Z

    enhance dot tests

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16008443
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
    @@ -0,0 +1,207 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
    +
    +/**
    + * BLAS routines for MLlib's vectors and matrices.
    + */
    +private[mllib] object BLAS extends Serializable {
    +
    +  @transient private var _f2jBLAS: NetlibBLAS = _
    +
    +  // For level-1 routines, we use Java implementation.
    +  private def f2jBLAS: NetlibBLAS = {
    +    if (_f2jBLAS == null) {
    +      _f2jBLAS = new F2jBLAS
    +    }
    +    _f2jBLAS
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  def axpy(a: Double, x: Vector, y: Vector): Unit = {
    +    require(x.size == y.size)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    +            axpy(a, sx, dy)
    +          case dx: DenseVector =>
    +            axpy(a, dx, dy)
    +          case _ =>
    +            throw new UnsupportedOperationException(
    +              s"axpy doesn't support x type ${x.getClass}.")
    +        }
    +      case _ =>
    +        throw new IllegalArgumentException(
    +          s"axpy only supports adding to a dense vector but got type ${y.getClass}.")
    +    }
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: DenseVector, y: DenseVector): Unit = {
    +    val n = x.size
    +    f2jBLAS.daxpy(n, a, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: SparseVector, y: DenseVector): Unit = {
    +    val nnz = x.indices.size
    +    if (a == 1.0) {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += x.values(k)
    +        k += 1
    +      }
    +    } else {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += a * x.values(k)
    +        k += 1
    +      }
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  def dot(x: Vector, y: Vector): Double = {
    +    require(x.size == y.size)
    +    (x, y) match {
    +      case (dx: DenseVector, dy: DenseVector) =>
    +        dot(dx, dy)
    +      case (dx: DenseVector, sy: SparseVector) =>
    +        dot(dx, sy)
    +      case (sx: SparseVector, dy: DenseVector) =>
    +        dot(sx, dy)
    +      case (sx: SparseVector, sy: SparseVector) =>
    +        dot(sx, sy)
    +      case _ =>
    +        throw new IllegalArgumentException(s"dot doesn't support (${x.getClass}, ${y.getClass}).")
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: DenseVector): Double = {
    +    val n = x.size
    +    f2jBLAS.ddot(n, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: DenseVector): Double = {
    +    val nnz = x.indices.size
    +    var sum = 0.0
    +    var k = 0
    +    while (k < nnz) {
    +      sum += x.values(k) * y.values(x.indices(k))
    +      k += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: SparseVector): Double = {
    --- End diff --
    
    Remove this and just do it at line 96?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51875312
  
    Thanks! I've merged this into both master and branch-1.1.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51569473
  
    QA results for PR 1849:<br>- This patch PASSES unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18194/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51668154
  
    QA results for PR 1849:<br>- This patch PASSES unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18230/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16015610
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/linalg/BLASSuite.scala ---
    @@ -0,0 +1,129 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import org.scalatest.FunSuite
    +
    +import org.apache.spark.mllib.util.TestingUtils._
    +import org.apache.spark.mllib.linalg.BLAS._
    +
    +class BLASSuite extends FunSuite {
    +
    +  test("copy") {
    +    val sx = Vectors.sparse(4, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0, 0.0)
    +    val sy = Vectors.sparse(4, Array(0, 1, 3), Array(2.0, 1.0, 1.0))
    +    val dy = Array(2.0, 1.0, 0.0, 1.0)
    +
    +    val dy1 = Vectors.dense(dy.clone())
    +    copy(sx, dy1)
    +    assert(dy1 ~== dx absTol 1e-15)
    +
    +    val dy2 = Vectors.dense(dy.clone())
    +    copy(dx, dy2)
    +    assert(dy2 ~== dx absTol 1e-15)
    +
    +    intercept[IllegalArgumentException] {
    +      copy(sx, sy)
    +    }
    +
    +    intercept[IllegalArgumentException] {
    +      copy(dx, sy)
    +    }
    +
    +    withClue("vector sizes must match") {
    +      intercept[Exception] {
    +        copy(sx, Vectors.dense(0.0, 1.0, 2.0))
    +      }
    +    }
    +  }
    +
    +  test("scal") {
    +    val a = 0.1
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +
    +    scal(a, sx)
    +    assert(sx ~== Vectors.sparse(3, Array(0, 2), Array(0.1, -0.2)) absTol 1e-15)
    +
    +    scal(a, dx)
    +    assert(dx ~== Vectors.dense(0.1, 0.0, -0.2) absTol 1e-15)
    +  }
    +
    +  test("axpy") {
    +    val alpha = 0.1
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +    val dy = Array(2.0, 1.0, 0.0)
    +    val expected = Vectors.dense(2.1, 1.0, -0.2)
    +
    +    val dy1 = Vectors.dense(dy.clone())
    +    axpy(alpha, sx, dy1)
    +    assert(dy1 ~== expected absTol 1e-15)
    +
    +    val dy2 = Vectors.dense(dy.clone())
    +    axpy(alpha, dx, dy2)
    +    assert(dy2 ~== expected absTol 1e-15)
    +
    +    val sy = Vectors.sparse(4, Array(0, 1), Array(2.0, 1.0))
    +
    +    intercept[IllegalArgumentException] {
    +      axpy(alpha, sx, sy)
    +    }
    +
    +    intercept[IllegalArgumentException] {
    +      axpy(alpha, dx, sy)
    +    }
    +
    +    withClue("vector sizes must match") {
    +      intercept[Exception] {
    +        axpy(alpha, sx, Vectors.dense(1.0, 2.0))
    +      }
    +    }
    +  }
    +
    +  test("dot") {
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +    val sy = Vectors.sparse(3, Array(0, 1), Array(2.0, 1.0))
    +    val dy = Vectors.dense(2.0, 1.0, 0.0)
    +
    +    assert(dot(sx, sy) ~== 2.0 absTol 1e-15)
    +    assert(dot(sy, sx) ~== 2.0 absTol 1e-15)
    +    assert(dot(sx, dy) ~== 2.0 absTol 1e-15)
    +    assert(dot(dy, sx) ~== 2.0 absTol 1e-15)
    +    assert(dot(dx, dy) ~== 2.0 absTol 1e-15)
    +    assert(dot(dy, dx) ~== 2.0 absTol 1e-15)
    +
    +    assert(dot(sx, sx) ~== 5.0 absTol 1e-15)
    +    assert(dot(dx, dx) ~== 5.0 absTol 1e-15)
    +    assert(dot(sx, dx) ~== 5.0 absTol 1e-15)
    +    assert(dot(dx, dx) ~== 5.0 absTol 1e-15)
    --- End diff --
    
    right. thanks for catching it!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51866552
  
    We can create a binary search version in Python in another PR. For this PR, does it look good to you?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16015611
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
    @@ -0,0 +1,207 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
    +
    +/**
    + * BLAS routines for MLlib's vectors and matrices.
    + */
    +private[mllib] object BLAS extends Serializable {
    +
    +  @transient private var _f2jBLAS: NetlibBLAS = _
    +
    +  // For level-1 routines, we use Java implementation.
    +  private def f2jBLAS: NetlibBLAS = {
    +    if (_f2jBLAS == null) {
    +      _f2jBLAS = new F2jBLAS
    +    }
    +    _f2jBLAS
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  def axpy(a: Double, x: Vector, y: Vector): Unit = {
    +    require(x.size == y.size)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    +            axpy(a, sx, dy)
    +          case dx: DenseVector =>
    +            axpy(a, dx, dy)
    +          case _ =>
    +            throw new UnsupportedOperationException(
    +              s"axpy doesn't support x type ${x.getClass}.")
    +        }
    +      case _ =>
    +        throw new IllegalArgumentException(
    +          s"axpy only supports adding to a dense vector but got type ${y.getClass}.")
    +    }
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: DenseVector, y: DenseVector): Unit = {
    +    val n = x.size
    +    f2jBLAS.daxpy(n, a, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: SparseVector, y: DenseVector): Unit = {
    +    val nnz = x.indices.size
    +    if (a == 1.0) {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += x.values(k)
    +        k += 1
    +      }
    +    } else {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += a * x.values(k)
    +        k += 1
    +      }
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  def dot(x: Vector, y: Vector): Double = {
    +    require(x.size == y.size)
    +    (x, y) match {
    +      case (dx: DenseVector, dy: DenseVector) =>
    +        dot(dx, dy)
    +      case (dx: DenseVector, sy: SparseVector) =>
    +        dot(dx, sy)
    +      case (sx: SparseVector, dy: DenseVector) =>
    +        dot(sx, dy)
    +      case (sx: SparseVector, sy: SparseVector) =>
    +        dot(sx, sy)
    +      case _ =>
    +        throw new IllegalArgumentException(s"dot doesn't support (${x.getClass}, ${y.getClass}).")
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: DenseVector): Double = {
    +    val n = x.size
    +    f2jBLAS.ddot(n, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: DenseVector): Double = {
    +    val nnz = x.indices.size
    +    var sum = 0.0
    +    var k = 0
    +    while (k < nnz) {
    +      sum += x.values(k) * y.values(x.indices(k))
    +      k += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: SparseVector): Double = {
    --- End diff --
    
    done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51868853
  
    Yes, LGTM


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51574696
  
    QA tests have started for PR 1849. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18198/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51639832
  
    @mengxr Other than the above comments, LGTM


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16008439
  
    --- Diff: mllib/src/test/scala/org/apache/spark/mllib/linalg/BLASSuite.scala ---
    @@ -0,0 +1,129 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import org.scalatest.FunSuite
    +
    +import org.apache.spark.mllib.util.TestingUtils._
    +import org.apache.spark.mllib.linalg.BLAS._
    +
    +class BLASSuite extends FunSuite {
    +
    +  test("copy") {
    +    val sx = Vectors.sparse(4, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0, 0.0)
    +    val sy = Vectors.sparse(4, Array(0, 1, 3), Array(2.0, 1.0, 1.0))
    +    val dy = Array(2.0, 1.0, 0.0, 1.0)
    +
    +    val dy1 = Vectors.dense(dy.clone())
    +    copy(sx, dy1)
    +    assert(dy1 ~== dx absTol 1e-15)
    +
    +    val dy2 = Vectors.dense(dy.clone())
    +    copy(dx, dy2)
    +    assert(dy2 ~== dx absTol 1e-15)
    +
    +    intercept[IllegalArgumentException] {
    +      copy(sx, sy)
    +    }
    +
    +    intercept[IllegalArgumentException] {
    +      copy(dx, sy)
    +    }
    +
    +    withClue("vector sizes must match") {
    +      intercept[Exception] {
    +        copy(sx, Vectors.dense(0.0, 1.0, 2.0))
    +      }
    +    }
    +  }
    +
    +  test("scal") {
    +    val a = 0.1
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +
    +    scal(a, sx)
    +    assert(sx ~== Vectors.sparse(3, Array(0, 2), Array(0.1, -0.2)) absTol 1e-15)
    +
    +    scal(a, dx)
    +    assert(dx ~== Vectors.dense(0.1, 0.0, -0.2) absTol 1e-15)
    +  }
    +
    +  test("axpy") {
    +    val alpha = 0.1
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +    val dy = Array(2.0, 1.0, 0.0)
    +    val expected = Vectors.dense(2.1, 1.0, -0.2)
    +
    +    val dy1 = Vectors.dense(dy.clone())
    +    axpy(alpha, sx, dy1)
    +    assert(dy1 ~== expected absTol 1e-15)
    +
    +    val dy2 = Vectors.dense(dy.clone())
    +    axpy(alpha, dx, dy2)
    +    assert(dy2 ~== expected absTol 1e-15)
    +
    +    val sy = Vectors.sparse(4, Array(0, 1), Array(2.0, 1.0))
    +
    +    intercept[IllegalArgumentException] {
    +      axpy(alpha, sx, sy)
    +    }
    +
    +    intercept[IllegalArgumentException] {
    +      axpy(alpha, dx, sy)
    +    }
    +
    +    withClue("vector sizes must match") {
    +      intercept[Exception] {
    +        axpy(alpha, sx, Vectors.dense(1.0, 2.0))
    +      }
    +    }
    +  }
    +
    +  test("dot") {
    +    val sx = Vectors.sparse(3, Array(0, 2), Array(1.0, -2.0))
    +    val dx = Vectors.dense(1.0, 0.0, -2.0)
    +    val sy = Vectors.sparse(3, Array(0, 1), Array(2.0, 1.0))
    +    val dy = Vectors.dense(2.0, 1.0, 0.0)
    +
    +    assert(dot(sx, sy) ~== 2.0 absTol 1e-15)
    +    assert(dot(sy, sx) ~== 2.0 absTol 1e-15)
    +    assert(dot(sx, dy) ~== 2.0 absTol 1e-15)
    +    assert(dot(dy, sx) ~== 2.0 absTol 1e-15)
    +    assert(dot(dx, dy) ~== 2.0 absTol 1e-15)
    +    assert(dot(dy, dx) ~== 2.0 absTol 1e-15)
    +
    +    assert(dot(sx, sx) ~== 5.0 absTol 1e-15)
    +    assert(dot(dx, dx) ~== 5.0 absTol 1e-15)
    +    assert(dot(sx, dx) ~== 5.0 absTol 1e-15)
    +    assert(dot(dx, dx) ~== 5.0 absTol 1e-15)
    --- End diff --
    
    Did you mean dot(dx, sx) ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/1849


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51664938
  
    QA tests have started for PR 1849. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18230/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16008451
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala ---
    @@ -128,6 +128,33 @@ object Vectors {
       }
     
       /**
    +   * Creates a dense vector of all zeros.
    +   *
    +   * @param size vector size
    +   * @return a zero vector
    +   */
    +  def zeros(size: Int): Vector = {
    +    new DenseVector(new Array[Double](size))
    +  }
    +
    +
    +  /**
    +   * Makes a deep copy of the input vector.
    +   */
    +  def copy(v: Vector): Vector = {
    --- End diff --
    
    Why support copy here, rather than in DenseVector and SparseVector?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16008446
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
    @@ -0,0 +1,207 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
    +
    +/**
    + * BLAS routines for MLlib's vectors and matrices.
    + */
    +private[mllib] object BLAS extends Serializable {
    +
    +  @transient private var _f2jBLAS: NetlibBLAS = _
    +
    +  // For level-1 routines, we use Java implementation.
    +  private def f2jBLAS: NetlibBLAS = {
    +    if (_f2jBLAS == null) {
    +      _f2jBLAS = new F2jBLAS
    +    }
    +    _f2jBLAS
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  def axpy(a: Double, x: Vector, y: Vector): Unit = {
    +    require(x.size == y.size)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    +            axpy(a, sx, dy)
    +          case dx: DenseVector =>
    +            axpy(a, dx, dy)
    +          case _ =>
    +            throw new UnsupportedOperationException(
    +              s"axpy doesn't support x type ${x.getClass}.")
    +        }
    +      case _ =>
    +        throw new IllegalArgumentException(
    +          s"axpy only supports adding to a dense vector but got type ${y.getClass}.")
    +    }
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: DenseVector, y: DenseVector): Unit = {
    +    val n = x.size
    +    f2jBLAS.daxpy(n, a, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: SparseVector, y: DenseVector): Unit = {
    +    val nnz = x.indices.size
    +    if (a == 1.0) {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += x.values(k)
    +        k += 1
    +      }
    +    } else {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += a * x.values(k)
    +        k += 1
    +      }
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  def dot(x: Vector, y: Vector): Double = {
    +    require(x.size == y.size)
    +    (x, y) match {
    +      case (dx: DenseVector, dy: DenseVector) =>
    +        dot(dx, dy)
    +      case (dx: DenseVector, sy: SparseVector) =>
    +        dot(dx, sy)
    +      case (sx: SparseVector, dy: DenseVector) =>
    +        dot(sx, dy)
    +      case (sx: SparseVector, sy: SparseVector) =>
    +        dot(sx, sy)
    +      case _ =>
    +        throw new IllegalArgumentException(s"dot doesn't support (${x.getClass}, ${y.getClass}).")
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: DenseVector): Double = {
    +    val n = x.size
    +    f2jBLAS.ddot(n, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: DenseVector): Double = {
    +    val nnz = x.indices.size
    +    var sum = 0.0
    +    var k = 0
    +    while (k < nnz) {
    +      sum += x.values(k) * y.values(x.indices(k))
    +      k += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: SparseVector): Double = {
    +    dot(y, x)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: SparseVector): Double = {
    +    var kx = 0
    +    val nnzx = x.indices.size
    +    var ky = 0
    +    val nnzy = y.indices.size
    +    var sum = 0.0
    +    // y catching x
    +    while (kx < nnzx && ky < nnzy) {
    +      val ix = x.indices(kx)
    +      while (ky < nnzy && y.indices(ky) < ix) {
    +        ky += 1
    +      }
    +      if (ky < nnzy && y.indices(ky) == ix) {
    +        sum += x.values(kx) * y.values(ky)
    +        ky += 1
    +      }
    +      kx += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * y = x
    +   */
    +  def copy(x: Vector, y: Vector): Unit = {
    +    val n = y.size
    +    require(x.size == n)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    --- End diff --
    
    Not sure of the various use cases for copying Dense <-- Sparse, but if it is common, then it could be worth checking the nnz vs. n and using memset(0) call.  (Is there a memset-like call available?)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51656240
  
    QA tests have started for PR 1849. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18223/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16015652
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala ---
    @@ -128,6 +128,33 @@ object Vectors {
       }
     
       /**
    +   * Creates a dense vector of all zeros.
    +   *
    +   * @param size vector size
    +   * @return a zero vector
    +   */
    +  def zeros(size: Int): Vector = {
    +    new DenseVector(new Array[Double](size))
    +  }
    +
    +
    +  /**
    +   * Makes a deep copy of the input vector.
    +   */
    +  def copy(v: Vector): Vector = {
    --- End diff --
    
    Done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51566676
  
    QA tests have started for PR 1849. This patch merges cleanly. <br>View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18194/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1849#discussion_r16015643
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
    @@ -0,0 +1,207 @@
    +/*
    + * 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.spark.mllib.linalg
    +
    +import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
    +
    +/**
    + * BLAS routines for MLlib's vectors and matrices.
    + */
    +private[mllib] object BLAS extends Serializable {
    +
    +  @transient private var _f2jBLAS: NetlibBLAS = _
    +
    +  // For level-1 routines, we use Java implementation.
    +  private def f2jBLAS: NetlibBLAS = {
    +    if (_f2jBLAS == null) {
    +      _f2jBLAS = new F2jBLAS
    +    }
    +    _f2jBLAS
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  def axpy(a: Double, x: Vector, y: Vector): Unit = {
    +    require(x.size == y.size)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    +            axpy(a, sx, dy)
    +          case dx: DenseVector =>
    +            axpy(a, dx, dy)
    +          case _ =>
    +            throw new UnsupportedOperationException(
    +              s"axpy doesn't support x type ${x.getClass}.")
    +        }
    +      case _ =>
    +        throw new IllegalArgumentException(
    +          s"axpy only supports adding to a dense vector but got type ${y.getClass}.")
    +    }
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: DenseVector, y: DenseVector): Unit = {
    +    val n = x.size
    +    f2jBLAS.daxpy(n, a, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * y += a * x
    +   */
    +  private def axpy(a: Double, x: SparseVector, y: DenseVector): Unit = {
    +    val nnz = x.indices.size
    +    if (a == 1.0) {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += x.values(k)
    +        k += 1
    +      }
    +    } else {
    +      var k = 0
    +      while (k < nnz) {
    +        y.values(x.indices(k)) += a * x.values(k)
    +        k += 1
    +      }
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  def dot(x: Vector, y: Vector): Double = {
    +    require(x.size == y.size)
    +    (x, y) match {
    +      case (dx: DenseVector, dy: DenseVector) =>
    +        dot(dx, dy)
    +      case (dx: DenseVector, sy: SparseVector) =>
    +        dot(dx, sy)
    +      case (sx: SparseVector, dy: DenseVector) =>
    +        dot(sx, dy)
    +      case (sx: SparseVector, sy: SparseVector) =>
    +        dot(sx, sy)
    +      case _ =>
    +        throw new IllegalArgumentException(s"dot doesn't support (${x.getClass}, ${y.getClass}).")
    +    }
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: DenseVector): Double = {
    +    val n = x.size
    +    f2jBLAS.ddot(n, x.values, 1, y.values, 1)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: DenseVector): Double = {
    +    val nnz = x.indices.size
    +    var sum = 0.0
    +    var k = 0
    +    while (k < nnz) {
    +      sum += x.values(k) * y.values(x.indices(k))
    +      k += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: DenseVector, y: SparseVector): Double = {
    +    dot(y, x)
    +  }
    +
    +  /**
    +   * dot(x, y)
    +   */
    +  private def dot(x: SparseVector, y: SparseVector): Double = {
    +    var kx = 0
    +    val nnzx = x.indices.size
    +    var ky = 0
    +    val nnzy = y.indices.size
    +    var sum = 0.0
    +    // y catching x
    +    while (kx < nnzx && ky < nnzy) {
    +      val ix = x.indices(kx)
    +      while (ky < nnzy && y.indices(ky) < ix) {
    +        ky += 1
    +      }
    +      if (ky < nnzy && y.indices(ky) == ix) {
    +        sum += x.values(kx) * y.values(ky)
    +        ky += 1
    +      }
    +      kx += 1
    +    }
    +    sum
    +  }
    +
    +  /**
    +   * y = x
    +   */
    +  def copy(x: Vector, y: Vector): Unit = {
    +    val n = y.size
    +    require(x.size == n)
    +    y match {
    +      case dy: DenseVector =>
    +        x match {
    +          case sx: SparseVector =>
    --- End diff --
    
    I thought about setting all zeros and then copy nonzeros when nnz is small. It may be faster but sparse->dense is not a common use case and I wonder whether we should do this optimization. And I don't know something as efficient as memset in Java.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51722636
  
    @mengxr  By the way, I actually realized that copying sparse to dense vectors would be useful for me (in an example I wrote for the stats API check).  I wanted it for a replacement for indexing into sparse vectors (since that does not exist yet).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51578983
  
    QA results for PR 1849:<br>- This patch PASSES unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18198/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-2923][MLLIB] Implement some basic BLAS ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/1849#issuecomment-51661232
  
    QA results for PR 1849:<br>- This patch FAILED unit tests.<br>- This patch merges cleanly<br>- This patch adds no public classes<br><br>For more information see test ouptut:<br>https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/18223/consoleFull


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org