# bug #60361: division on double data with single precision diagonal matrix very slow

 Submitter: A.R. Burgers Submitted: Fri 09 Apr 2021 09:41:35 AM UTC Category: Performance Severity: 3 - Normal Priority: 5 - Normal Item Group: Performance Status: None Assigned to: None Originator Name: Open/Closed:  * Open Release:  * dev Operating System:  * GNU/Linux Fixed Release: None Planned Release: None
* Mandatory Fields

Add a New Comment Rich Markup

## Discussion

Fri 09 Apr 2021 09:41:35 AM UTC, original submission:

The script below produces these timings:

double: 0.000715971
single: 1.07861
single (no diag): 0.000701904

division of double data by single diagonal matrix is very slow.
Came across this when using pchip function on double precision x and single precision y. Applying this diff to pchip, avoiding the single precision diagonal matrix, makes pchip a lot faster for the mixed precision case.

<   h = diag (h);
---
>   hr = 1.0 ./ h;
120,122c120,122
<   delta = diff (y, 1, 2) / h;
<   del1 = (d1 - delta) / h;
<   del2 = (d2 - delta) / h;
---
>   delta = diff (y, 1, 2) .* hr;
>   del1 = (d1 - delta) .* hr;
>   del2 = (d2 - delta) .* hr;
125c125
<   c3 /= h;
---
>   c3 .*= hr;

a=rand(1,1500);
a_single = single(a);
b_single=diag(a_single);
b_double=diag(a);
nrep = 100;

tic;
for i = 1 : nrep
c = a / b_double;
end
fprintf('double: %g\n', toc);

tic;
for i = 1 : nrep
c = a / b_single;
end
fprintf('single: %g\n', toc);

tic;
for i = 1 : nrep
c = a ./ a_single;
end
fprintf('single (no diag): %g\n', toc);

A.R. Burgers <arb>

## Attached Files

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

No files currently attached

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by arb (Submitted the item)
•