I'm trying to implement my own elementwise UFunc for a Scala Breeze matrix, so that the function can be applied to each element of a matrix. Using the Breeze.numerics package as a guide I have tried:
object step extends UFunc with MappingUFunc {
implicit object stepImplDouble extends Impl[Double, Double] {
def apply(x: Double) = if (x >= 0.5) 1.0 else 0.0
}
Looks pretty easy, huh? I am trying to use the function as follows:
val H: BDM[Double] = step((M(::,*) + bias).t)
i.e. apply it a function element by element, to a matrix, giving an output H. However the code gives an error at compile time:
Error:(60, 26) could not find implicit value for parameter impl: dev.elm.step.Impl[breeze.linalg.DenseMatrix[Double],VR]
case "step" => step((M(::, *) + bias).t)
Error:(60, 26) not enough arguments for method apply: (implicit impl: dev.elm.step.Impl[breeze.linalg.DenseMatrix[Double],VR])VR in trait UFunc.
Unspecified value parameter impl.
case "step" => step((M(::, *) + bias).t)
This is very similar to the error I raised in my previous question. It sounds like it might need the matrix arguments but I thought that was all dealt with in the MappingUFunc trait. Any help appreciated! Thanks
Because this is an object, the declaration order matters. Either place it higher in the code than the first call, or pull it out into its own file.