Make `general_mat_mul`/`general_mat_vec_mul` more discoverable

Open
#927 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust

Research direction

Start with the linked general_mat_mul and general_mat_vec_mul documentation in the linalg module, then read the docs for the dot methods and Dot trait. Clarify whether the change should only improve documentation or also add the proposed GeneralDot trait and ArrayBase methods; done means the agreed functionality is discoverable and documented.

Written by the indexing model from the issue text.

Description

The general_mat_mul and general_mat_vec_mul functions are not easy to find, since they're in the linalg module while most other functionality is available either at the top level of the crate or as methods on the array types.

At a minimum, we should mention them in the docs for the dot methods and Dot trait.

However, I think it would also be useful to expose the functionality as methods on ArrayBase. I'd suggest adding a trait like this:

/// General matrix multiplication.
pub trait GeneralDot<A, Rhs1, Rhs2> {
    /// Perform general matrix-matrix multiplication, modifying `self` in-place.
    ///
    /// Compute C ← α A B + β C, where `self` is C.
    ///
    /// The array shapes must agree in the way that if `a` is *M* × *N*, then
    /// `b` is *N* × *K* and `self` is *M* × *K*.
    ///
    /// ***Panics*** if array shapes are not compatible<br>
    /// *Note:* If enabled, uses blas `gemm` for elements of `f32, f64` when memory
    /// layout allows.  The default matrixmultiply backend is otherwise used for
    /// `f32, f64` for all memory layouts.
    fn mul_add_scaled_dot_inplace(
        &mut self,
        beta: A,
        alpha: A,
        a: &Rhs1,
        b: &Rhs2,
    );
}

and then add mul_add_scaled_dot_inplace methods which use this trait to ArrayBase<S, Ix1> and ArrayBase<S, Ix2>. What do you think?

Dominant language
Rust
Stars
4.3k
Forks
391
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-ndarray/ndarray

All issues in rust-ndarray/ndarray

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.