Skip to content

Conversation

@rcurtin
Copy link
Member

@rcurtin rcurtin commented Feb 20, 2025

This fixes #3886. Basically, the crash there happens like this:

  • When a user calls .get_cpp_params() on an mlpack object in Python, this uses cereal to serialize the C++ object to JSON.
  • We then load the JSON object into a Python dict with Python's json.loads().
  • We detect any Armadillo objects in the dict and convert them to numpy objects.
  • During that conversion, we look for the elem key in the dictionary representation of the Armadillo object; but the code crashes, because for an empty Armadillo matrix (e.g. 0 rows or 0 columns), no elem key is serialized by cereal...

so, I addressed this by checking if the number of rows or columns is 0, and if so, returning an empty numpy object with the correct size.

Copy link
Contributor

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me too

@conradsnicta conradsnicta merged commit d035e1c into mlpack:master Feb 24, 2025
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem getting coefficients in linear regression

4 participants