Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy function #1

Open
davidbsp opened this issue Jan 11, 2018 · 4 comments
Open

Copy function #1

davidbsp opened this issue Jan 11, 2018 · 4 comments

Comments

@davidbsp
Copy link

Hi @tzikis and @eecharlie

I've been playing around with the MatrixMath library, and I have a very specific issue with the Copy function, which is giving me a huge headache:

Here is a minimal example:

  float X[10][40][3];    //an array of 10 matrices (40x3)
   
   //just fill it with 5's:
   for(int i=0; i<10; i++){
       for (int j=0; j<40; j++){
           for (int k=0; k<3; k++){
               X[i][j][k] = 5.0;
           }
       }
   }    

   float Q [10][40][3];    
   
  //now, I just want to copy the 1st matrix of X (located in X[0]) to Q[0]:
   Matrix.Copy( (float*)X[0], 3, 40, (float*)Q[0] );
   Serial.println("Copy done");

While the compiler doesn't complain about this code, the program segfaults after the copy operation...
Can you perhaps let me know why, and how can I solve this?

I also noticed that the Copy function receives n (cols) first and m (rows) after, as opposed to all the other functions in the library. Do you know the reason for this design choice? I would recommend to change the order for easiness of use.

Thanks!

@tzikis
Copy link
Member

tzikis commented Jan 11, 2018

Hi @davidbsp to be honest, I've got no clue! See, we're not the original developers of this library, we just put it up on github because a few of codebender's users wanted to use it for Arduino. The original library was bundled along with Wiring (wiring.org), which is a project the Arduino was based on

@eecharlie
Copy link

eecharlie commented Jan 11, 2018 via email

@fakedrake
Copy link

fakedrake commented Jan 11, 2018 via email

@davidbsp
Copy link
Author

Hi! It seems that my problem was memory management in the board.
Although I provided a minimal code, I was flashing the board with other stuff as well.
The code compiles, the board flashes without any issue. However, nothing happened when executing.

Just for reference:

  • there's nothing wrong with the index order.
  • "segfaults" was a bad choice of words, what I meant was: the board would block (red light flash) when executing the code.
  • other methods from the library work.
  • I am using a Particle Photon IoT device -- It has 128k of RAM.

When I erased other large variables (10 to 12 "float X[10][40][3]" 3D arrays), things started working again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants