C++ Logo

sg19

Advanced search

Re: [isocpp-lib-ext] Restoring row and column vectors to the linear algebra proposal

From: Mark Hoemmen <mark.hoemmen_at_[hidden]>
Date: Mon, 1 May 2023 16:01:09 -0600
On Mon, May 1, 2023 at 3:43 PM Daveed Vandevoorde <daveed_at_[hidden]> wrote:
> On May 1, 2023, at 5:37 PM, Mark Hoemmen via Lib-Ext <lib-ext_at_[hidden]> wrote:
> > Outer products have a common use case which isn't represented in the
> > proposal: Rank-1 update of an existing matrix. If you try to spell
> > that using overloaded arithmetic operators, you get the following,
> > assuming that x is a row vector and y is a column vector.
>
> (Did you mean x is a column and y a row?)

Yes; thank you! : - )

> > A += x * y;
> >
> > A naive implementation would always create a new temporary matrix to
> > hold the outer product result x * y. The only way NOT to do that, and
> > still retain the syntax "A += x * y," would be to use expression
> > templates. ("x * y" would return outer_product_expression<X, Y>, and
> > matrix::operator+=(outer_product_expression<X, Y>&&) would perform a
> > rank-1 update.)
>
> Right. But expression templates aren’t a panacea for matrix-based operations. E.g., if y is replaced by an expression that depends on A, you run into aliasing issues.

That's right. P1673 chose to avoid the entire issue by not using
overloaded arithmetic operators to represent such operations.

mfh

Received on 2023-05-01 22:01:20