From eb9bb6ca67dac333f2ff90346012c43fa4484662 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Mottelet?= Date: Thu, 9 Apr 2020 15:02:33 +0200 Subject: [PATCH] * Bug 16403 fixed: 1D extraction of matrix with implicit index had wrong dimensions Change-Id: Ib0025ce308de45734fd6c39961ea46ff92ab6f81 --- scilab/CHANGES.md | 7 ++-- scilab/modules/ast/src/cpp/types/arrayof.cpp | 5 ++- .../modules/ast/tests/nonreg_tests/bug_16403.tst | 34 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 scilab/modules/ast/tests/nonreg_tests/bug_16403.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index e1772d4..1f58c95 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -269,6 +269,7 @@ Bug Fixes * [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. * [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE. * [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression) +* [#16403](https://bugzilla.scilab.org/16403): 1D extraction of matrix with implicit index had wrong dimensions. ### Bugs fixed in 6.1.0: * [#2694](https://bugzilla.scilab.org/2694): `bitget` did not accept positive integers of types int8, int16 or int32. @@ -281,7 +282,7 @@ Bug Fixes * [#7724](https://bugzilla.scilab.org/7724): When a figure is created in .auto_resize="on" mode, its .axes_size sets its .figure_size accordingly, not the reverse. But this was not documented. * [#7732](https://bugzilla.scilab.org/7732): The `datafit` help page needed to be fixed and overhauled. * [#7765](https://bugzilla.scilab.org/7765): `champ1` is useless. `champ().colored` is available for a long time. -* [#7777](https://bugzilla.scilab.org/7777): `ged` did not allow moving several objects. +* [#7777](https://bugzilla.scilab.org/7777): `ged` did not allow moving several objects. * [#7948](https://bugzilla.scilab.org/7948): `gsort` could not perform multilevel sorting, and could not sort complex numbers completely. * [#7967](https://bugzilla.scilab.org/7967): The tricky size `[ny,nx]` of `meshgrid(x,y)` results and usages with graphics was not enough documented. * [#8301](https://bugzilla.scilab.org/8301): `definedfields` wrongly considered as defined void elements in lists, tlists and mlists. @@ -305,7 +306,7 @@ Bug Fixes * [#11852](https://bugzilla.scilab.org/11852): File browser didn't update after file creation or removal. * [#11363](https://bugzilla.scilab.org/11363): `show_window()` did not raise the current graphics window. * [#12013](https://bugzilla.scilab.org/12013): `bitset` did not work for numbers greater than 2^32-1. -* [#12302](https://bugzilla.scilab.org/12302): Blocks of legends could not be moved interactively. +* [#12302](https://bugzilla.scilab.org/12302): Blocks of legends could not be moved interactively. * [#12428](https://bugzilla.scilab.org/12428): A part of an error message from `toprint` was not translated. * [#12520](https://bugzilla.scilab.org/12520): Variable browser did not display the size of the variables. * [#12534](https://bugzilla.scilab.org/12534): Variable browser did not display the size of the variables. @@ -321,7 +322,7 @@ Bug Fixes * [#14501](https://bugzilla.scilab.org/14501): `strsubst` crashed on consecutive occurrences. * [#14557](https://bugzilla.scilab.org/14557): `csim` failed when the system has no state. * [#14498](https://bugzilla.scilab.org/14498): `size([],3)` returned 1 instead of 0. -* [#14487](https://bugzilla.scilab.org/14487): matrix indexing was not coherent with MATLAB. +* [#14487](https://bugzilla.scilab.org/14487): matrix indexing was not coherent with MATLAB. * [#14502](https://bugzilla.scilab.org/14502): `Demo > GUI > Uicontrols 2` could not be exported to a file. * [#14585](https://bugzilla.scilab.org/14585): `closeEditvar()` had to be replaced with `editvar("close")`. * [#14604](https://bugzilla.scilab.org/14604): `emptystr` is 40x slower with 6.0.0 wrt 5.5.2 diff --git a/scilab/modules/ast/src/cpp/types/arrayof.cpp b/scilab/modules/ast/src/cpp/types/arrayof.cpp index 71989ee..d9350b7 100644 --- a/scilab/modules/ast/src/cpp/types/arrayof.cpp +++ b/scilab/modules/ast/src/cpp/types/arrayof.cpp @@ -1123,9 +1123,8 @@ GenericType* ArrayOf::extract(typed_list* _pArgs) return NULL; } - bool isRowVector = m_iRows == 1; - isRowVector = isRowVector && !isForceColVector; - int dims[2] = {isRowVector ? 1 : size, isRowVector ? size : 1}; + bool isColVector = isForceColVector || (isVector() && m_iCols == 1); + int dims[2] = {isColVector ? size : 1, isColVector ? 1 : size}; pOut = createEmpty(2, dims, isComplex()); double idx = start; diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16403.tst b/scilab/modules/ast/tests/nonreg_tests/bug_16403.tst new file mode 100644 index 0000000..bf3affb --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_16403.tst @@ -0,0 +1,34 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2020 - Stéphane MOTTELET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> +// +// <-- Non-regression test for bug 16144 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16403 +// +// <-- Short Description --> +// 1D extraction of matrix with implicit index has wrong dimensions + +a = [1 3 5 + 2 4 6]; +k = 1:3; +assert_checkequal(a(1:3),[1, 2, 3]); +assert_checkequal(a(k),[1, 2, 3]); +assert_checkequal(a(k'),[1; 2; 3]); + +// extracted vectors keep the shape of source +x=[1, 2, 3, 4, 5, 6]; +assert_checkequal(x(1:3),[1, 2, 3]); +assert_checkequal(x(k),[1, 2, 3]); +assert_checkequal(x(k'),[1, 2, 3]); +x=[1; 2; 3; 4; 5; 6]; +assert_checkequal(x(1:3),[1; 2; 3]); +assert_checkequal(x(k),[1; 2; 3]); +assert_checkequal(x(k'),[1; 2; 3]); -- 1.7.9.5