From a2233c64076da21e5095845c8b5f36061e2aea86 Mon Sep 17 00:00:00 2001 From: Allan CORNET Date: Sun, 31 Oct 2021 19:00:40 +0100 Subject: [PATCH] fix #533 find does not consider complex number correctly --- CHANGELOG.md | 4 ++ .../tests/bug_github_issue_#533.m | 38 +++++++++++++++++++ modules/types/src/cpp/ArrayOf_PromoteType.cpp | 5 ++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 modules/elementary_functions/tests/bug_github_issue_#533.m diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3773d379..fdab702468 100644 --- a/CHANGELOG.md +++ b/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: diff --git a/modules/elementary_functions/tests/bug_github_issue_#533.m b/modules/elementary_functions/tests/bug_github_issue_#533.m new file mode 100644 index 0000000000..224796f819 --- /dev/null +++ b/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 . +% 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) +%============================================================================= diff --git a/modules/types/src/cpp/ArrayOf_PromoteType.cpp b/modules/types/src/cpp/ArrayOf_PromoteType.cpp index c86e477450..c6f1a9f255 100644 --- a/modules/types/src/cpp/ArrayOf_PromoteType.cpp +++ b/modules/types/src/cpp/ArrayOf_PromoteType.cpp @@ -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; }