Re: [ojAlgo-user] how to get exact matrix type of a basicmatrix
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2015-11-08 10:48:24
|
You have to do instanceof on either the matrix or on one of the elements. Why do you need to do this, or why don’t you know which type you have? If you consistently declare variables as ComplexMatrix then all operations will actually return ComplexMatrix rather than BasicMatrix. final BasicMatrix tmpOrg1 = PrimitiveMatrix.FACTORY.makeEye(3, 3); final ComplexMatrix tmpOrg2 = ComplexMatrix.FACTORY.makeEye(3, 3); final BasicMatrix tmpBasic = tmpOrg1.transpose(); final ComplexMatrix tmpComplex = tmpOrg2.transpose(); // The specific subclass is maintained Even if you declare things as BasicMatrix rather than one of the specific implementations the underlying type will not change. It is possible to operate on two matrices of different types (add them together), in those cases it is always “this” that decides the type of the returned matrix. Are you sure you want to use the BasicMatrix interface and its implementations? It’s what many users find first, and start using, but I believe most would be better off using the various MatrixStore/PhysicalStore implementations. With BasicMatrix there’s a lot less to worry about but also musch less flexibility in terms of what you can do. BigMatrix, ComplexMatrix and PrimitiveMatrix are immutable. That’s not what most users expect and consequently they use those classes inefficiently. Try both alternatives and see which one suits you best, /Anders > On 8 nov. 2015, at 09:08, applyhhj <app...@16...> wrote: > > Hi everyone, > Is there any way to tell wether a BasicMatrix is a PrimitiveMatrix or a ComplexMatrix? Thanks! > > Regards! > hjh > > 2015-11-08 > applyhhj > ------------------------------------------------------------------------------ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |