1

I was trying to create a map that goes from integers to Nd4j arrays (as in INDArrays) using the nd4s library. I'm struggling with this issue:

import org.nd4j.linalg.factory._
scala> Map(0 -> Nd4j.create(2))
<console>:17: error: type mismatch;
 found   : org.nd4j.linalg.api.ndarray.INDArray
 required: Int
              Map(0 -> Nd4j.create(2))
                                  ^

If I set the key type as string, it works:

scala> Map("0" -> Nd4j.create(2))
res28:     scala.collection.immutable.Map[String,org.nd4j.linalg.api.ndarray.INDArray] = Map(0 -> [ 0.00, 0.00])

It works also by inverting key and value type.

I can't understand what is happening.

pygabriel
  • 9,840
  • 4
  • 41
  • 54

1 Answers1

0

I found the answer by asking help on the Scala channel on gitter.

The problem is that nd4s does an implicit conversion for the -> operator, leading to this issue.

https://github.com/deeplearning4j/nd4s/blob/master/src/main/scala/org/nd4s/Implicits.scala#L143-L176

pygabriel
  • 9,840
  • 4
  • 41
  • 54