Pagemldivide returns incorrect results for complex gpuArrays

A1=randn(20,10,2)+1j*randn(20,10,2);
B1=randn(20,10,2)+1j*randn(20,10,2);
A = gpuArray(A1);
B = gpuArray(B1);
X = pagemldivide(A,B);
x=mldivide(A(:,:,1),B(:,:,1));
X(:,:,1)-x
Am I missing something obvious here, or is this a bug? I first assumed this is related to pagemldivide and pagefun(@mldivide,...) for gpuArray inputs return incorrect results for rectangular pages when singleton dimension expansion is required (4237666) but there is no singleton dimension here.

6 Comments

Please show the outputs of:
D = gather(X(:,:,1) - x);
mxd = max(abs(D(:)))
relerr = norm(D,'fro') ./ norm(x,'fro')
D = gather(X(:,:,1) - x);
mxd = max(abs(D(:)))
relerr = norm(D,'fro') ./ norm(x,'fro')
mxd =
1.2228
relerr =
1.8817
Second example, we should get identity matrix:
>> X = pagemldivide(A,A);
gather(X(1:5,1:5))
ans =
0.4196 + 0.6081i -0.3541 + 0.5028i -0.0160 + 0.5755i -0.0796 + 0.3308i -0.1578 + 0.7219i
0.2302 - 0.2807i -0.2500 + 0.3753i 0.3586 + 0.5197i 0.3694 - 0.0015i 0.1390 + 0.1273i
-0.3643 - 0.2273i -0.0669 - 0.0129i 0.0627 - 0.3806i 0.1366 - 0.2914i -0.2097 - 0.3401i
0.2924 + 0.6179i 0.2658 - 0.2841i -0.6560 - 0.3509i -0.4483 + 0.5855i -0.1390 - 0.0670i
0.2981 + 0.7508i -0.0881 + 0.3008i -0.3810 - 0.2276i -0.3943 + 0.1851i 0.0732 + 0.2760i
A = randn(20,10,2)+1j*randn(20,10,2);
pagemldivide(A,A)
ans =
ans(:,:,1) = Columns 1 through 9 1.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 1.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 1.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i Column 10 -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 1.0000 - 0.0000i ans(:,:,2) = Columns 1 through 9 1.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 1.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 1.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i Column 10 -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 - 0.0000i 1.0000 + 0.0000i
Does this work for A being a gpuArray ?
@Torsten: unfortunately Answers does not appear to support gpuArrays.
Torsten
Torsten on 1 Jul 2026 at 0:17
Edited: Torsten on 1 Jul 2026 at 0:22
I thought the code was intended as an example contradicting OP's second example. But without A being a gpuArray, I don't understand why you posted it. Or does it work with your home licence ?

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 1 Jul 2026 at 2:00
Edited: Matt J on 1 Jul 2026 at 17:28
Looks like a bug to me. I would report it.
Test Data
Acpu=randn(20,10,2)+1j*randn(20,10,2);
Bcpu=randn(20,10,2)+1j*randn(20,10,2);
Agpu = gpuArray(Acpu);
Bgpu = gpuArray(Bcpu);
Compute
Baseline=pagemldivideLoop(Acpu,Bcpu); %ground truth
X = pagemldivideLoop(Agpu,Bgpu);
Y = pagemldivide(Acpu,Bcpu);
Z = pagemldivide(Agpu,Bgpu);
Compare
Error=@(P,Q) norm( P(:)-Q(:) ,inf)/norm(Q(:),inf)*100; %Percent error function
Error(X,Baseline) %Correct
ans =
6.9896e-14
Error(Y,Baseline) %Correct
ans = 0
Error(Z,Baseline) %Wrong
ans =
160.0906
function C=pagemldivideLoop(A,B)
n=size(A,3);
C=cell(1,1,n);
for i=1:n
C{i}=A(:,:,i)\B(:,:,i);
end
C=cat(3,C{:});
end

5 Comments

From Tech Support:
"I have verified the same results on my end on both MATLAB R2024b and MATLAB R2025b. I will inform the developers about this issue and you will be notified when a fix is available."
I always find it a bit off-putting when the Tech Support seems to go out their way to not use the word "bug."
Is there anything about this example that is corner- or edge-ish? Or is this just a case of very poor quality control in testing the functionality of exactly what the function is supposed to do? Whatever the "issue" is, I wonder how long it's been present.
Has pagemrdivide been tested to see if it has the same "issue"?
Matti
Matti on 4 Jul 2026 at 9:40
Edited: Matti on 4 Jul 2026 at 9:58
It is inexcusable that there is no public bug report about this behavior. It is one thing to fail with error message, but quite another to give wrong results silently.
And yes, pagemrdivide has the exactly same issue, easily verified by replacing pagemldivide with pagemrdivide in the above example.
Personally, I think it's inexcusable that such a bug wasn't found through unit testing, though I'd be willing to reduce the temperature of that statement if someone could explain why this example is some sort of special case.
IF a bug report is going to be published, there can be a delay of a few days between reporting and publication that gives Mathworks time figure out what the probem really is (e.g., is this bug limited only to two complex inputs?) to get the wording correct, figure out affected releases, etc. At least that's been my experience. Might be a bit longer in this case given that it's a holiday weekend in the USA.
WHETHER a bug report is going to be published depends on if this bug "may be of interest to customers, based on general use of our products." My own experience is that I've reported bugs that I thought met that criterion, but weren't published. Of course, I might have a lower threshold than Mathworks; the publication criterion can't be any more subjective than it is.
Seems like this "issue" is quite serious and worthy of publication, I guess we'll know soon.
Does your support case also cover pagemrdivide?
Also, "I have verified the same results on my end on both MATLAB R2024b and MATLAB R2025b."
Does that statement imply that the "issue" does not exist in 2024a and any previous releases for which pagemldivide is supposed to support complex gpuArray(s)? Or had they just not investigated further back than 2024b at the time of that response?
Does your support case also cover pagemrdivide?
I have updated the case with the additional info about pagemrdivide. I surmise though that they both have the same origin in the code. It is unlikely there would be independent implementations of mrdivide vs. mldivide.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2026a

Asked:

on 30 Jun 2026 at 7:50

Commented:

on 4 Jul 2026 at 15:23

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!