Skip to content

Commit

Permalink
fix-chebfun3-feval-matrix-case
Browse files Browse the repository at this point in the history
Addresses issue #2436
  • Loading branch information
bhashemi committed Sep 14, 2023
1 parent ce4abe7 commit db207bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions @chebfun3/feval.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
max(max(max(abs(bsxfun(@minus, yeval, yeval(:, 1)))))) == 0 && ...
max(max(max(abs(bsxfun(@minus, zeval, zeval(1, 1)))))) == 0 )

xeval = xeval(1, :)';
xeval = xeval(1, :).';
yeval = yeval(:, 1);
zeval = zeval(1, 1);
colsVals = f.cols(xeval);
Expand All @@ -277,14 +277,14 @@
max(max(max(abs(bsxfun(@minus, yeval, yeval(1, 1)))))) == 0 && ...
max(max(max(abs(bsxfun(@minus, zeval, zeval(:, 1)))))) == 0 )

xeval = xeval(1, :)';
xeval = xeval(1, :).';
yeval = yeval(1, 1);
zeval = zeval(:, 1);
colsVals = f.cols(xeval);
rowsVals = f.rows(yeval);
tubesVals = f.tubes(zeval);
out = squeeze(chebfun3.txm(chebfun3.txm(chebfun3.txm(f.core, colsVals, 1),...
rowsVals, 2), tubesVals, 3));
rowsVals, 2), tubesVals, 3)).';

% Data generated by meshgrid & xx is a multiple of a single scalar
elseif ( max(max(max(abs(bsxfun(@minus, xeval, xeval(1, 1)))))) == 0 && ...
Expand All @@ -298,7 +298,7 @@
rowsVals = f.rows(yeval);
tubesVals = f.tubes(zeval);
out = squeeze(chebfun3.txm(chebfun3.txm(chebfun3.txm(f.core,...
colsVals, 1), rowsVals, 2), tubesVals, 3));
colsVals, 1), rowsVals, 2), tubesVals, 3)).';

else
% Inputs are not obtained by ndgrid or meshgrid.
Expand Down
18 changes: 14 additions & 4 deletions tests/chebfun3/test_feval.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@
FF = ff(xx,yy,zz);
pass(18) = norm(F - FF) < 100*tol;

% y and z are matrix inputs (meshgrid) and x is just a matrix of just one
% scalar
% y and z are matrix inputs (meshgrid) and x is a matrix of just one scalar
ff = @(x,y,z) sin(pi*(x+y+z));
f = chebfun3(ff);
zz = linspace(-1, 1, 100)';
Expand Down Expand Up @@ -144,8 +143,7 @@
FF = ff(xx,yy,zz);
pass(21) = norm(F - FF) < 100*tol;

% y and z are matrix inputs (ndgrid) and x is just a matrix of just one
% scalar
% y and z are matrix inputs (ndgrid) and x is a matrix of just one scalar
ff = @(x,y,z) sin(pi*(x+y+z));
f = chebfun3(ff);
zz = linspace(-1, 1, 100)';
Expand Down Expand Up @@ -350,4 +348,16 @@
pass(47) = all(size (xx) == size(vals));
pass(48) = norm(ff(xx,yy,zz) - vals) < tol;

%% Test from #2436: Ensure output is not transposed incorrectly.
% Follows Test 20 above.
ff = @(x,y,z) x;
f = chebfun3(ff);
xx = [-0.4 0.4;
-0.4 0.4];
yy = [-0.2 -0.2;
0.2 0.2];
FF = ff(xx,0*xx,yy);
F = f(xx,0*xx,yy);
pass(49) = norm(F - FF) < 100*tol;

end

0 comments on commit db207bc

Please sign in to comment.