flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-3996) Add addition, subtraction and multiply by scalar to DenseVector.scala and SparseVector.scala
Date Tue, 31 May 2016 12:17:12 GMT

    [ https://issues.apache.org/jira/browse/FLINK-3996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15307636#comment-15307636
] 

ASF GitHub Bot commented on FLINK-3996:
---------------------------------------

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.


> Add addition, subtraction and multiply by scalar to DenseVector.scala and SparseVector.scala
> --------------------------------------------------------------------------------------------
>
>                 Key: FLINK-3996
>                 URL: https://issues.apache.org/jira/browse/FLINK-3996
>             Project: Flink
>          Issue Type: Improvement
>            Reporter: Daniel Blazevski
>            Assignee: Daniel Blazevski
>            Priority: Minor
>
> Small change to add vector operations. With this small change, can now do things like:
> 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:
> val v1 = DenseVector(0.1, 0.1)
> val v2 = DenseVector(0.2, 0.2)
> val v3 = (v1.asBreeze + v2.asBreeze).fromBreeze



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message