Skip to content

Commit

Permalink
fix #739 special case with empty matrix or cell (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Sep 19, 2022
1 parent 6e1b6ac commit 7b67eeb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- [#723](http://github.com/Nelson-numerical-software/nelson/issues/723): MacOS CI was broken.

- [#737](http://github.com/Nelson-numerical-software/nelson/issues/737): profiler failed with 'sind' example..
- [#737](http://github.com/Nelson-numerical-software/nelson/issues/737): profiler failed with 'sind' example.

- [#739](http://github.com/Nelson-numerical-software/nelson/issues/739): special case with empty cell.

## 0.6.8 (2022-08-27)

Expand Down
16 changes: 13 additions & 3 deletions modules/interpreter/src/cpp/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,12 @@ Evaluator::statementType(AbstractSyntaxTreePtr t, bool printIt)
if (context->lookupVariable(t->down->text, b) && b.isFunctionHandle()) {
m = rhsExpression(t->down, 0);
} else {
m = rhsExpression(t->down);
if (b.isCell()) {
m = rhsExpression(t->down, 0);

} else {
m = rhsExpression(t->down);
}
}
if (m.size() == 0) {
b = ArrayOf::emptyConstructor();
Expand Down Expand Up @@ -3743,7 +3748,10 @@ Evaluator::rhsExpression(AbstractSyntaxTreePtr t, int nLhs)
rv = ArrayOfVector();
} else if (rv.size() == 0) {
r = ArrayOf::emptyConstructor();
Error(ERROR_EMPTY_EXPRESSION);

if (nLhs == 1) {
Error(ERROR_EMPTY_EXPRESSION);
}
}
}
if (t->opNum == (OP_DOT)) {
Expand Down Expand Up @@ -3817,7 +3825,9 @@ Evaluator::rhsExpression(AbstractSyntaxTreePtr t, int nLhs)
t = t->right;
}
if (rv.empty()) {
rv.push_back(r);
if (nLhs != 0) {
rv.push_back(r);
}
}
callstack.popID();
return rv;
Expand Down
26 changes: 26 additions & 0 deletions modules/interpreter/tests/bug_github_issue_#739.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%=============================================================================
% Copyright (c) 2017 Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
% <-- Issue URL -->
% https://github.com/Nelson-numerical-software/nelson/issues/739
% <-- Short Description -->
% special case with empty cell.
%=============================================================================
p = {};
p{:}
assert_checkerror('R = eval(''p{:}'');', _('Empty expression!'));
R = evalc('p{:}');
assert_isequal(R, '');
assert_checkerror('k = p{:}', _('Empty expression!'));
%=============================================================================
P = [];
assert_isequal(P(:), zeros(0, 1));
R = P(:);
assert_isequal(R, zeros(0, 1));
%=============================================================================
3 changes: 3 additions & 0 deletions modules/types/src/cpp/ArrayOf_CellType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ ArrayOf::getVectorContentsAsList(ArrayOf& index)
if (index.isEmpty()) {
return ArrayOfVector();
}
if (isEmpty()) {
return ArrayOfVector();
}
if (index.isRowVectorCharacterArray()) {
std::wstring str = index.getContentAsWideString();
if (str != L":") {
Expand Down
32 changes: 12 additions & 20 deletions modules/types/src/cpp/ArrayOf_IntegersType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,28 @@ ArrayOf
ArrayOf::integerRangeConstructor(indexType minval, indexType stepsize, indexType maxval, bool vert)
{
Dimensions Cdim;
if (stepsize == 0) {
Cdim[0] = 1;
Cdim[1] = 0;
NelsonType classC;
#ifdef NLS_INDEX_TYPE_64
return ArrayOf(NLS_INT32, Cdim, nullptr, false);
classC = NLS_INT64;
#else
return ArrayOf(NLS_INT64, Cdim, nullptr, false);
classC = NLS_INT32;
#endif
if (stepsize == 0) {
Cdim[0] = 1;
Cdim[1] = 0;
return ArrayOf(classC, Cdim, nullptr, false);
}
if (minval < maxval) {
#ifndef NLS_INDEX_TYPE_64
if (stepsize < 0) {
Cdim[0] = 1;
Cdim[1] = 0;
return ArrayOf(NLS_INT32, Cdim, nullptr, false);
return ArrayOf(classC, Cdim, nullptr, false);
}
#endif
}
if (minval > maxval) {
Cdim[0] = 1;
Cdim[1] = 0;
#ifdef NLS_INDEX_TYPE_64
return ArrayOf(NLS_INT64, Cdim, nullptr, false);
#else
return ArrayOf(NLS_INT32, Cdim, nullptr, false);
#endif
Cdim[0] = 0;
Cdim[1] = 1;
return ArrayOf(classC, Cdim, nullptr, false);
}
auto dn = static_cast<double>((((maxval - minval) / stepsize) + 1));
#ifdef NLS_INDEX_TYPE_64
Expand Down Expand Up @@ -192,11 +188,7 @@ ArrayOf::integerRangeConstructor(indexType minval, indexType stepsize, indexType
i++;
}
}
#ifdef NLS_INDEX_TYPE_64
return ArrayOf(NLS_INT64, Cdim, rp);
#else
return ArrayOf(NLS_INT32, Cdim, rp);
#endif
return ArrayOf(classC, Cdim, rp);
}
//=============================================================================
template <class T>
Expand Down

0 comments on commit 7b67eeb

Please sign in to comment.