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

Till Rohrmann commented on FLINK-1937:
--------------------------------------

Hi [~chiwanpark],

the problem here is that the Scala type inference mechanism cannot infer that 
the tuple type should be (Int, Double) instead of (Int, Int). When you provide 
multiple tuples to the {{fromCOO}} method, Scala knows that only the varargs 
method can be applied and thus concludes that the second field of each tuple 
has to be a {{Double}}. In case of a single tuple, I assume that Scala also 
considers the overloaded method which takes an {{Iterable}}.

You can circumvent this problem by simply telling Scala that your tuple is of 
type (Int, Double) by:
{code}
SparseVector.fromCOO(3, (1, 1.0))
{code}

We can also think of adding a special case {{fromCOO}} implementation which 
takes a single (Int, Int) tuple and converts it into (Int, Double).

> Cannot create SparseVector with only one non-zero element.
> ----------------------------------------------------------
>
>                 Key: FLINK-1937
>                 URL: https://issues.apache.org/jira/browse/FLINK-1937
>             Project: Flink
>          Issue Type: Bug
>          Components: Machine Learning Library
>            Reporter: Chiwan Park
>            Assignee: Till Rohrmann
>              Labels: ML
>
> I tried creating SparseVector with only one non-zero element. But I couldn't 
> create it. Following code causes the problem.
> {code}
> val vec2 = SparseVector.fromCOO(3, (1, 1))
> {code}
> I got a compile error following:
> {code:none}
> Error:(60, 29) overloaded method value fromCOO with alternatives:
>   (size: Int,entries: Iterable[(Int, 
> Double)])org.apache.flink.ml.math.SparseVector <and>
>   (size: Int,entries: (Int, Double)*)org.apache.flink.ml.math.SparseVector
>  cannot be applied to (Int, (Int, Int))
>     val vec2 = SparseVector.fromCOO(3, (1, 1))
>                             ^
> {code}



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

Reply via email to