octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dot product full-sparse


From: Marco Caliari
Subject: Re: Dot product full-sparse
Date: Wed, 18 Aug 2010 09:10:32 +0200 (CEST)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

On Wed, 18 Aug 2010, Jaroslav Hajek wrote:

On Thu, Aug 12, 2010 at 10:14 AM, Marco Caliari <address@hidden> wrote:
On Thu, 12 Aug 2010, Jaroslav Hajek wrote:

On Wed, Aug 11, 2010 at 8:20 AM, Marco Caliari <address@hidden>
wrote:

Dear maintainers,

if I run

A = toeplitz ([-2, 1, 1, 1, zeros(1, 856)]);
A = reshape (A, 18490, 40);
SA = sparse (A);
B = rand (size (A));
tic, A .* B;,toc
tic, SA .* B;, toc
tic, SA .* sparse (B);, toc

I get

Elapsed time is 0.00745105 seconds.
Elapsed time is 0.229055 seconds.
Elapsed time is 0.0203849 seconds.

(3.3.51 with Suitesparse 3.5.0, similar results with 3.2.4 with
Suitesparse
3.4.0). Why SA .* sparse (B) is so faster than SA .* B? What is done by
default when a full-sparse dot product is required?

Best regards,

Marco


Apparently this operation is just poorly optimized.

Before I start doing anything here, I'd like to know what the Matlab
behavior is w.r.t. NaNs. Namely, if
A = sparse ([2,3,1,2], [1,1,3,3], [0.1, 0.2, 0.3, 0.4]);
B = ones (3); B(1,1) = NaN;
C = sparse ([1,2,3,1,2], [1,1,1,3,3], [NaN, 0.1, 0.2, 0.3, 0.4]);

what is the output of A.*B, B.*A, A ./ B, A .*C?
Of course, newer version is better.

Here are the results with Matlab 7.6.0 (R2008a)

A.*B

ans =
  (1,1)          NaN
  (2,1)       0.1000
  (3,1)       0.2000
  (1,3)       0.3000
  (2,3)       0.4000

 B.*A

ans =
  (1,1)          NaN
  (2,1)       0.1000
  (3,1)       0.2000
  (1,3)       0.3000
  (2,3)       0.4000

A ./ B

ans =
  (1,1)          NaN
  (2,1)       0.1000
  (3,1)       0.2000
  (1,3)       0.3000
  (2,3)       0.4000

A .* C

ans =
  (1,1)          NaN
  (2,1)       0.0100
  (3,1)       0.0400
  (1,3)       0.0900
  (2,3)       0.1600

Marco


Thanks, Marco. Two more questions, please: What happens for:

Inf * speye (3)
speye(3) / NaN

Inf * speye (3)
ans =
   (1,1)      Inf
   (2,1)      NaN
   (3,1)      NaN
   (1,2)      NaN
   (2,2)      Inf
   (3,2)      NaN
   (1,3)      NaN
   (2,3)      NaN
   (3,3)      Inf
speye(3) / NaN
ans =
   (1,1)      NaN
   (2,1)      NaN
   (3,1)      NaN
   (1,2)      NaN
   (2,2)      NaN
   (3,2)      NaN
   (1,3)      NaN
   (2,3)      NaN
   (3,3)      NaN

Marco

reply via email to

[Prev in Thread] Current Thread [Next in Thread]