ArrayTools - Maple Programming Help

Home : Support : Online Help : Programming : Low-level Manipulation : Matrices, Vectors, and Arrays : ArrayTools : ArrayTools/ComplexAsFloat

ArrayTools

 ComplexAsFloat
 provide real view of a complex Matrix, Vector, or Array

 Calling Sequence ComplexAsFloat(A)

Parameters

 A - rectangular storage Matrix, Vector, or Array of data type complex[8] or complex(sfloat)

Description

 • The ComplexAsFloat(A) command provides a double-size real view of an existing Matrix, Vector, or Array of complex[8] or complex(sfloat) data type. The input Matrix, Vector, or Array must have rectangular (dense) storage.
 • ComplexAsFloat does not change the underlying data of the input rtable object. Instead, ComplexAsFloat casts it to an rtable object with the same specifications, the corresponding float datatype, and double the size in one of the dimensions of the input rtable. As such, changes to the contents of the view also affect the contents of the original input rtable, and vice-versa.
 • If the original Matrix, Vector, or Array has been unassigned, it will still exist in the attributes of the real view, but changing the data will only affect the current view.
 Important: Use this function with caution. If you remove the table reference from the attributes and unassign the original input object, accessing or changing the data in the view will crash Maple. If a persistent and permanent copy of the data is desired, then this command can be used in combination with copy or ArrayTools:-Copy.
 • The layout of the output view from ComplexAsFloat is different for C_order and Fortran_order input, as indicated in the following description.
 If the input rtable is C_order, then the last dimension of the input is doubled on output, and the real and imaginary parts of the input are interleaved (alternating) with respect to the last dimension. For example, calling ComplexAsFloat with a C_order 3 x 4 Matrix results in a 3 x 8 Matrix where the odd columns contain the real parts of the input Matrix, and the even columns contain the imaginary parts (see the Examples section).
 If the input rtable is Fortran_order, then the first dimension of the input is doubled on output, and the real and imaginary parts of the input are interleaved (alternating) with respect to the first dimension. For example, calling ComplexAsFloat with a Fortran_order 3 x 4 Matrix results in a 6 x 4 Matrix where the odd rows contain the real parts of the input Matrix, and the even rows contain the imaginary parts (see the Examples section).
 • This command can be used in combination with ArrayTools:-Fill to clear or set the real or imaginary parts of a complex Matrix, or can be used in combination with ArrayTools:-Copy to efficiently extract the real or imaginary parts of a complex Matrix.
 • This function is part of the ArrayTools package, so it can be used in the short form ComplexAsFloat(..) only after executing the command with(ArrayTools).  However, it can always be accessed through the long form of the command by using ArrayTools[ComplexAsFloat](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$

C_order 3 x 4 Matrix

 > $A≔\mathrm{Matrix}\left(3,4,\left(i,j\right)→i+10j-I\left(i+10j\right),\mathrm{datatype}=\mathrm{complex}[8],\mathrm{order}=\mathrm{C_order}\right)$
 ${A}{≔}\left[\begin{array}{cccc}{11.}{-}{11.}{}{I}& {21.}{-}{21.}{}{I}& {31.}{-}{31.}{}{I}& {41.}{-}{41.}{}{I}\\ {12.}{-}{12.}{}{I}& {22.}{-}{22.}{}{I}& {32.}{-}{32.}{}{I}& {42.}{-}{42.}{}{I}\\ {13.}{-}{13.}{}{I}& {23.}{-}{23.}{}{I}& {33.}{-}{33.}{}{I}& {43.}{-}{43.}{}{I}\end{array}\right]$ (1)
 > $\mathrm{Ar}≔\mathrm{ComplexAsFloat}\left(A\right)$
 ${\mathrm{Ar}}{≔}\left[\begin{array}{cccccccc}{11.}& {-}{11.}& {21.}& {-}{21.}& {31.}& {-}{31.}& {41.}& {-}{41.}\\ {12.}& {-}{12.}& {22.}& {-}{22.}& {32.}& {-}{32.}& {42.}& {-}{42.}\\ {13.}& {-}{13.}& {23.}& {-}{23.}& {33.}& {-}{33.}& {43.}& {-}{43.}\end{array}\right]$ (2)

Use the Fill command to clear imaginary part only. Note this affects A and Ar.

 > $\mathrm{Fill}\left(0,\mathrm{Ar},1,2\right)$
 > $\mathrm{Ar}$
 $\left[\begin{array}{cccccccc}{11.}& {0.}& {21.}& {0.}& {31.}& {0.}& {41.}& {0.}\\ {12.}& {0.}& {22.}& {0.}& {32.}& {0.}& {42.}& {0.}\\ {13.}& {0.}& {23.}& {0.}& {33.}& {0.}& {43.}& {0.}\end{array}\right]$ (3)
 > $A$
 $\left[\begin{array}{cccc}{11.}{+}{0.}{}{I}& {21.}{+}{0.}{}{I}& {31.}{+}{0.}{}{I}& {41.}{+}{0.}{}{I}\\ {12.}{+}{0.}{}{I}& {22.}{+}{0.}{}{I}& {32.}{+}{0.}{}{I}& {42.}{+}{0.}{}{I}\\ {13.}{+}{0.}{}{I}& {23.}{+}{0.}{}{I}& {33.}{+}{0.}{}{I}& {43.}{+}{0.}{}{I}\end{array}\right]$ (4)

Use the Copy command to extract the real part to an existing Matrix.

 > $B≔\mathrm{Matrix}\left(3,4,\mathrm{datatype}=\mathrm{float}[8],\mathrm{order}=\mathrm{C_order}\right):$
 > $\mathrm{Copy}\left(\mathrm{Ar},0,2,B\right)$
 > $B$
 $\left[\begin{array}{cccc}{11.}& {21.}& {31.}& {41.}\\ {12.}& {22.}& {32.}& {42.}\\ {13.}& {23.}& {33.}& {43.}\end{array}\right]$ (5)

Fortran_order 3 x 4 Matrix

 > $A≔\mathrm{Matrix}\left(3,4,\left(i,j\right)→i+10j-I\left(i+10j\right),\mathrm{datatype}=\mathrm{complex}[8],\mathrm{order}=\mathrm{Fortran_order}\right)$
 ${A}{≔}\left[\begin{array}{cccc}{11.}{-}{11.}{}{I}& {21.}{-}{21.}{}{I}& {31.}{-}{31.}{}{I}& {41.}{-}{41.}{}{I}\\ {12.}{-}{12.}{}{I}& {22.}{-}{22.}{}{I}& {32.}{-}{32.}{}{I}& {42.}{-}{42.}{}{I}\\ {13.}{-}{13.}{}{I}& {23.}{-}{23.}{}{I}& {33.}{-}{33.}{}{I}& {43.}{-}{43.}{}{I}\end{array}\right]$ (6)
 > $\mathrm{Ar}≔\mathrm{ComplexAsFloat}\left(A\right)$
 ${\mathrm{Ar}}{≔}\left[\begin{array}{cccc}{11.}& {21.}& {31.}& {41.}\\ {-}{11.}& {-}{21.}& {-}{31.}& {-}{41.}\\ {12.}& {22.}& {32.}& {42.}\\ {-}{12.}& {-}{22.}& {-}{32.}& {-}{42.}\\ {13.}& {23.}& {33.}& {43.}\\ {-}{13.}& {-}{23.}& {-}{33.}& {-}{43.}\end{array}\right]$ (7)