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

[LWG 19] P1673R13 A free function linear algebra interface based on the BLAS #6704

Merged
merged 15 commits into from Dec 18, 2023

Conversation

jensmaurer
Copy link
Member

@jensmaurer jensmaurer commented Nov 17, 2023

Fixes #6677
Fixes cplusplus/papers#557

Issues found and fixed in separate commits:

  • synopsis: missing closing } for namespace at end of synopsis
  • synopsis: T dot(...: "T" was never introduced; did you mean "Scalar"?
  • synopsis: template<class Scalar, class ExecutionPolicy, ...> void symmetric_matrix_rank_k_update: strange order of template parameters
  • There is lots of mentions of "BLAS", but no expansion of the acronym, and no bibliography entry for the BLAS specification.
  • [linalg.reqs.alg] p2.3 says "otherwise", but there is no preceding "if" that would match.
  • [linalg.layout.packed.obs] p3 (p13 in the paper https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/P1673R13.html#wording ): p3 would benefit from having the "let" in p4 come earlier, so that it can be used.
  • The introductory notes for [linalg.helpers.mandates] vs. [linalg.helpers.precond] are different.
  • The specification for dotc seems overly complicated. In particular, the auto-returning functions construct a type "T",
    which is a bit complicated. Instead, they could just say "return dot(conjugated(v1), v2)" and rely on the auto-returning "dot" function to do the right thing. NOT FIXED in this pull request
  • [linalg.algs.blas1.ssq] had a duplicate definition for struct sum_of_squares_result (also present in the synopsis).
  • [linalg.algs.blas1.ssq] talks about "LAPACK", but everywhere else, we talk about "BLAS". We need a bibliography entry for that.
  • Pervasive issue in the paper: It tries to convert "decltype(something)" to a type. You can't convert types to other types; you can only convert expressions to types. (Because the value category of the expression influences convertibility.) NOT FIXED in this pull request
  • The example scaled_matvec_2 in [linalg.algs.blas2.gemv] uses the "updating matrix-vector product" function that is defined later. I suggest to split the example to avoid the forward reference.
  • Some functions are available with an "alpha" scalar and without. Move functions with "alpha" first.
  • [linalg.algs.blas3.rankk] p7 (for hermitian_matrix_rank_k_update) does not show "alpha" in the formula of the effects. That feels like a bug.
  • [linalg.algs.blas3.rank2k] p6 (for hermitian_matrix_rank_2k_update) uses ^T, not ^H, in the formula. Is that correct?
  • There are a few cross-references to [linalg.algs], which doesn't exist. I've switched them to [linalg].

@jensmaurer jensmaurer added this to the post-2023-11 milestone Nov 17, 2023
@jensmaurer jensmaurer changed the title P1673R13 A free function linear algebra interface based on the BLAS [LWG 19] P1673R13 A free function linear algebra interface based on the BLAS Nov 17, 2023
@jensmaurer jensmaurer force-pushed the motions-2023-11-lwg-19 branch 2 times, most recently from 3a8aa93 to aa6d7e9 Compare November 17, 2023 21:37
@jensmaurer jensmaurer marked this pull request as ready for review November 17, 2023 22:09
@Dani-Hub
Copy link
Member

@jensmaurer The definition of imag-if-needed for sub-bullet (1.2) is incorrect, I assume that

otherwise, ((void)E, T).

should be either

otherwise, ((void)E, T{}).

as the paper says or

otherwise, ((void)E, T()).

@jensmaurer jensmaurer force-pushed the motions-2023-11-lwg-19 branch 2 times, most recently from 1e16e8c to 51afb68 Compare November 18, 2023 20:02
@jensmaurer
Copy link
Member Author

@Dani-Hub, thanks for the hint:

The definition of imag-if-needed for sub-bullet (1.2) is incorrect

Fixed; missing backslashes in LaTeX.

@burblebee
Copy link
Contributor

@JohelEGP @jwakely (or any other volunteers) This one is huge - how about we split this review up between us? This is looks to be about fair:

  • 28-28.9.2
  • 28.9.3-28.9.13
  • 28.9.14-end

I'll take the last one, 28.9.14-end.

Copy link
Contributor

@burblebee burblebee left a comment

Choose a reason for hiding this comment

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

not done, but probably done for the night - here's what I have so far...

constexpr size_t num_rows = 5;
constexpr size_t num_cols = 6;

// y = 3.0 * A * x
Copy link
Contributor

@burblebee burblebee Nov 18, 2023

Choose a reason for hiding this comment

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

\tcode needed (same for C++ comments elsewhere)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm... operator* is not provided for the involved types, so formatting this as C++ code throughout isn't correct.
Formatting y, A, x as C++ code would work, but then this is almost indistinguishable from all-code.

@tkoeppe , what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably write the code as code, but the whole expression as in maths. We can either use \times or \cdot or just juxtaposition for the various kinds of multiplication.

But we can clean that up later, too.

source/numerics.tex Outdated Show resolved Hide resolved
source/numerics.tex Show resolved Hide resolved
Comment on lines +13654 to +13752
void scaled_matvec_1(mdspan<double, extents<size_t, num_rows, num_cols>> A,
mdspan<double, extents<size_t, num_cols>> x, mdspan<double, extents<size_t, num_rows>> y) {
matrix_vector_product(scaled(3.0, A), x, y);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Format as it is in the paper - it's easier to see what's happening

Copy link
Member Author

Choose a reason for hiding this comment

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

I find all of this rather verbose. Maybe we should invent type aliases for these.
using Matrix = mdspan<double, extents<size_t, num_rows, num_cols>>;

@tkoeppe , what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that would be helpful. Let's do that as a follow-up.

Comment on lines 13660 to 13661
void scaled_matvec_2(mdspan<double, extents<size_t, num_rows, num_cols>> A,
mdspan<double, extents<size_t, num_cols>> x, mdspan<double, extents<size_t, num_rows>> y) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Format as it is in the paper - it's easier to see what's happening

source/numerics.tex Show resolved Hide resolved
source/numerics.tex Outdated Show resolved Hide resolved
source/numerics.tex Outdated Show resolved Hide resolved
source/numerics.tex Show resolved Hide resolved
source/numerics.tex Show resolved Hide resolved
@JohelEGP
Copy link
Contributor

@JohelEGP @jwakely (or any other volunteers) This one is huge - how about we split this review up between us? This is looks to be about fair:

* 28-28.9.2

* 28.9.3-28.9.13

* 28.9.14-end

I'll take the last one, 28.9.14-end.

In that case, I'll take the first one.

Copy link
Contributor

@burblebee burblebee left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes so far!

Still have issues with:

  • \tcode vs. italics used to represent the same variables (in paper also),
  • spaces between variables in math expressions (looks like separate expressions, but without space as in paper, the string looks like a single variable), and
  • missing "is \tcode{true}" after some expressions (in paper also)

source/numerics.tex Show resolved Hide resolved

\pnum
\effects
Computes $z = y + A x$.
Copy link
Contributor

@burblebee burblebee Nov 22, 2023

Choose a reason for hiding this comment

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

I disagree. At the very least, preface this section with what /A/, etc, are. But really, they are the variables in the prototypes, so why wouldn't we just use them directly? Also, having 2 variables right next to each other with only a space and no operator between them is meaningless in either math or C++ code. At least the paper didn't include a space, so could be read mathematically as a multiplication, but doing that gets confusing because the string of variables can look like a single variable

source/numerics.tex Outdated Show resolved Hide resolved
source/numerics.tex Show resolved Hide resolved
@jensmaurer
Copy link
Member Author

@jwakely , is there any specific text in the paper (that I'm currently overlooking) that would associate input math variables with same-named C++ function parameters? [linalg.general] p1.4 talks about output variables only.

Copy link
Contributor

@burblebee burblebee left a comment

Choose a reason for hiding this comment

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

Just 1 last required change

Computes a vector $x'$ such that $b = A x'$,
and assigns each element of $x'$ to the corresponding element of $x$.
If no such $x'$ exists,
then the elements of \tcode{x} are valid but unspecified.
Copy link
Contributor

@burblebee burblebee Nov 22, 2023

Choose a reason for hiding this comment

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

This x should be in math font (not \tcode) for consistency

@jwakely
Copy link
Member

jwakely commented Dec 18, 2023

@jwakely , is there any specific text in the paper (that I'm currently overlooking) that would associate input math variables with same-named C++ function parameters? [linalg.general] p1.4 talks about output variables only.

Erm, possibly not. We have similar problems in [rand], see #4295 for an old attempt to fix it there.

@tkoeppe
Copy link
Contributor

tkoeppe commented Dec 18, 2023

Thank you all very much for the reviews, and special thanks to Jens for the drafting! I'll merge this now, and we can perform follow-up cleanup afterwards. Thanks again!

@tkoeppe tkoeppe merged commit 7f97465 into main Dec 18, 2023
4 checks passed
@jensmaurer jensmaurer deleted the motions-2023-11-lwg-19 branch March 23, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants