Skip to content

Commit

Permalink
Clean up definition of 'promote'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Sep 27, 2020
1 parent 81fc9be commit 0bcdd18
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions chapters/arrays.tex
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,33 @@ \section{Built-in Array Functions}\label{built-in-array-functions}

Modelica provides a number of built-in functions that are applicable to arrays.

The following \lstinline!promote! function is
utilized below to define other array operators and functions:
\begin{longtable}[]{|l|p{9cm}|}
\caption{Promote function (cannot be used in Modelica).}\\
\hline \endhead
\lstinline!promote(A, $n$)! & Fills dimensions of size 1 from the right to array \lstinline!A! upto
dimension $n$, where $n \geq$ \lstinline!ndims(A)! is required. Let \lstinline!C = promote(A, $n$)!, with $n_{\mathrm{A}}$ = \lstinline!ndims(A)!,
then \lstinline!ndims(C) = $n$!, \lstinline!size(C, $j$) = size(A, $j$)! for $1 \leq j \leq n_{\mathrm{A}}$,
\lstinline!size(C, $j$)! = $1$ for $n_{\mathrm{A}} + 1 \leq j \leq n$, \lstinline!C[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$, 1, $\ldots$, 1]! =
\lstinline!A[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$]!\\ \hline
\end{longtable}
The argument $n$ must be a constant that can be evaluated during translation, as it determines
the number of dimensions of the returned array.
The \lstinline!promote! function listed below is utilized to define other array operators and functions.
\begin{center}
\begin{tabular}{l|l l}
\hline
\tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\
\hline
\hline
\lstinline!promote($A$, $n$)! & Append dimensions of size 1 (not Modelica) & \Cref{modelica:promote} \\
\hline
\end{tabular}
\end{center}

\begin{operatordefinition}[promote]
\begin{synopsis}\begin{lstlisting}
promote($A$, $n$) /* Not available in Modelica. */
\end{lstlisting}\end{synopsis}
\begin{semantics}
Fills dimensions of size 1 from the right to array $A$ upto dimension $n$, where $n \geq$ \lstinline!ndims($A$)! is required.

Let \lstinline!C = promote(A, $n$)!, with $n_{\mathrm{A}}$ = \lstinline!ndims(A)!, then \lstinline!ndims(C) = $n$!, \lstinline!size(C, $j$) = size(A, $j$)! for $1 \leq j \leq n_{\mathrm{A}}$, \lstinline!size(C, $j$)! = $1$ for $n_{\mathrm{A}} + 1 \leq j \leq n$, \lstinline!C[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$, 1, $\ldots$, 1]! = \lstinline!A[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$]!

The argument $n$ must be a constant that can be evaluated during translation, as it determines the number of dimensions of the returned array.
\begin{nonnormative}
An $n$ that is not a constant that can be evaluated during translation for \lstinline!promote!
complicates matrix handling as it
can change matrix-equations in subtle ways (e.g.\ changing inner products to matrix multiplication).
An $n$ that is not a constant that can be evaluated during translation for \lstinline!promote! complicates matrix handling as it can change matrix-equations in subtle ways (e.g.\ changing inner products to matrix multiplication).
\end{nonnormative}
\end{semantics}
\end{operatordefinition}

\begin{nonnormative}
Some examples of using the functions defined in the following
Expand Down

0 comments on commit 0bcdd18

Please sign in to comment.