jonathf / matlab2cpp

Convertion program from Matlab to C++ using Armadillo
BSD 3-Clause "New" or "Revised" License
181 stars 64 forks source link

subtract 1 #125

Closed taiwuchiang closed 7 years ago

taiwuchiang commented 7 years ago

Hi Jonath:

Here is another bug I found. The following Matlab script when converted there is an error.

Matlab: J = zeros(6,12); X_kk = ones(3,3); J(1:2:end,[1 4 7]) = -X_kk';

C++ (wrong):

int main(int argc, char** argv) { mat J, X_kk ; urowvec _aux_urowvec_1 ; J = arma::zeros(6, 12) ; X_kk = arma::ones(3, 3) ; uword __aux_urowvec_1 [] = {1, 4, 7} ; _aux_urowvec_1 = urowvec(__aux_urowvec_1, 3, false) ; J(m2cpp::span(1-1, 2, J.n_rows-1), _aux_urowvec_1) = -arma::trans(X_kk) ; return 0 ; }

C++ (correct):

int main(int argc, char** argv) { mat J, X_kk ; urowvec _aux_urowvec_1 ; J = arma::zeros(6, 12) ; X_kk = arma::ones(3, 3) ; uword __aux_urowvec_1 [] = {1, 4, 7} ; _aux_urowvec_1 = urowvec(__aux_urowvec_1, 3, false) ; J(m2cpp::span(1-1, 2, J.n_rows-1), _aux_urowvec_1 - 1) = -arma::trans(X_kk) ; return 0 ; }

The _aux_urowvec_1 should subtract one from it.

Thanks.

taiwuchiang commented 7 years ago

Here is the Tree:

 Program    program      TYPE    /Users/taiwu/code/brava/Machine_Vision/test.m
 | Includes   program      TYPE    
 | | Include    program      TYPE    #include <armadillo>
 | | Include    program      TYPE    #include "mconvert.h"
 | | Include    program      TYPE    using namespace arma ;

1 1| Funcs program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m 1 1| | Main func_return TYPE main 1 1| | | Declares func_return TYPE
1 1| | | | Var mat mat J 1 1| | | | Var mat mat X_kk 1 1| | | | Var unknown urowvec _aux_urowvec_1 1 1| | | Returns func_return TYPE
1 1| | | Params func_return TYPE
1 4| | | Block code_block TYPE
1 4| | | | Assign reserved mat zeros 1 4| | | | | Var mat mat J 1 8| | | | | Get reserved mat zeros 1 14| | | | | | Int int int
1 16| | | | | | Int int int
2 22| | | | Assign reserved mat ones 2 22| | | | | Var mat mat X_kk 2 29| | | | | Get reserved mat ones 2 34| | | | | | Int int int
2 36| | | | | | Int int int
1 4| | | | Assign matrix uword
1 4| | | | | Var urowvec urowvec _aux_urowvec_1 3 51| | | | | Matrix matrix urowvec 3 52| | | | | | Vector matrix irowvec 3 52| | | | | | | Int int int
3 54| | | | | | | Int int int
3 56| | | | | | | Int int int
3 41| | | | Assign expression mat
3 41| | | | | Set mat mat J 3 43| | | | | | Colon expression uvec
3 43| | | | | | | Int int int
3 45| | | | | | | Int int int
3 47| | | | | | | End expression int
3 41| | | | | | Var unknown urowvec _aux_urowvec_1 3 62| | | | | Neg expression mat
3 63| | | | | | Ctranspose expression mat
3 63| | | | | | | Var mat mat X_kk | Inlines program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m | Structs program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m | Headers program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m | Log program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m

taiwuchiang commented 7 years ago

fixed