Skip to content

Commit

Permalink
fix #533 find does not consider complex number correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Nov 2, 2021
1 parent 05140df commit a2233c6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -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
@@ -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
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

0 comments on commit a2233c6

Please sign in to comment.