Closed kjameslubin closed 9 years ago
This sounds reasonable. The only caveat is that the newOrCheck functions need to work with null matrix arguments when there's no container to reuse, so you cant use the omat parameter to infer the type. You have to introduce another matrix argument which you match the type to. That should be available in the contexts you're interested in.
@jcanny perhaps we could use Scala Option's for the null matrix case?
Given that the omat parameter is always generic anyway, it's likely we could write a catch-all newOrCheck method in Mat and override it individually. The reason I mention it is that implementing caching for generic matrix methods could end up requiring quite a few pattern matches. It's manageable at the moment (just FMat's, SMat's, GMat's and GSMat's) but could grow in complexity.
In practice the methods pattern match on the omat type inside the function body, so it should be 'safe' to make the method generic. https://github.com/BIDData/BIDMat/blob/master/src/main/scala/BIDMat/DMat.scala#L1459-L1465
Something might be lost vis-a-vis (e.g.) reflection, though. I still don't understand Scala's type erasure semantics very well.