Giter VIP home page Giter VIP logo

Comments (7)

WardBrian avatar WardBrian commented on June 18, 2024

This appears to be an issue with assigning to the SoA matrix type.

The specific error is a segmentation fault in
void stan::model::internal::assign_impl<stan::math::var_value<Eigen::Matrix<double, -1, 1, 0, -1, 1>, void>&, stan::math::var_value<Eigen::VectorBlock<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, -1>, void>, (void*)0>(stan::math::var_value<Eigen::Matrix<double, -1, 1, 0, -1, 1>, void>&, stan::math::var_value<Eigen::VectorBlock<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, -1>, void>&&, char const*)

Whether this issue should be transferred to stan-dev/stan or stan-dev/stanc3 depends on whether or not we think these vectors should be marked as SoA. If you change the code to x = y[:] it works fine, so I suspect this is a bug in the C++, not in the compiler's behavior

@SteveBronder thoughts?

from math.

SteveBronder avatar SteveBronder commented on June 18, 2024

I think this is an issue with the assign functions in the Stan repo. I can take a look tmrw. My best guess is an off by one error

from math.

WardBrian avatar WardBrian commented on June 18, 2024

I tried writing a test which exposes this in the Stan repo and found something interesting. The issue seems to be that x is not initialized before it is assigned to. E.g, this segfaults:

  var_value<Vec> x;
  auto y = conditionally_generate_linear_var_vector<Vec>(3, 10);

  assign(x, rvalue(y, "y", index_min_max(1,3)), "");

but this doesn't:

  var_value<Vec> x = conditionally_generate_linear_var_vector<Vec>(3,1);
  auto y = conditionally_generate_linear_var_vector<Vec>(3, 10);

  assign(x, rvalue(y, "y", index_min_max(1,3)), "");

This seems to be to be different than the behavior for non-SOA types which allow you to assign to them if they're uninitialized, I believe. We could try to address this in the compiler (by never omitting the initialization for SoA types) or we could improve the logic in assigning these types.

@SteveBronder thoughts?

from math.

WardBrian avatar WardBrian commented on June 18, 2024

This is the specific line that segfaults in math when the LHS is an uninitialized var matrix:

arena_t<plain_type_t<T>> prev_val = vi_->val_;

This is only triggered I believe if the RHS is a expression? Otherwise, this overload of operator= is used and no segfault occurs.

from math.

SteveBronder avatar SteveBronder commented on June 18, 2024

I can take a look at this today

from math.

SteveBronder avatar SteveBronder commented on June 18, 2024

I thought harder about this and think that this may be a bug in the compiler optimizations.

We do assume in the var_value that the value is not a nullptr, otherwise we have to have constant checks and throws everywhere. I think this is an issue with the optimization pass that removes the NA defaults if we immediately do an assignment. I'll look into this more tmrw

from math.

WardBrian avatar WardBrian commented on June 18, 2024

I have an old compiler branch which removed that pass from SoA types, I wasn’t sure if it was the “right” fix or not, since the behavior for these overloads of operator= is very different from the normal AoS ones

from math.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.