tomstewart89 / BasicLinearAlgebra

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

Slicing matrix (0,0) element #17

Closed RafalRoszkowski closed 6 years ago

RafalRoszkowski commented 6 years ago

Hey,

Let's say I've got Matrix Matrix<3, 4> M={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

I'm unable to get any sub matrix containing 0. Let's say just {0} Serial << M.Submatrix(Slice<0, 1>(), Slice<0, 1>());// gives {1} Serial << M.Submatrix(Slice<0, 1>(), Slice<0, 2>());// gives {1,2} this gives hope Serial << M.Submatrix(Slice<0, 1>(), Slice<-1, 2>()) // gives {1,2,3} Serial << M.Submatrix(Slice<0, 1>(), Slice<1, 2>()); // {1} again Serial << M.Submatrix(Slice<0, 2>(), Slice<0, 1>());// gives {2,6} Serial << M.Submatrix(Slice<0, 2>(), Slice<0, 2>());// gives {{2,3},{6,7}} Serial << M.Submatrix(Slice<0, 0>(), Slice<0, 1>());// gives "{"

It seems to me:

template<int rows, int cols, class MemT> template<int rowStart, int rowEnd, int colStart, int colEnd> Matrix<rowEnd-rowStart,colEnd-colStart,Reference > Matrix<rows,cols,MemT>::Submatrix(Slice<rowStart,rowEnd>, Slice<colStart,colEnd>) const { Reference ref(delegate, rowStart, rowEnd); //<- rowEnd should be colStart line 140 return Matrix<rowEnd-rowStart,colEnd-colStart,Reference >(ref); }

Regards Raffe :)

tomstewart89 commented 6 years ago

Hi Raffe, You're absolutely correct, thanks for spotting that!

I can make this change myself but are you sure you don't want to submit a PR for it instead? It's a nice way of showing your contribution to the library.

RafalRoszkowski commented 6 years ago

Hey,

I did something, since you encourage me to do so. Since I'm brand new to github, just tell me if it works or if it doesn't tell me what to do or what should I google for.

tomstewart89 commented 6 years ago

Ok so you've created a fork from my repo, next you just need to make the changes you've suggested in your fork and make a pull request. For now you can just edit the file in the browser here here. Then once you've made the change you can make a pull request by following this guide