Scala (Breeze) + Intellij: “Cannot resolve symbol

2019-08-12 14:29发布

问题:

I'm using Breeze to to do sum simple linear algebra operations on dense matrices. I'm using the Intellij IDEA. Here is an snippet of my code:

import breeze.linalg._    
val X1:DenseMatrix[Double] = DenseMatrix.zeros[Double](10, 5) + 1.0
val n1 : Double = X1.rows.toDouble
val one_tall_t1  = DenseMatrix.zeros[Double](1, n1.toInt) + 1.0
val mu1=one_tall_t1*X1/n1

In the last line, the symbols * and / are shown with red color in the IDE. The error message is "Cannot resolve the symbol *".

But Intellij builds the program without any errors, and it runs fine.

I've been trying to find out the reason: since I'm new to Scala, I'm not sure if it is because of Intellij, Breeze, or just my code. In some posts, people have suggested to invalidate cache and restart Intellij, but this does not solve my issue.

I appreciate your comments or solutions!

回答1:

IntelliJ gets confused by complex implicit searches like those used in Breeze. I file bugs when I can minimize them and get around to it, but it's a slog. (Eclipse, for what it's worth, isn't much better.)

It typically works better if you're just depending on Breeze, not developing inside of it. I assume you're doing that already though.