Skip to content

Commit

Permalink
fix #468 A(':') = [] was not managed. (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Jul 2, 2021
1 parent 55171a9 commit 0e6c04f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@

- [#449](http://github.com/Nelson-numerical-software/nelson/issues/449): `conv2`: 2-D convolution and `conv`: Convolution and polynomial multiplication.

## Bug Fixes:

- [#468](http://github.com/Nelson-numerical-software/nelson/issues/468): A(':') = [] was not managed.

# 0.5.6 (2021-06-27)

BREAKING CHANGE:
Expand Down
3 changes: 2 additions & 1 deletion modules/interpreter/src/cpp/Evaluator.cpp
Expand Up @@ -768,7 +768,8 @@ Evaluator::expressionList(AbstractSyntaxTreePtr t, ArrayOf subRoot)
for (size_t i = 0; i < n.size(); i++) {
m.push_back(n[i]);
}
} else if (t->type == non_terminal && t->opNum == (OP_ALL)) {
} else if ((t->type == non_terminal && t->opNum == OP_ALL)
|| (t->type == const_character_array_node && t->text == ":")) {
Dimensions dim = subRoot.getDimensions();
if (root->right == nullptr) {
// Singleton reference, with ':' - return 1:length as column vector...
Expand Down
43 changes: 43 additions & 0 deletions modules/interpreter/tests/bug_github_issue_#468.m
@@ -0,0 +1,43 @@
%=============================================================================
% 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/468
% <-- Short Description -->
% A(':') = [] was not managed.
%=============================================================================
A = 1;
A(':') = [];
assert_isequal(A, []);
%=============================================================================
A = 1;
A(:) = [];
assert_isequal(A, []);
%=============================================================================
B = eye(3);
B(':') = 3;
REF = [3 3 3; 3 3 3; 3 3 3];
assert_isequal(B, REF);
%=============================================================================
6 changes: 3 additions & 3 deletions modules/interpreter/tests/test_colon_as_string.m
Expand Up @@ -72,10 +72,10 @@
assert_isequal(A, [ 1 3; 4 6; 7 9]);
%=============================================================================
A = { 1 2 3; 4 5 6; 7 8 9};
assert_checkerror('A{'':''} = [];',_('Cannot convert string data types to indices.'));
assert_checkerror('A{'':''} = [];',_('Not enough right hand side values to satisy left hand side expression.'));
%=============================================================================
A = [ 1 2 3; 4 5 6; 7 8 9];
A(':',1) = [10; 11; 12]
A(':',1) = [10; 11; 12];
REF =[ 10 2 3; 11 5 6; 12 8 9];
assert_isequal(A, REF);
%=============================================================================
Expand All @@ -87,7 +87,7 @@
assert_isequal(A, REF);
%=============================================================================
A = { 1 2 3; 4 5 6; 7 8 9};
A(':',1) = {10; 11; 12}
A(':',1) = {10; 11; 12};
REF = { 10 2 3; 11 5 6; 12 8 9};
assert_isequal(A, REF);
%=============================================================================
11 changes: 5 additions & 6 deletions modules/text_editor/src/cpp/QtTextEditor.cpp
Expand Up @@ -695,13 +695,12 @@ QtTextEditor::open()
QString textFilesText = TR("Text files");
QString markdowFilesText = TR("Markdown files");
QString allFilesText = TR("All files");

QString filesSupported = QString("Nelson (*.m);;") + textFilesText + QString(" (*.txt);;") +
markdowFilesText + QString(" (*.md);;") + allFilesText + QString(" (*.*)");

QStringList fileNames
= QFileDialog::getOpenFileNames(this, TR("Open file ..."), QDir::currentPath(),
filesSupported);
QString filesSupported = QString("Nelson (*.m);;") + textFilesText + QString(" (*.txt);;")
+ markdowFilesText + QString(" (*.md);;") + allFilesText + QString(" (*.*)");

QStringList fileNames = QFileDialog::getOpenFileNames(
this, TR("Open file ..."), QDir::currentPath(), filesSupported);
for (int k = 0; k < fileNames.size(); k++) {
loadFile(fileNames[k]);
}
Expand Down
11 changes: 7 additions & 4 deletions modules/types/src/cpp/ArrayOf_Delete.cpp
Expand Up @@ -82,9 +82,13 @@ ArrayOf::deleteVectorSubset(ArrayOf& arg)
deletionMap = nullptr;
Dimensions newDim;
if (dp->isScalar()) {
newDim.reset();
newDim[0] = 1;
newDim[1] = newSize;
if (arg.getElementCount() == 1) {
newDim[0] = 0;
newDim[1] = 0;
} else {
newDim[0] = 1;
newDim[1] = newSize;
}
} else if (dp->isVector()) {
newDim = dp->dimensions;
if (dp->dimensions[0] != 1) {
Expand All @@ -93,7 +97,6 @@ ArrayOf::deleteVectorSubset(ArrayOf& arg)
newDim[1] = newSize;
}
} else {
newDim.reset();
if (newSize == 0) {
newDim[0] = 0;
newDim[1] = 0;
Expand Down

0 comments on commit 0e6c04f

Please sign in to comment.