Skip to content

Commit

Permalink
Minor corrections with empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Jan 18, 2022
1 parent 2638494 commit e48cc9e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chapters/arrays.tex
Expand Up @@ -1415,14 +1415,21 @@ \section{Empty Arrays}\label{empty-arrays}
Real A[0, 3], B[5, 0], C[0, 0]; // empty matrices
\end{lstlisting}

Empty matrices can be constructed with the fill function. For example:
Empty matrices can be constructed using the \lstinline!fill! function. For example:
\begin{lstlisting}[language=modelica]
Real A[:,:] = fill(0.0, 0, 1); // a Real 0 x 1 matrix
Boolean B[:, :, :] = fill(false, 0, 1, 0); // a Boolean 0 x 1 x 0 matrix
\end{lstlisting}

It is not possible to access an element of an empty matrix, e.g.\ \lstinline!v[j, k]! cannot be evaluated if \lstinline!v = []! because the assertion fails
that the index must be bigger than one.
\begin{example}
Whereas scalar indexing into an empty dimension of an array is an error, not all applications of indices to empty arrays are invalid:
\begin{lstlisting}
Real[1, 0] a = fill(0.0, 1, 0); // a Real 1 x 0 matrix
Real[0] a1a = a[1]; // empty vector
Real[0] a1b = a[1, :]; // same as above
Real[0] a1c = a[1, 1 : end]; // same as above, as 1 : end is empty
\end{lstlisting}
\end{example}

Size-requirements of operations, such as \lstinline!+!, \lstinline!-!, must also be fulfilled if a dimension is zero. For example:
\begin{lstlisting}[language=modelica]
Expand All @@ -1434,9 +1441,9 @@ \section{Empty Arrays}\label{empty-arrays}

Multiplication of two empty matrices results in a zero matrix of corresponding numeric type if the result matrix has no zero dimension sizes, i.e.,
\begin{lstlisting}[language=modelica]
Real[0, m] * Real[m, n] = Real[0, n] (empty matrix)
Real[m, n] * Real[n, 0] = Real[m, 0] (empty matrix)
Real[m, 0] * Real[0, n] = fill(0.0, m, n) (non-empty matrix, with zero elements).
Real[0, m] * Real[m, n] = Real[0, n] // empty matrix
Real[m, n] * Real[n, 0] = Real[m, 0] // empty matrix
Real[m, 0] * Real[0, n] = fill(0.0, m, n) // non-empty matrix of zeros
\end{lstlisting}

\begin{example}
Expand Down

0 comments on commit e48cc9e

Please sign in to comment.