You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by danielblazevski <gi...@git.apache.org> on 2016/05/30 17:18:42 UTC

[GitHub] flink pull request: Added addition, subtraction and multiply by sc...

GitHub user danielblazevski opened a pull request:

    https://github.com/apache/flink/pull/2052

    Added addition, subtraction and multiply by scalar to DenseVector.scala and SparseVector.scala

    Small change to add vector operations.  With this small change, can now do things like:
    
    ```scala
    val v1 = DenseVector(0.1, 0.1)
    val v2 = DenseVector(0.2, 0.2)
    val v3 = v1 + v2
    ```
    instead of what is now has to be done:
    ```scala
    val v1 = DenseVector(0.1, 0.1)
    val v2 = DenseVector(0.2, 0.2)
    val v3 = (v1.asBreeze + v2.asBreeze).fromBreeze
    ```
    Did not add a test, not sure if I should add a test to any Suite for such a small change?  There is no JIRA issue on this. @chiwanpark 

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

    $ git pull https://github.com/danielblazevski/flink vectorOps

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

    https://github.com/apache/flink/pull/2052.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 #2052
    
----
commit 44fc80b67c6e2fb85fb2bddfece44b34c9061e1d
Author: danielblazevski <da...@gmail.com>
Date:   2016-05-30T16:34:58Z

    added addition/subtraction and mult by scalar to Vector.scala

commit bac684c19e2427b7db41f3430378ef050e660b03
Author: danielblazevski <da...@gmail.com>
Date:   2016-05-30T16:41:19Z

    moved to only DenseVector.scala

commit 073149403253a4891223ea46bfc3d8455382703b
Author: danielblazevski <da...@gmail.com>
Date:   2016-05-30T17:08:10Z

    added ops to SparseVector.scala

----


---
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.
---

[GitHub] flink pull request: Added addition, subtraction and multiply by sc...

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

    https://github.com/apache/flink/pull/2052#issuecomment-222644723
  
    Hi @danielblazevski, thanks for opening pull request. But we need a related JIRA issue for this. Could you create an issue and change title of this PR?


---
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.
---

[GitHub] flink pull request: [FLINK-3996] Add addition, subtraction and multiply by s...

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

    https://github.com/apache/flink/pull/2052
  
    @chiwanpark 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.
---

[GitHub] flink pull request: [FLINK-3996] Add addition, subtraction and multiply by s...

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

    https://github.com/apache/flink/pull/2052#discussion_r65170092
  
    --- Diff: flink-libraries/flink-ml/src/main/scala/org/apache/flink/ml/math/SparseVector.scala ---
    @@ -175,10 +176,21 @@ case class SparseVector(
     
         java.util.Arrays.binarySearch(indices, 0, indices.length, index)
       }
    +
    +  def + (other: Vector): Vector = (this.asBreeze + other.asBreeze).fromBreeze
    +
    +  def - (other: Vector): Vector = (this.asBreeze - other.asBreeze).fromBreeze
    +
    +  def * (scalar: Double): Vector = (scalar * this.asBreeze).fromBreeze
    +
    --- End diff --
    
    Remark:  when I put `+` and `-` in the `Vector` Trait to avoid duplication of code, it works fine, but not when I add the `*` method to the `Vector` Trait.  I get errors even when using `+` when I add the `*` method in `Vector`, namely:
    
    ```
    Error:(86, 68) could not find implicit value for evidence parameter of type org.apache.flink.ml.math.BreezeVectorConverter[T]
      def + (other: Vector): Vector = (this.asBreeze + other.asBreeze).fromBreeze
                                                   ^
    ```
    
    This error does not appear if I have `+` and `-` in Vector.scala and keep `*` duplicated in both DenseVector.scala and SparseVector.scala.  Found it weird then to have `+` and `-` in Vector.scala and `*` separate.  This is why I decided to duplicate the code in DenseVector and SparseVector.  Happy to hear if anyone knows of a way to avoid this.


---
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.
---