Skip to content

node child _resize not found #122

Open

Description

@kongdd

I got an error when convert HANTS.m in the following MATLAB file.

https://cn.mathworks.com/matlabcentral/fileexchange/38841-matlab-implementation-of-harmonic-analysis-of-time-series--hants-

`kong@KONG:/mnt/c/Users/kongdd/m2cpp-master$ m2cpp HANTS.m
Traceback (most recent call last):
File "/usr/local/bin/m2cpp", line 99, in

matlab2cpp.main(args)  

File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/init.py", line 230, in main
builder.project.translate(args)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/frontend.py", line 171, in translate
backend.translate(self, opt)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/backend.py", line 479, in translate
map(translate, node)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/backend.py", line 493, in translate
translate_one(node, opt)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/backend.py", line 557, in translate_one
value = value(node)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/rules/cube.py", line 135, in Set
node = node.resize() # matlab to armadillo fix for cubes
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/frontend.py", line 289, in resize
backend.resize(self)
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/backend.py", line 234, in resize
if node["_resize"]:
File "/usr/local/lib/python2.7/dist-packages/matlab2cpp/node/frontend.py", line 404, in getitem
raise IndexError("node child "%s" not found" % i)
IndexError: node child "_resize" not found`

Activity

  1. taiwuchiang commented on Sep 20, 2017

    @taiwuchiang
    Collaborator

    Hello:
    I have seen this same error too. Could someone explain what it means? Thanks.

  2. added a commit that references this issue on Sep 21, 2017
  3. jonathf commented on Sep 21, 2017

    @jonathf
    Owner

    Hey!

    I am unable to find the file you are referring to, so I am struggling to recreate the problem.
    But from the error message alone I have made a proposed fix in master. So try it out and tell me if it works or not. If not, please provide me with some code that I can use to duplicate the problem with.

  4. taiwuchiang commented on Sep 22, 2017

    @taiwuchiang
    Collaborator

    Thank you so much for such quick support.

    Yes, let me get your update and test if it fixed the problem. If not, I will create a codelet that can reproduce the problem.

    I truly believe m2cpp is such a wonderful tool and appreciate you share it with the community. It works even better than Mathworks' Matlab Coder in a sense that it allows linking to different underlying BLAS library optimized for various platforms.

    I wish to contribute to this project. Even though I am not a Python programmer, welcome to let me know if anything I can do on my side.

    Taiwu

  5. taiwuchiang commented on Sep 22, 2017

    @taiwuchiang
    Collaborator

    Back

    Archive

    Move

    Delete

    Spam

    Re: [jonathf/matlab2cpp] node child _resize not found (#122)
    Sent

    Tai-Wu Chiang taiwuchiang@yahoo.com
    To:
    jonathf/matlab2cpp
    ,
    Jonathan Feinberg
    Cc:
    Comment

    Sep 21 at 5:05 PM

    Jonathan:
    You have checked your change into the deprecated branch, right? I got it and merged into the 1.0 version which is the emc2norway fork. Is it right?

    So it worked good for that particular problem.

    Then I found there is another issue with Matlab syntax. If you write a matlab script like the following:

        dRdm1 = zeros(9,21);
                 dRdm1([1 5 9],1) = ones(3,1); 
    

    The m2cpp will give an exception at
    # uvec + scalar
    elif dim0 > 0 and dim1 == 0:
    error--> index = node[0].str.index('(')
    return "%(name)s(" + "m2cpp::span" + node[0].str[index:] +
    ", m2cpp::span(" + arg1 + ", " + arg1 + "))"

    Because node[0].str doesn't have '(' there.
    But if I change the matlab script to

        dRdm1(1,1) = 1;
        dRdm1(5,1) = 1;
        dRdm1(9,1) = 1;
    

    It works fine this way.

    So I guess it's just a small glitch. We just have to write Matlab in a simpler way, not to confuse the translator.

    Thanks.

    Taiwu

  6. jonathf commented on Sep 25, 2017

    @jonathf
    Owner

    Hey.

    Yes, the update is to my local master.

    It is a long story, but the emc2-fork was created for an EU-project that I was part of in the beginning. I believe the project is over, so moving back to my own branch is on my agenda. But you are right, there are some updates there that I should include here. I will try to get to it soon, together with your bug.

    As for help, that is much appreciated.
    Addressing bugs the way you are doing is very helpful.
    And if there is a non-python task on the agenda that needs looking in to, I will let you know.

  7. taiwuchiang commented on Sep 25, 2017

    @taiwuchiang
    Collaborator

    Great! This is such a valuable project and will benefit lots people in the long run. Yes, please let me know things like testing or the like that I can do, perhaps with some contributions.

  8. taiwuchiang commented on Sep 27, 2017

    @taiwuchiang
    Collaborator

    Hi Jonathan:
    I have used your m2cpp to translate a Matlab script of about 700 lines to C++. Overall, it worked well for 95% of time but there are 5% of code needs manual fixes. Even though it doesn't do 100% good translation, I think it is still a very valuable tool to use. It shortened my development time from 2 weeks to around 2 days.

    I have now got quite familiar with using the tool. There are some mistakes in translation are frequently repeating itself and I can easily spot and fix them in the C++ code. Do you like me to make a list of such things?

    I understand you are doing this as a volunteer and may not have time to do all the fixes by yourself. So I don't want to overwhelm you with a whole list of bugs unless you like to.

    However, I do see the values of such tool and wish to make it works better. If you can guide me, then I may be able to fix some of the easy bugs.

    Thanks,

    Taiwu

  9. jonathf commented on Sep 30, 2017

    @jonathf
    Owner

    Okay, I have gotten back into the mode of working a little on this project. Since this is one of my older project, I see some need for TLC. I have started the work on that now.

    As I almost do not work with C++ these days, translation suggestions would be very useful.

    If you don't mind:

    • Reduce the problems down to minimal examples.
    • Include the Matlab code to be translate.
    • Include the current translation (or crash report).
    • Include a suggestion for what it should do or do differently.
    • Include the full node tree when you use the flag -T if no crash.

    This will drastically reduce the amount of work for me on each problem.

  10. taiwuchiang commented on Oct 3, 2017

    @taiwuchiang
    Collaborator

    so happy to hear this. I will be glad to do so.
    So should I do this based on which branch? Right now, I am using emc2norway/m2cpp. But if you want to use yours, it's fine too. I am not sure what exactly the differences between them.
    Thanks

  11. jonathf commented on Oct 3, 2017

    @jonathf
    Owner

    As soon as you noted the discrepancy I merged the emc2norway remote into the "depricated" master branch. So use that one. (I also removed the deprecation message, as it should no longer be considered deprecated.)

  12. taiwuchiang commented on Oct 4, 2017

    @taiwuchiang
    Collaborator

    Ok, here is the first bug report: (Matlab script is embedded in the C++ code as comments)

    C++ code translated:

    #include
    #include "mconvert.h"
    using namespace arma ;

    int main(int argc, char** argv)
    {
    double b;
    mat A;
    // A=rand(10,10)
    A = arma::randu(10, 10);
    // b=sum(A(:))
    b = double(arma::as_scalar(arma::sum(A(span(0, A.n_rows - 1)))));
    return 0;
    }

    Errors:
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    Suggested (working) C++ code:

    int main(int argc, char** argv)
    {
    double b;
    mat A;
    // A=rand(10,10)
    A = arma::randu(10, 10);
    // b=sum(A(:))
    b = double(arma::sum(arma::vectorise(A)));
    return 0;
    }

    Tree
    Program program TYPE /Users/taiwu/code/brava/Machine_Vision/test.m
    | Includes program TYPE
    | | Include program TYPE #include
    | | 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 A
    1 1| | | | Var double double b
    1 1| | | Returns func_return TYPE
    1 1| | | Params func_return TYPE
    1 1| | | Block code_block TYPE
    1 1| | | | Assign reserved mat rand
    1 1| | | | | Var mat mat A
    1 3| | | | | Get reserved mat rand
    1 8| | | | | | Int int int
    1 11| | | | | | Int int int
    2 16| | | | Assign reserved rowvec sum
    2 16| | | | | Var double double b
    2 18| | | | | Get reserved rowvec sum
    2 22| | | | | | Get mat mat A
    2 24| | | | | | | All expression uvec
    | 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

    Comment

    Armadillo has a function call 'vectorise' does the thing.

  13. taiwuchiang commented on Oct 4, 2017

    @taiwuchiang
    Collaborator

    same thing can be done for 'cube' as the following:

    {
    double b;
    cube A;
    // A=rand(10,10,10)
    A = arma::randu(10, 10, 10);
    // b=sum(A(:))
    b = double(arma::sum(arma::vectorise(A)));
    return 0;
    }

  14. taiwuchiang commented on Oct 4, 2017

    @taiwuchiang
    Collaborator

    Thanks.
    I have a day job (I guess you have one too) so I can only use my night time to do this. I will gradually (and slowly) add more bugs I encountered. Thanks for taking time for finding fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions