Skip to content

Conversation

@BenBrock
Copy link
Collaborator

Add specifiers triangle and diagonal specifiers for triangular operations. These are directly based on the tag classes from std::linalg [link].

Implementations should statically inspect the types of the triangle and diagonal tags in a manner similar to the following example (again directly borrowed from std::linalg):

template<class Triangle>
void triangular_matrix_vector_2x2_product(
       mdspan<const float, extents<int, 2, 2>> m,
       Triangle t,
       mdspan<const float, extents<int, 2>> x,
       mdspan<float, extents<int, 2>> y) {

  static_assert(is_same_v<Triangle, lower_triangle_t> ||
                is_same_v<Triangle, upper_triangle_t>);

  if constexpr (is_same_v<Triangle, lower_triangle_t>) {
    y[0] = m[0,0] * x[0]; // + 0 * x[1]
    y[1] = m[1,0] * x[0] + m[1,1] * x[1];
  } else { // upper_triangle_t
    y[0] = m[0,0] * x[0] + m[0,1] * x[1];
    y[1] = /* 0 * x[0] + */ m[1,1] * x[1];
  }
}

Copy link
Contributor

@spencerpatty spencerpatty left a comment

Choose a reason for hiding this comment

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

These look great and mirroring std::linalg is the right choice, Approved once CI completes

@BenBrock BenBrock force-pushed the triangle_specifiers branch from 058fb25 to 0df349d Compare February 19, 2025 01:26
@BenBrock BenBrock merged commit fb87063 into main Feb 19, 2025
5 checks passed
@BenBrock BenBrock deleted the triangle_specifiers branch February 19, 2025 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants