vkostyukov / la4j

Linear Algebra for Java
http://la4j.org
Apache License 2.0
373 stars 109 forks source link

Introduce typesafe factories #234

Closed vkostyukov closed 9 years ago

vkostyukov commented 9 years ago

We should be able to construct object within a concrete type not just Matrix or Vector. The goal is to achieve the following:

CRSMatrix a = new CRSFactory().createMatrix();

For now we only can do the following:

CRSMatrix a = (CRSMatrix) new CRSFactory().createMatrix();

We might want to have a Factory interface generic:

interface Factory<M extends Matrix, V extends Vector> {
  M createMatrix(...);
  V createVector(...);
}

And then

class CRSFactory extends Factory<CRSMatrix, CompressedVector> {
 ... 
}
sylvia43 commented 9 years ago

Generic types! Whoo! I got this.

vkostyukov commented 9 years ago

Oops. Shouldn't have closed this issue. It's still on air.

vkostyukov commented 9 years ago

This is no longer actual. @anubiann00b did you start working on this? I wish I can close it.

sylvia43 commented 9 years ago

Nope :P

Probably won't have time anytime soon, but if it's still up in a couple of days or a week ping me again.

vkostyukov commented 9 years ago

No worries. We can close it for now. I have a better idea on how to deal with factories. I was thinking to throw them out :)

sylvia43 commented 9 years ago

I'm not sure why factories are even neccasary or what they do. Could you explain them?

vkostyukov commented 9 years ago

It's just a tool for creating new matrices/vectors. Since, most of the operations are immutable (create new matrix/vector as a result), we might pass that operation a factory to use for creating new objects. For instance, we want to multiply dense matrix by sparse matrix and build the result matrix as CRSMatrtix. We can just pass the factory instance then.

What I want to do - is to hide those questions from users (what matrix to chose to store the result). The la4j library is smart enough to answer those questions by itself. It knows exactly what to chose in terms of memory-footprint and runtime performance. So, users shouldn't be cate about it.