Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes for matrix initialisation #305

Merged
merged 6 commits into from
Jul 2, 2021

Conversation

conradsnicta
Copy link
Contributor

Mainly to take into account changes in Armadillo 10.5, where matrices are by default constructed with all elements set to zero.
The changes in this PR are backwards compatible with earlier versions of Armadillo.

Copy link
Member

@birm birm left a comment

Choose a reason for hiding this comment

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

Not sure why the appveyor builds couldn't all find your branch, but this looks good to me.

@conradsnicta
Copy link
Contributor Author

Not sure why the appveyor builds couldn't all find your branch, but this looks good to me.

MS software -- I have yet to find a single instance where it's reliable :)

Copy link
Member

@shrit shrit left a comment

Choose a reason for hiding this comment

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

Just curious, it seems there are only four checks, where are all other Linux check that were on Travis?

@zoq
Copy link
Member

zoq commented Jul 2, 2021

Just curious, it seems there are only four checks, where are all other Linux check that were on Travis?

We have to migrate from travis-ci.org to travis-ci.com, I did the migration, so if everything worked, we will see the travis build for future commits.

Copy link
Member

@zoq zoq left a comment

Choose a reason for hiding this comment

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

Looks great to me.

@@ -114,7 +114,7 @@ class SchwefelFunction
template<typename MatType = arma::mat>
MatType GetFinalPoint() const
{
MatType result(initialPoint.n_rows, initialPoint.n_cols);
MatType result(initialPoint.n_rows, initialPoint.n_cols, arma::fill::none);
Copy link
Member

Choose a reason for hiding this comment

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

Are there any plans to support specific value initialization in the constructor as well?

Copy link
Contributor Author

@conradsnicta conradsnicta Jul 2, 2021

Choose a reason for hiding this comment

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

I've done preliminary experiments on this in an experimental armadillo branch. It seems to work, but the implementation is convoluted and hacky.

The seemingly straightforward approach of simply specifying a value on the constructor via Mat<eT>(uword n_rows, uword n_cols, eT scalar_fill_value) is actually not intuitive, could be confused with the cube constructor, and doesn't follow the arma::fill pattern. However it does allow using the eT template parameter directly to specify the correct type of the scalar.

A more intuitive approach (from a user perspective) is to have a constructor along these lines: mat(n_rows, n_cols, fill::value(123.0)). The problem here is that we can't constrain the type of the scalar, as the definition of fill::value() is separate from the definition of mat. In the experimental code I opted to use Mat<eT>( uword n_rows, uword n_cols, fill::scalar_holder<scalar_type>& f ), where scalar_type is a separate template parameter, and fill::scalar_holder<scalar_type> is generated via arma::fill(scalar_value). Then the scalar specified by the user is internally converted to the eT element type of the matrix. I'm not 100% certain that all the possible conversions are valid and/or portable across compilers.

Copy link
Member

Choose a reason for hiding this comment

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

Could SFINAE work here, to ensure that whatever the provided scalar type is is castable to eT? It might also be possible to write an SFINAE overload where, when the scalar type cannot be converted to eT, a static_assert() is thrown. But, I am not sure if such complexity is warranted for that feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rcurtin Turns out a specific type of SFINAE in combination with a conversion operator did indeed help :) Gory details at the Gitlab repo.

@conradsnicta conradsnicta merged commit ec114f1 into master Jul 2, 2021
@conradsnicta conradsnicta deleted the conradsnicta-init-fixes branch July 2, 2021 03:35
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.

5 participants