Skip to content

Commit

Permalink
Sentence-based line breaking in array concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 26, 2022
1 parent 82aec37 commit b8fd96f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions chapters/arrays.tex
Expand Up @@ -803,25 +803,17 @@ \subsubsection{Constructor with Several Iterators}\label{array-constructor-with-

\subsection{Concatenation}\label{array-concatenation}\label{concatenation}

The function \lstinline!cat($k$, A, B, C, $\ldots$)! concatenates arrays
\lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots along
dimension $k$ according to the following rules:
The function \lstinline!cat($k$, A, B, C, $\ldots$)! concatenates arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots along dimension $k$ according to the following rules:
\begin{itemize}
\item
Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have the same number of dimensions, i.e.,
\lstinline!ndims(A)! = \lstinline!ndims(B)! = \ldots
Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have the same number of dimensions, i.e., \lstinline!ndims(A)! = \lstinline!ndims(B)! = \ldots
\item
Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must be type compatible expressions (\cref{type-compatible-expressions})
giving the type of the elements of the result. The maximally expanded
types should be equivalent. \lstinline!Real! and \lstinline!Integer! subtypes can be mixed
resulting in a \lstinline!Real! result array where the \lstinline!Integer! numbers have been
transformed to \lstinline!Real! numbers.
Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must be type compatible expressions (\cref{type-compatible-expressions}) giving the type of the elements of the result. The maximally expanded types should be equivalent.
\lstinline!Real! and \lstinline!Integer! subtypes can be mixed resulting in a \lstinline!Real! result array where the \lstinline!Integer! numbers have been transformed to \lstinline!Real! numbers.
\item
$k$ has to characterize an existing dimension, i.e., $1 \leq k \leq \text{\lstinline!ndims(A)!} = \text{\lstinline!ndims(B)!} = \text{\lstinline!ndims(C)!}$; $k$ shall be a parameter expression of \lstinline!Integer! type.
\item
Size matching: Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have identical array sizes
with the exception of the size of dimension $k$, i.e., \lstinline!size(A, $j$)! =
\lstinline!size(B, $j$)!, for $1 \leq j \leq \text{\lstinline!ndims(A)!}$ and $j \neq k$.
Size matching: Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have identical array sizes with the exception of the size of dimension $k$, i.e., \lstinline!size(A, $j$)! = \lstinline!size(B, $j$)!, for $1 \leq j \leq \text{\lstinline!ndims(A)!}$ and $j \neq k$.
\end{itemize}

\begin{example}
Expand Down Expand Up @@ -855,22 +847,17 @@ \subsubsection{Concatenation along First and Second Dimensions}\label{array-conc
\begin{itemize}
\item
\emph{Concatenation along first dimension}:\\
\lstinline![A; B; C; $\ldots$] = cat(1, promote(A, n), promote(B, n), promote(C, n), $\ldots$)!
where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized
dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is
carried out, in order that the operands have the same number of dimensions which will be at least two.
\lstinline![A; B; C; $\ldots$] = cat(1, promote(A, n), promote(B, n), promote(C, n), $\ldots$)! where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!.
If necessary, 1-sized dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is carried out, in order that the operands have the same number of dimensions which will be at least two.
\item
\emph{Concatenation along second dimension}:\\
\lstinline![A, B, C, $\ldots$] = cat(2, promote(A, n), promote(B, n), promote(C, n), $\ldots$)!
where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized
dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is
carried out, especially that each operand has at least two dimensions.
\lstinline![A, B, C, $\ldots$] = cat(2, promote(A, n), promote(B, n), promote(C, n), $\ldots$)! where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!.
If necessary, 1-sized dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is carried out, especially that each operand has at least two dimensions.
\item
The two forms can be mixed. \lstinline![$\ldots$, $\ldots$]! has higher precedence than
\lstinline![$\ldots$; $\ldots$]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a, b]; [c, d]]!.
The two forms can be mixed.
\lstinline![$\ldots$, $\ldots$]! has higher precedence than \lstinline![$\ldots$; $\ldots$]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a, b]; [c, d]]!.
\item
\lstinline![A] = promote(A, max(2, ndims(A)))!, i.e., \lstinline![A] = A!, if \lstinline!A! has 2 or more dimensions, and it is a matrix
with the elements of \lstinline!A!, if \lstinline!A! is a scalar or a vector.
\lstinline![A] = promote(A, max(2, ndims(A)))!, i.e., \lstinline![A] = A!, if \lstinline!A! has 2 or more dimensions, and it is a matrix with the elements of \lstinline!A!, if \lstinline!A! is a scalar or a vector.
\item
There must be at least one argument (i.e.\ \lstinline![]! is not defined).
\end{itemize}
Expand Down

0 comments on commit b8fd96f

Please sign in to comment.