Skip to content

Commit

Permalink
Bugfix (ensure return datatype matches arguments)
Browse files Browse the repository at this point in the history
This commit fixes a bug where calling this function with single-
precision arguments would produce double-precision results.

This bug is unlikely to have caused any issues, however, because it is
essentially unreachable. This code is only executed when use_mex=true
but the corresponding MEX file is unavailable, but it is difficult to
enter that state because you can't set use_mex=true unless the MEX
files are present.
  • Loading branch information
kqshan committed Jan 10, 2020
1 parent 7dfeeec commit ab971f1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion @MoDT/bandPosSolve.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[p,N] = size(A_bands);

% MATLAB doesn't support single-precision sparse yet (as of R2017a)
was_single = isa(A_bands,'single') || isa(b,'single');
A_bands = double(A_bands); b = double(b);

% Call sparse() to construct A
Expand All @@ -32,7 +33,7 @@
x = A \ b;

% Cast to single if A or b was single
if isa(A_bands,'single') || isa(b,'single')
if was_single
x = single(x);
end

Expand Down

0 comments on commit ab971f1

Please sign in to comment.