In scalaSci the trait scalaSci.StaticScalaSciGlobal defines some global static operations available in scalaSci, independent of the library that the interpreter uses.
Other static operations exist for example in objects RichDoubleArray, RichDoubleDoubleArray, Vec, Matrix, Sparse, CCMatrix which are always imported.
The basic problem that this trait solves is to import properly overloaded versions of a method. For example the method sin() has some fixed signatures independent of the particular library, which at the time of writing are (of course we can extend the list with other matrix types, for example sparse matrices):
sin(x: Double)
sin(x: Array[Double])
sin(x: Array[Array[Double]])
sin(x: Matrix)
sin(x: Vec)
All the Scala Objects for Static Math Operations (SOSMOs) should mixin this trait in order to have the common functionality. Additionally, each SOSMO should implement its library specific routines.
For example the StaticMathsEJML object, by mixing the StaticScalaSciGlobal trait, acquires all the implementations of the sin() for the library independent types.
Then, it implements the sin() for the EJML matrix as:
def sin(x: Mat) = {
scalaSci.EJML.Mat.sin(x)
}
IMPORTANT:
New import statements can overwrite symbols with the same name acquired from previous imports. Thefore, usually imports of the SOSMOs should be placed after objects containing symbols with the same names.
For example, if we write:
import scalaSci.EJML.StaticMathsEJML._
import scalaSci.EJML.Mat._
then the statement:
var x = sin(3.4)
fails, while the statements:
var g = scalaSci.EJML.StaticMathsEJML.rand0(2,3) // g is EJML matrix
sin(g)
succeed.
The problem is that the second import statement (i.e. import scalaSci.EJML.Mat._ ) imports thesin() from thescalaSci.EJML.Mat class that is defined only for scalaSci.EJML.Mat, and overwrites the sin() from the scalaSci.EJML.StaticMathsEJML,that defines many more overloaded versions of sin() . So, the proper order of the imports is:
import scalaSci.EJML.Mat._
import scalaSci.EJML.StaticMathsEJML._
`