Thread Subject: parenthesize the multiplication of X and it's transpose to make sure the result is hermitian

Subject: parenthesize the multiplication of X and it's transpose to make sure the result is hermitian

From: Juliette Salexa

Date: 5 Sep, 2011 00:02:07

Message: 1 of 10

Hello !

When I have A*X'*X ,

I get the the M-Lint warning: "parenthesize the multiplication of X and it's transpose to make sure the result is hermitian"

But what else course X'*X be doing other than X' times X ?

I don't even understand where to put the parentheses here: (X')*X ? (X'*X) ?

I googled this warning but found nothing - anyone know anything about it ?

Thanks!

Subject: parenthesize the multiplication of X and it's transpose to make

From: dpb

Date: 5 Sep, 2011 00:53:15

Message: 2 of 10

On 9/4/2011 7:02 PM, Juliette Salexa wrote:
> Hello !
>
> When I have A*X'*X ,
>
> I get the the M-Lint warning: "parenthesize the multiplication of X and
> it's transpose to make sure the result is hermitian"
>
> But what else course X'*X be doing other than X' times X ?
>
> I don't even understand where to put the parentheses here: (X')*X ?
No

> (X'*X) ?

Yes

The warning explicitly says "the multiplication of X and it[']s transpose".

There are two multiplications in the expression, both of which have the
same precedence and parsing is from left to right w/o any help to the
interpreter.

What happens is dependent on what A is.

--

Subject: parenthesize the multiplication of X and it's transpose to make

From: Juliette Salexa

Date: 5 Sep, 2011 01:18:11

Message: 3 of 10

dpb <none@non.net> wrote in message <j416ia$cpr$1@speranza.aioe.org>...


Thank you dpb. So are you telling me that there could be a situation in which
A*B*C could be different from A*(B*C) ?

Subject: parenthesize the multiplication of X and it's transpose to make

From: John D'Errico

Date: 5 Sep, 2011 01:29:09

Message: 4 of 10

"Juliette Salexa" wrote in message <j4180j$ohm$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <j416ia$cpr$1@speranza.aioe.org>...
>
>
> Thank you dpb. So are you telling me that there could be a situation in which
> A*B*C could be different from A*(B*C) ?

Welcome to the world of floating point arithmetic, where
exact associativity need not always apply.

John

Subject: parenthesize the multiplication of X and it's transpose to make

From: Juliette Salexa

Date: 5 Sep, 2011 02:11:29

Message: 5 of 10

"John D'Errico" <woodchips@rochester.rr.com> wrote in message

Thank you John. I didn't think of that .. I think floating point errors will be of the order of 10^-17, but imagine sometimes it's useful to have exact hermiticity.

So (A'*A) will do either the upper or lower triangle of A'*A and then fill in the other half by ensuring hermiticity ?

Thank you.

Subject: parenthesize the multiplication of X and it's transpose to make

From: John D'Errico

Date: 5 Sep, 2011 02:44:11

Message: 6 of 10

"Juliette Salexa" wrote in message <j41b4h$3ol$1@newscl01ah.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message
>
> Thank you John. I didn't think of that .. I think floating point errors will be of the order of 10^-17, but imagine sometimes it's useful to have exact hermiticity.
>
> So (A'*A) will do either the upper or lower triangle of A'*A and then fill in the other half by ensuring hermiticity ?
>
> Thank you.

That I do not know, nor can we be sure without talking
directly to someone who knows how matlab interprets
a line of code. Of course, this is also something that may
change with time too, based on optimizations employed.

The warning is definitely an indication that something
happens however.

John

Subject: parenthesize the multiplication of X and it's transpose to make sure the result is hermitian

From: Bruno Luong

Date: 5 Sep, 2011 06:10:25

Message: 7 of 10

"Juliette Salexa" wrote in message <j413hv$cj5$1@newscl01ah.mathworks.com>...
> Hello !
>
> When I have A*X'*X ,
>
> I get the the M-Lint warning: "parenthesize the multiplication of X and it's transpose to make sure the result is hermitian"
>
> But what else course X'*X be doing other than X' times X ?
>
> I don't even understand where to put the parentheses here: (X')*X ? (X'*X) ?
>

Did someone ever inform you that

(A*X')*X and A*(X'*X)

are
1. numerically different and
2. the cost of carry out both expression could be well different as well ?

Bruno

Subject: parenthesize the multiplication of X and it's transpose to make

From: Bruno Luong

Date: 5 Sep, 2011 06:47:28

Message: 8 of 10

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <j41d1q$8mv$1@newscl01ah.mathworks.com>...

>
> That I do not know, nor can we be sure without talking
> directly to someone who knows how matlab interprets
> a line of code. Of course, this is also something that may
> change with time too, based on optimizations employed.
>
> The warning is definitely an indication that something
> happens however.
>

I believe in the latest version expression such as

A*A'

is carried out without explicit transposition.

The following tests (2011A):

A=randn(500,100000);

C=A; tic; B=A*C'; t1=toc, % 2.4442 seconds

% Same as above but Matlab parser can't assume Hermitian
C=A; C(1)=A(1); tic; B=A*C'; t2=toc, % 3.2386 seconds

% Same as above, no transposition
C=A'; tic; B=A*C; t3=toc, % 3.3393 seconds

% Same as t1
tic; B=A*A'; t4=toc % 2.4223 seconds

% Time of an explicit transposition
tic; C=A'; toc % 0.442047 seconds.

tell me that there is indeed a simplification of calculation if Hermitian is detected (cases t1/t4). Matlab parser can't assume Hermitian in t2/t3. Avoiding explicit transposition explains t2 is similar (even shorter) to t3.

Bruno

Subject: parenthesize the multiplication of X and it's transpose to make

From: James Tursa

Date: 6 Sep, 2011 01:24:10

Message: 9 of 10

"Juliette Salexa" wrote in message <j41b4h$3ol$1@newscl01ah.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message
>
> Thank you John. I didn't think of that .. I think floating point errors will be of the order of 10^-17, but imagine sometimes it's useful to have exact hermiticity.
>
> So (A'*A) will do either the upper or lower triangle of A'*A and then fill in the other half by ensuring hermiticity ?

Yes. MATLAB calls symmetric BLAS routines to calculate this expression (e.g. DSYRK and DSYR2K) rather than the generic matrix multiply routine DGEMM. Those symmetric BLAS routines only physically calculate one triangle of the matrix, and then MATLAB fills in the other triangle to get the final result. This turns out to be faster and guarantees the symmetry of the result.

James Tursa

Subject: parenthesize the multiplication of X and it's transpose to make

From: Juliette Salexa

Date: 12 Sep, 2011 02:08:13

Message: 10 of 10

"James Tursa" wrote in message <j43snq$jdn$1@newscl01ah.mathworks.com>...


Thank you Bruno for showing me those very helpful benchmarks,
And thank you very much James Tursa for perfectly explaining just what made me curious!

Thanks both of you,
Hugs,
Juliette

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com