rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
163 stars 29 forks source link

FixedArray of rank 1 fails to get its gradient #10

Closed gray-heron closed 5 years ago

gray-heron commented 5 years ago

Hello, I found that the following code:

    adept::Stack main_stack;
    adept::FixedArray<adept::Real, true, 2> v({2, 3});
    main_stack.new_recording();
    adept::aReal r = adept::sum(v); 

    r.set_gradient(1.0);
    main_stack.reverse();

    std::cerr << v.get_gradient();

throws at _v.getgradient():

terminate called after throwing an instance of 'adept::gradient_out_of_range' what(): Gradient index out of range: probably aReal objects have been created after a set_gradient(s) call

If I substitute the first line with:

adept::FixedArray<adept::Real, true, 2, 2> v({{2, 3}, {2, 3}});

then it all works well.

Am I doing something wrong? This happens to me on Linux both with GCC 5.4.0 and Clang 6.0.

rjhogan commented 5 years ago

Bug. Latest commit should fix - please let me know. Thanks!

gray-heron commented 5 years ago

Yes, it works fine now. Thank you.