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

SmallMatrix: Matrix class with compile time size #4176

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

WeiqunZhang
Copy link
Member

@WeiqunZhang WeiqunZhang commented Oct 1, 2024

@zingale
Copy link
Member

zingale commented Oct 1, 2024

it would be good to have a .setVal() method to set all elements to a value.

@WeiqunZhang WeiqunZhang force-pushed the smallmatrix branch 2 times, most recently from 932bd1e to 5c6ce39 Compare October 2, 2024 00:14
@WeiqunZhang WeiqunZhang marked this pull request as ready for review October 2, 2024 00:14
@WeiqunZhang WeiqunZhang force-pushed the smallmatrix branch 2 times, most recently from b1db197 to 6f827e4 Compare October 2, 2024 00:25
Add amrex::SmallMatrix class with compile time size.
@WeiqunZhang
Copy link
Member Author

Notes on why SmallMatrix matrix{} is zero initialized.

SmallMatrix is not an aggregate, because it has a user declared default
constructor. The rule is that, for SmallMatrix matrix{} with an empty
brace-enclosed initializer list, value-initialization is performed. The
effects of value-initialization of SmallMatrix (which has a user-declared
but not user-provided default constructor) are that the matrix object is
first zero-initialized and then the object's default constructor is
applied. Since the default constructor does nothing, the final result is
the object is zero-initialized.

Why is SmallMatrix's default constructor user-declared not user-provided?
It's because we first declare it with SmallMatrix () = default.

Reference:
https://en.cppreference.com/w/cpp/language/list_initialization
https://en.cppreference.com/w/cpp/language/value_initialization
https://en.cppreference.com/w/cpp/language/zero_initialization

@ax3l
Copy link
Member

ax3l commented Oct 3, 2024

Is SmallMatrix<Real, N, M> m; also zero-defined then or is it allocated but values are undefined?

@ax3l
Copy link
Member

ax3l commented Oct 3, 2024

FYI @cemitch99

@WeiqunZhang
Copy link
Member Author

It's uninitialized by default.

/**
 * \brief Default constructor
 *
 * The data are uninitialized by default. If you want to initialize
 * to zero, you can do `SmallMatrix<T,NRows,NCols> M{};`.
 */
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
constexpr SmallMatrix () = default;

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

That is super useful, I think that is all we currently need 🚀 ✨

Comment on lines +62 to +66
auto v3 = SmallVector<double,3>::Zero();
v3[0] = 1.;
v3(1) = 2.;
v3[2] = 3.;
auto m33 = SmallMatrix<double,3,3>::Identity();
Copy link
Member

Choose a reason for hiding this comment

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

Nice, very useful!

@ax3l ax3l merged commit 4ec03b8 into AMReX-Codes:development Oct 3, 2024
59 checks passed
@ax3l ax3l self-assigned this Oct 3, 2024
@WeiqunZhang WeiqunZhang deleted the smallmatrix branch October 3, 2024 23:04
WeiqunZhang added a commit to WeiqunZhang/amrex that referenced this pull request Oct 4, 2024
WeiqunZhang added a commit that referenced this pull request Oct 4, 2024
ax3l added a commit to ax3l/impactx that referenced this pull request Oct 10, 2024
Update AMReX to the latest `development` commit, so we can start
using the `SmallMatrix` math from
AMReX-Codes/amrex#4176
ax3l added a commit to ECP-WarpX/impactx that referenced this pull request Oct 10, 2024
* AMReX: `development`

Update AMReX to the latest `development` commit, so we can start
using the `SmallMatrix` math from
AMReX-Codes/amrex#4176

* Update `pyAMReX` to latest `development`

Use latest commit in `development` for breaking AMReX changes.
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.

3 participants