tomstewart89 / BasicLinearAlgebra

A library for using matrices and linear algebra on Arduino
MIT License
185 stars 38 forks source link

Eye() behaves like Ones() when doing math #70

Closed Copper280z closed 8 months ago

Copper280z commented 8 months ago

Hi,

I noticed that in some cases a matrix instantiated by using Eye() sometimes behaves like it was instantiated by Ones(). It seems if you access it via indexing, ie I(0,0), it behaves like the identity, but if you use it to do math, it behaves like ones.

  auto I = BLA::Eye<2,2>(); 
  auto Z = BLA::Zeros<2,2>();
  auto R = I+Z;

  Serial.printf("%.3f, %.3f, %.3f, %.3f\n", I(0,0),I(1,0),I(0,1),I(1,1) );
  Serial.printf("%.3f, %.3f, %.3f, %.3f\n", R(0,0),R(1,0),R(0,1),R(1,1) );

returns

1.000, 0.000, 0.000, 1.000
1.000, 1.000, 1.000, 1.000

Using a debug probe I've confirmed that the memory of I is full of 1's.

Is this a bug, or am I using the result of Eye() inappropriately?

tomstewart89 commented 8 months ago

Hey @Copper280z , thanks for the issue, this is a bug! I just pushed a commit to fix it here: #71 , I'll merge it and make a new release soon.

tomstewart89 commented 8 months ago

Should be fixed in v4.3, let me know if you have any other trouble. Thanks again!