Skip to content

Commit 91ce7a8

Browse files
committed
Corrected Octave bug in nnz with range input
1 parent 75dcc40 commit 91ce7a8

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

compatibility/nnz_comp.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function y = nnz(x)
2+
% Octave treats ranges specially to save memory: https://www.gnu.org/software/octave/doc/v4.2.0/Ranges.html
3+
% When applying `nnz` to a range an error occurs. It seems to be solved by linearizing the input (that is,
4+
% applying index `(:)`). That probably turns the range into an actual column vector
5+
y = builtin('nnz', x(:));
6+
end

matl_compile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'diff' 'mod' 'repelem' 'dec2bin' 'dec2base' ...
363363
'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit' 'max' 'min' 'strncmp' 'round'...
364364
'datestr' 'regexp' 'regexprep' 'imshow' 'mat2str' 'blkdiag' 'strcat' 'str2num' 'str2double' 'cconv' ...
365-
'gcd' 'lcm' 'fftn' 'mode'};
365+
'gcd' 'lcm' 'fftn' 'mode' 'nnz'};
366366
verNumTh = [4 0 0]; % first version in which a modified function is not needed:
367367
if (verNum(1)<verNumTh(1)) || ((verNum(1)==verNumTh(1)) && (verNum(2)<verNumTh(2))) || ((verNum(1)==verNumTh(1)) && (verNum(2)==verNumTh(2)) && (verNum(3)<verNumTh(3)))
368368
fnames = [fnames {'colon'}];

spec/MATL_spec.aux

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,5 @@
221221
{1}{127.09738pt}\LT@entry
222222
{1}{23.69952pt}\LT@entry
223223
{1}{125.09738pt}}
224-
\@writefile{lot}{\contentsline {table}{\numberline {7}{\ignorespaces Output of predefined literal functions\relax }}{70}{table.caption.8}}
225-
\newlabel{tab: preLit}{{7}{70}{Output of predefined literal functions\relax \relax }{table.caption.8}{}}
224+
\@writefile{lot}{\contentsline {table}{\numberline {7}{\ignorespaces Output of predefined literal functions\relax }}{71}{table.caption.8}}
225+
\newlabel{tab: preLit}{{7}{71}{Output of predefined literal functions\relax \relax }{table.caption.8}{}}

spec/MATL_spec.pdf

2.2 KB
Binary file not shown.

spec/MATL_spec.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,8 @@ \subsection{MATL functions}
13991399
\item
14001400
\matlab+char+ implicitly rounds down in MATLAB, and rounds to closest in Octave. This difference has been addressed by enforcing MATLAB's behaviour.
14011401
Octave's \matlab+mode+ doesn't handle char input. This has been fixed.
1402+
\item
1403+
Octave treats ranges specially to save memory\footnote{\url{https://www.gnu.org/software/octave/doc/v4.2.0/Ranges.html}}. When applying function \matlab+nnz+ to a range an error occurs. This has been fixed.
14021404
\end{itemize}
14031405

14041406

@@ -1520,6 +1522,9 @@ \section{Acknowledgments}
15201522
and for finding a bug in the parser, which incorrectly identified \matl{]} or \matl{\}} within strings as closing symbols for array literals.
15211523
% https://chat.stackexchange.com/transcript/message/42555761#42555761
15221524
\item
1525+
\user{@Steadybox} for finding a bug in Octave's \matlab+nnz+ function when applied to a range.
1526+
% Comments in https://codegolf.stackexchange.com/a/155943/36398
1527+
\item
15231528
\user{@Suever} for his help in finding several differences between Octave and MATLAB,
15241529
% regarding the $0$ character, as well as the \matlab+max+ and \matlab+min+ functions;
15251530
% concatenation of chars and logical doesn't work in Matlab

0 commit comments

Comments
 (0)