Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #533 find does not consider complex number correctly #537

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.11 (UNRELEASED)

- [#533](http://github.com/Nelson-numerical-software/nelson/issues/533): `find` with one lhs did not return expected result with complex.

# 0.5.10 (2021-10-30)

- Polynomial functions:
Expand Down
38 changes: 38 additions & 0 deletions modules/elementary_functions/tests/bug_github_issue_#533.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%=============================================================================
% Copyright (c) 2017 Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU Lesser General Public
% License as published by the Free Software Foundation; either
% version 2.1 of the License, or (at your option) any later version.
%
% Alternatively, you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation; either version 2 of
% the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this program. If not, see <http://www.gnu.org/licenses/>.
% LICENCE_BLOCK_END
%=============================================================================
% <-- Issue URL -->
% https://github.com/Nelson-numerical-software/nelson/issues/533
% <-- Short Description -->
% find does not consider complex number correctly
%=============================================================================
R = find([1 i]);
REF = [1 2];
assert_isequal(R, REF)
%=============================================================================
R = find(single([1 i]));
REF = [1 2];
assert_isequal(R, REF)
%=============================================================================
5 changes: 3 additions & 2 deletions modules/types/src/cpp/ArrayOf_PromoteType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ promoteComplexAsLogical(Class dstClass, const TIN* ptr, indexType count)
#if defined(_NLS_WITH_OPENMP)
#pragma omp parallel for
#endif
for (ompIndexType i = 0; i < (ompIndexType)count; i++) {
dstPtr[i] = (ptr[i * 2] == 0) ? 0 : 1;
for (ompIndexType i = 0; i < count; ++i) {
dstPtr[i] = (ptr[(i*2)] || ptr[(i*2) + 1]) ? 1 : 0;

}
return dstPtr;
}
Expand Down