Cannot transpose a TMatrixFSparse matrix - Error in <Transpose>: matrix has wrong shape

Dear co-rooters,

I am trying to transpose a matrix constructed with TMastrixFSparse but I get the error

Error in <Transpose>: matrix has wrong shape

A simplified code to illustrate my issue can be seen below

#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSparse.h"

void TMatrix_Transpose(){
	TMatrixFSparse G(5, 1);
	
	int   icol[3] = {0, 0, 0};
	int   irow[3] = {1, 2, 3};
	float data[3] = {1.2, 1.3, 1.4};
	
	G.SetMatrixArray(3, irow, icol, data);
	
	G.Print();
	
	(G.T()).Print();
}

I am compiling my code using ACLiC . Any idea on what might be the issue?

Thanks in advance!

It seems TMatrixFSparse can only transpose square matrices. There is an explicit check for this in the code.

If you change your definition of G to TMatrixFSparse G(5, 5); your code example will work.

As to why it is coded this way I cannot answer; The dense TMatrix can handle non-square transposes.

Cheers,
Kim

Oh I see…
This is bad…
Is there a way to transpose a non-square sparse Matrix?

There is this workaround:

G.ResizeTo(5, 5);
G.T()
G.ResizeTo(1, 5);
G.Print();

Unfortunately this is the best I can give you :confused:

(I also opened a JIRA ticket for this issue, so that we may have resolution in a future release.)

Cheers,
Kim

Thank you very much for your workaround!
It’s better than nothing!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.