Re: [ojAlgo-user] how to get exact matrix type of a basicmatrix
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: applyhhj<app...@16...> - 2015-11-09 03:36:41
|
Thank you very much for your reply. The reason is that I need to extend a vector(n x 1) to a diagnoal matrix(n x n), however I declared all matrix vector as BasicMatrix so I need to know the exact type of the matrix to create a diagnoal matrix. By the way will MatrixStore/PhysicalStore be faster than BasicMatrix in various operations? And is there any difference between MatrixStore and PhysicalStore? If details of these aspects are preseted in the Github wiki that would be great. Moreover I do not see any SpareMatrix in Ojalgo. Is there any way to create spareMatrix to accelerate matrix operations cause I need to operate on big spareMatrix such as diagnoal matrix? Thanks again! Best Regards! hjh 2015-11-09 applyhhj 发件人:Anders Peterson <an...@op...> 发送时间:2015-11-08 18:48 主题:Re: [ojAlgo-user] how to get exact matrix type of a basicmatrix 收件人:"ojalgo-user"<oja...@li...> 抄送: 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 ------------------------------------------------------------------------------ _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |