Skip to content

Commit

Permalink
Generalized z for cell arrays
Browse files Browse the repository at this point in the history
Generalized `z` for cell arrays, following Sanchises' suggestion
  • Loading branch information
lmendo committed May 3, 2019
1 parent 0a56e76 commit 6975ad9
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 20 deletions.
Binary file modified funDef.mat
Binary file not shown.
6 changes: 5 additions & 1 deletion funDef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,11 @@ y 0 inf 2 3 0 0 0 false true false true out = in(1); duplicate element duplicat
Xy 1 4 1 1 1 1 true true true true out{1} = eye(in{:}); identity matrix \matlab+eye+ (matrix with ones on diagonal and zeros elsewhere)
Yy 2 2 2 1 1 1 true true true true out{1} = bsxfun(@hypot, in{1}, in{2}); hypotenuse (element-wise, singleton expansion) \matlab+hypot+, element-wise with singleton expansion
Zy 1 2 1 1 inf 1 true true true true [out{:}] = size(in{:}); size \matlab+size+
z 1 1 1 1 1 1 true true true true out{1} = nnz(in{:}); number of nonzero elements \matlab+nnz+
z 1 1 1 1 1 1 true true true true if ~iscell(in{1}) (i) For non-cell input: number of nonzero elements. (ii) For cell array input: number of nonzero elements of each cell \matlab+nnz+ / \matlab+cellfun(@nnz, ...)+
out{1} = nnz(in{1});
else
out{1} = cellfun(@nnz, in{1});
end
Xz 1 1 1 1 1 1 true true true true if iscell(in{1}), out{1} = regexprep(in{1}, '[\s\0]', ''); elseif ischar(in{1}), out{1} = regexprep(reshape(in{1},1,[]), '[\s\0]', ''); else, out{1} = nonzeros(in{:}); end nonzero elements / remove whitespace \matlab+nonzeros+. If input is a string or char array: removes whitespace, including \matlab+char(0)+; the result is a string. If input is cell array of strings: operates on each string
Yz
Zz
Expand Down
Binary file modified help.mat
Binary file not shown.
Binary file modified spec/MATL_spec.pdf
Binary file not shown.
Binary file modified spec/MATL_spec.synctex.gz
Binary file not shown.
6 changes: 4 additions & 2 deletions spec/MATL_spec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ \section{Acknowledgments}
\item
\user{@Giuseppe} for finding a bug in \matl{u}.
\item
\user{@H.PWiz} for coreecting a typo in the documentation.
\user{@H.PWiz} for correcting a typo in the documentation.
% https://chat.stackexchange.com/transcript/message/42323700#42323700
\item
\user{@pragmatist1} for suggesting the use of a regular expression to check contents of array literals.
Expand All @@ -1531,8 +1531,10 @@ \section{Acknowledgments}
% https://chat.stackexchange.com/transcript/message/41158178#41158178
for suggesting to include \matlab+expm+ (matrix exponential) and to generalize matrix power as a sum over different exponents;
% https://chat.stackexchange.com/transcript/message/41206681#41206681
and for finding a bug in the parser, which incorrectly identified \matl{]} or \matl{\}} within strings as closing symbols for array literals.
for finding a bug in the parser, which incorrectly identified \matl{]} or \matl{\}} within strings as closing symbols for array literals;
% https://chat.stackexchange.com/transcript/message/42555761#42555761
and for suggesting to generalize \matl{z} for cell arrays.
% https://chat.stackexchange.com/transcript/message/49993614#49993614
\item
\user{@Steadybox} for finding a bug in Octave's \matlab+nnz+ function when applied to a range.
% Comments in https://codegolf.stackexchange.com/a/155943/36398
Expand Down
2 changes: 1 addition & 1 deletion spec/funDefTable/funDefTable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
\matl{Xy} & 1--4 (1) & 1 & \matlab+eye+ (matrix with ones on diagonal and zeros elsewhere) \\
\matl{Yy} & 2 & 1 & \matlab+hypot+, element-wise with singleton expansion \\
\matl{Zy} & 1--2 (1) & 1-- (1) & \matlab+size+ \\
\matl{z} & 1 & 1 & \matlab+nnz+ \\
\matl{z} & 1 & 1 & \matlab+nnz+ / \matlab+cellfun(@nnz, ...)+ \\
\matl{Xz} & 1 & 1 & \matlab+nonzeros+. If input is a string or char array: removes whitespace, including \matlab+char(0)+; the result is a string. If input is cell array of strings: operates on each string \\
\matl{X\{} & 1--2 (1 / 2) & 1 & \matlab+num2cell+ \\
\matl{Y\{} & 2-- (3 / 2) & 1 & \matlab+mat2cell+ \\
Expand Down
Binary file modified spec/functionTable/MATL.xlsx
Binary file not shown.
32 changes: 16 additions & 16 deletions spec/functionTable/function_table.eps.old
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%!PS-Adobe-3.0 EPSF-3.0
%%Title: MATL.xlsx
%%Creator: PScript5.dll Version 5.2.2
%%CreationDate: 11/22/2017 0:22:37
%%CreationDate: 12/24/2018 1:49:25
%%For: Luis
%%BoundingBox: 54 77 507 769
%%BoundingBox: 54 77 507 770
%%Pages: 1
%%Orientation: Portrait
%%PageOrder: Ascend
Expand Down Expand Up @@ -4637,7 +4637,7 @@ dup 11 /parenleft put
pop
F0S31YFFFFFFCE Ji
362 1080 M <0B>S
; 1 1 1 1 scol : 442 1037 653 54 rc 3 15352 91 <0001000f000003f10426001001dcb1020243545840150f010b0604020906
; 1 1 1 1 scol : 442 1037 520 54 rc 3 15352 91 <0001000f000003f10426001001dcb1020243545840150f010b0604020906
02060d0a000a0f180f0f02550f2f2b003f3f3f3f11173931301bb70f1201
0f22193906b8ffde405019395a0f96049608990e9a0fc005c006c007cb0f
090f4016391a031309150d1a1035013a0b81018e0b082f1257045907590b
Expand All @@ -4663,7 +4663,7 @@ end
dup 33 /x put
pop
F1S31YFFFFFFCE Ji
442 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C1902211B0C170A0E0A0103151B06>S
442 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C1902211B0C17>S
; : 1362 1037 520 54 rc 4 1088 94 <00010039fe51027c05d3002a007b404d470f0128120f113402120f113407
180b0e3425120b0e3416271600292a2a0c1f2520130d250c110d0c0c1f20
ae1b12112505193a1b2526033a05ae2a273a26ae2a2a5f008f000200692b
Expand Down Expand Up @@ -4692,7 +4692,7 @@ dup 35 /braceright put
pop
F1S31YFFFFFFCE Ji
1362 1080 M <220A230A0401011B170C0F020C060A1B0C1902211B0C17>S
; : 2282 1037 814 54 rc 2 7766 29 <000200b9000001860426000300070038402004050006070902063c04033c
; : 2282 1037 667 54 rc 2 7766 29 <000200b9000001860426000300070038402004050006070902063c04033c
0106040a023c2f003f000220000100a108a198182b10f45d71ed003f3fed
10ed011112393912393931301335331503353315b9cdcdcd0359cdcdfca7
cdcd>/TT61t00 AddT42Char
Expand All @@ -4703,9 +4703,9 @@ end
dup 36 /colon put
pop
F1S31YFFFFFFCE Ji
2282 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C19080A1F1B06180A141B0C04150A240A0A0A0E0A0103151B06>S
; : 3202 1037 838 54 rc F1S31YFFFFFFCE Ji
3202 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C19080A1F1B06180A1B0C1B061B04150A240A0A0A0E0A0103151B06>S
2282 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C19080A1F1B06180A141B0C04150A240A>S
; : 3202 1037 691 54 rc F1S31YFFFFFFCE Ji
3202 1080 M <0B0A0D0A0401011B170C0F020C060A1B0C19080A1F1B06180A1B0C1B061B04150A240A>S
; 0 0 0 1 scol : 362 1097 17 55 rc 2 2610 12 <00010043fe51024005d30010004940182702270a6702670a9702a702a80e
07090810000810001210bd012200000009012200000294b408f3059b0cb8
0296b3126a43182b10f6edfde4ed10ed003f3f103c103c3130015d133e03
Expand All @@ -4719,14 +4719,14 @@ dup 12 /parenright put
pop
F0S31YFFFFFFCE Ji
362 1140 M <0C>S
; 1 1 1 1 scol : 442 1097 477 54 rc F1S31YFFFFFFCE Ji
442 1140 M <0B0A0D0A0502140205020C1A020A1B0C1902211B0C17>S
; 1 1 1 1 scol : 442 1097 610 54 rc F1S31YFFFFFFCE Ji
442 1140 M <0B0A0D0A0502140205020C1A020A1B0C1902211B0C170A0E0A0103151B06>S
; : 1362 1097 477 54 rc F1S31YFFFFFFCE Ji
1362 1140 M <220A230A0502140205020C1A020A1B0C1902211B0C17>S
; : 2282 1097 610 54 rc F1S31YFFFFFFCE Ji
2282 1140 M <0B0A0D0A0502140205020C1A020A1B0C19080A1F1B06180A141B0C04150A24>S
; : 3202 1097 679 54 rc F1S31YFFFFFFCE Ji
3202 1140 M <0B0A0D0A05021402050205020C1A020A1B0C19080A1F1B06180A1B0C1B061B04150A24>S
; : 2282 1097 757 54 rc F1S31YFFFFFFCE Ji
2282 1140 M <0B0A0D0A0502140205020C1A020A1B0C19080A1F1B06180A141B0C04150A240A0A0E0A0103151B06>S
; : 3202 1097 826 54 rc F1S31YFFFFFFCE Ji
3202 1140 M <0B0A0D0A05021402050205020C1A020A1B0C19080A1F1B06180A1B0C1B061B04150A240A0A0E0A0103151B06>S
; 0 0 0 1 scol : 362 1157 19 55 rc 2 2748 13 <0001001c031802f105d3001e00cb4025891301551d561e02451d461e021d
0c0b0518050f0e0b0c0a18051d0316001b861c2b008601b8012640140916
e51509e540152bb00a010a880f0e00153e16b8ffc04027111334163e1b72
Expand Down Expand Up @@ -6103,8 +6103,8 @@ F0S31YFFFFFFCE Ji
1362 3660 M <0107050605071F01>S
; : 2282 3617 172 54 rc F1S31YFFFFFFCE Ji
2282 3660 M <1A1B051A01181B1406>S
; : 3202 3617 270 54 rc F1S31YFFFFFFCE Ji
3202 3660 M <011B170C0A0E0A14140601181B1406>S
; : 3202 3617 498 54 rc F1S31YFFFFFFCE Ji
3202 3660 M <011B170C0A0E0A14140601181B14060A0E0A151B0C0103041A02>S
; : 362 3677 32 55 rc 2 13810 55 <0001002c000004b905ba0007007240232f09300430055009700980099009
0706010502250403020700080917171a047f050105b8012d400a06072001
30007f000200b8012d4011030e500270028002900204021908fdac182b4e
Expand Down
Binary file modified spec/functionTable/function_table.pdf
Binary file not shown.
Binary file modified spec/functionTable/function_table.pdf.old
Binary file not shown.
56 changes: 56 additions & 0 deletions spec/latex_tools/MATL_spec.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
\relax
\providecommand\hyper@newdestlabel[2]{}
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
\global\let\oldcontentsline\contentsline
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
\global\let\oldnewlabel\newlabel
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
\AtEndDocument{\ifx\hyper@anchor\@undefined
\let\contentsline\oldcontentsline
\let\newlabel\oldnewlabel
\fi}
\fi}
\global\let\hyper@last\relax
\gdef\HyperFirstAtBeginDocument#1{#1}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{1}{section.1}}
\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}The name}{1}{subsection.1.1}}
\@writefile{toc}{\contentsline {subsection}{\numberline {1.2}Notation}{2}{subsection.1.2}}
\@writefile{toc}{\contentsline {subsection}{\numberline {1.3}Examples}{2}{subsection.1.3}}
\newlabel{parte: examples of programs}{{1.3}{2}{Examples}{subsection.1.3}{}}
\@writefile{toc}{\contentsline {section}{\numberline {2}The stack. Data types}{2}{section.2}}
\newlabel{parte: stack. Data types}{{2}{2}{The stack. Data types}{section.2}{}}
\@writefile{toc}{\contentsline {section}{\numberline {3}Statements and separators}{3}{section.3}}
\@writefile{toc}{\contentsline {section}{\numberline {4}Literals}{4}{section.4}}
\newlabel{section: literals}{{4}{4}{Literals}{section.4}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.1}Numbers}{4}{subsection.4.1}}
\newlabel{parte: numbers}{{4.1}{4}{Numbers}{subsection.4.1}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.2}Numerical arrays}{5}{subsection.4.2}}
\newlabel{parte: numerical arrays}{{4.2}{5}{Numerical arrays}{subsection.4.2}{}}
\@writefile{lot}{\contentsline {table}{\numberline {1}{\ignorespaces Letters used as numbers in arrays\relax }}{6}{table.caption.1}}
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
\newlabel{tab: meaning of letters in arrays}{{1}{6}{Letters used as numbers in arrays\relax }{table.caption.1}{}}
\newlabel{parte: array checking}{{4.2}{6}{Numerical arrays}{table.caption.2}{}}
\newlabel{RF1}{7}
\@writefile{lot}{\contentsline {table}{\numberline {2}{\ignorespaces Characters that have special meaning within number literals or array literals\relax }}{7}{table.caption.2}}
\newlabel{tab: characters in arrays}{{2}{7}{Characters that have special meaning within number literals or array literals\relax }{table.caption.2}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.3}Logical arrays}{8}{subsection.4.3}}
\newlabel{parte: logical arrays}{{4.3}{8}{Logical arrays}{subsection.4.3}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.4}Character arrays}{9}{subsection.4.4}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.5}Cell arrays}{9}{subsection.4.5}}
\@writefile{toc}{\contentsline {section}{\numberline {5}Functions}{9}{section.5}}
\newlabel{parte: functions}{{5}{9}{Functions}{section.5}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {5.1}Normal functions}{10}{subsection.5.1}}
\@writefile{toc}{\contentsline {subsection}{\numberline {5.2}Meta-functions}{11}{subsection.5.2}}
\newlabel{parte: meta-functions}{{5.2}{11}{Meta-functions}{subsection.5.2}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {5.3}Stack rearranging functions}{14}{subsection.5.3}}
\newlabel{parte: stack rearranging functions}{{5.3}{14}{Stack rearranging functions}{subsection.5.3}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {5.4}Clipboard functions}{15}{subsection.5.4}}
\newlabel{parte: clipboard functions}{{5.4}{15}{Clipboard functions}{subsection.5.4}{}}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {5.4.1}Standard clipboards}{15}{subsubsection.5.4.1}}
\newlabel{parte: standard clipboards}{{5.4.1}{15}{Standard clipboards}{subsubsection.5.4.1}{}}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {5.4.2}Automatic clipboards}{17}{subsubsection.5.4.2}}
\new
Empty file added spec/latex_tools/MATL_spec.out
Empty file.
Binary file added spec/latex_tools/MATL_spec.pdf
Binary file not shown.

0 comments on commit 6975ad9

Please sign in to comment.