Copy - Maple Help

ArrayTools

 Copy
 copy portion of Matrix, Vector, or Array to another

 Calling Sequence Copy(num, A, offsetA, skipA, B, offsetB, skipB)

Parameters

 num - (optional) number of elements to copy A - source; rectangular storage Matrix, Vector, or Array of any data type and ordering offsetA - (optional) offset for source skipA - (optional) increment for source. Can be specified only if offsetA is specified B - target; rectangular storage Matrix, Vector, or Array of matching data type and any ordering offsetB - (optional) offset for target skipB - (optional) increment for target. Can be specified only if offsetB is specified

Description

 • The Copy command copies data from an existing Matrix, Vector, or Array (source) to another Matrix, Vector, or Array (target). The data types of the source and target must match, or an error results. In addition, the source and target must both have rectangular (dense) storage.
 • The additional parameters, num, offsetA, skipA, offsetB, and skipB extend Copy command usage. For example, you can copy of part of a Matrix to a smaller Matrix, copy one row of a Matrix to a column of another, or copy data from an $nxm$ Matrix to a $nm$ entry Vector.
 The use of these additional parameters is a programmer level feature, and requires detailed knowledge of the storage structure of multidimensional rtables under different data orderings (C_order and Fortran_order).  For a description of storage under these orderings, see Fortran_order.
 • Knowledge of these storage schemes becomes required when you want to compute the num, offsetA, skipA, offsetB, and skipB values to copy part of the data from one Matrix to another.
 • The default values of the parameters are described as follows.
 - offsetA and offsetB are 0 (start at the beginning)
 - skipA and skipB are 1 (fill all consecutive elements)
 - num is chosen so that the operation does not exceed the storage of the rtable
 As an example, copying data from the third column of a $nxm$ C_order Matrix $A$ corresponds to accessing the elements $\left(i-1\right)m+\left(3-1\right)$ for $i=1..n$. If you want to copy the entire column, num, the number of elements to copy would be $n$, the source offset $\mathrm{offsetA}$ would be 3-1=2, and skipA is the distance between consecutive elements (the multiplier of the $i$ above) which is $m$. If you were to copy this column to a $n$ element row Vector $B$, you would not need to compute $\mathrm{offsetB}$ and skipB, as the default values would do. The command to accomplish this would then be Copy(n,A,2,m,B) (where $n,m$ are fixed values corresponding to the problem).
 In contrast, the same operation for a $nxm$ Fortran_order Matrix corresponds to accessing the elements $\left(i-1\right)+\left(3-1\right)n$ for $i=1..n$. It is easy to see that in this case the command would be Copy(n,A,2*n,1,B) (where again $n,m$ are fixed values).
 Note: The calling sequences above can be abbreviated, as $\mathrm{num}=n$ is the largest value of num that can be used without exceeding the bounds of the target Vector. For the second calling sequence, the skipA value of 1 is redundant, as 1 is the default value, so you could use the equivalent calling sequences Copy(A,2,m,B) and Copy(A,2*n,B) respectively. This is shown in the following examples.
 • This function is part of the ArrayTools package, so it can be used in the short form Copy(..) only after executing the command with(ArrayTools).  However, it can always be accessed through the long form of the command by using ArrayTools[Copy](..).

Examples

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

Vector to Vector

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left[\mathrm{row}\right]\left(10,\mathrm{generator}=-100..100,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{integer}\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccccc}{-9}& {99}& {31}& {68}& {79}& {51}& {-25}& {26}& {-70}& {50}\end{array}\right]$ (1)
 > $B≔\mathrm{Vector}\left[\mathrm{row}\right]\left(10,\mathrm{datatype}=\mathrm{integer}\right)$
 ${B}{≔}\left[\begin{array}{cccccccccc}{0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}\end{array}\right]$ (2)

Direct copy from A to B

 > $\mathrm{Copy}\left(A,B\right)$
 > $B$
 $\left[\begin{array}{cccccccccc}{-9}& {99}& {31}& {68}& {79}& {51}& {-25}& {26}& {-70}& {50}\end{array}\right]$ (3)

Clear B and copy first 5 elements of A to B.

 > $\mathrm{Fill}\left(0,B\right)$
 > $\mathrm{Copy}\left(5,A,B\right)$
 > $B$
 $\left[\begin{array}{cccccccccc}{-9}& {99}& {31}& {68}& {79}& {0}& {0}& {0}& {0}& {0}\end{array}\right]$ (4)

Clear B and copy every second element of A to first 5 elements of B.

 > $\mathrm{Fill}\left(0,B\right)$
 > $\mathrm{Copy}\left(5,A,0,2,B\right)$
 > $B$
 $\left[\begin{array}{cccccccccc}{-9}& {31}& {79}& {-25}& {-70}& {0}& {0}& {0}& {0}& {0}\end{array}\right]$ (5)

Copying part of a C_order Matrix to a Vector

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(4,5,\mathrm{generator}=-100..100,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{integer},\mathrm{order}=\mathrm{C_order}\right]\right)$
 ${A}{≔}\left[\begin{array}{ccccc}{-53}& {-80}& {81}& {-69}& {1}\\ {57}& {-59}& {71}& {-65}& {34}\\ {55}& {13}& {73}& {-33}& {87}\\ {-73}& {-19}& {92}& {8}& {93}\end{array}\right]$ (6)
 > $B≔\mathrm{Vector}\left[\mathrm{row}\right]\left(5,\mathrm{datatype}=\mathrm{integer}\right)$
 ${B}{≔}\left[\begin{array}{ccccc}{0}& {0}& {0}& {0}& {0}\end{array}\right]$ (7)

Copy first row of A to B.

 > $\mathrm{Copy}\left(A,B\right)$
 > $B$
 $\left[\begin{array}{ccccc}{-53}& {-80}& {81}& {-69}& {1}\end{array}\right]$ (8)

Copy fourth row of A to B.

 > $\mathrm{Copy}\left(A,\left(4-1\right)\cdot 5,B\right)$
 > $B$
 $\left[\begin{array}{ccccc}{-73}& {-19}& {92}& {8}& {93}\end{array}\right]$ (9)

Copy third column of A to C.

 > $C≔\mathrm{Vector}\left[\mathrm{row}\right]\left(4,\mathrm{datatype}=\mathrm{integer}\right):$
 > $\mathrm{Copy}\left(A,3-1,5,C\right)$
 > $C,A\left[1..4,3\right]$
 $\left[\begin{array}{cccc}{81}& {71}& {73}& {92}\end{array}\right]{,}\left[\begin{array}{c}{81}\\ {71}\\ {73}\\ {92}\end{array}\right]$ (10)

Copying part of a Fortran_order Matrix to a Vector

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(4,5,\mathrm{generator}=-100..100,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{integer},\mathrm{order}=\mathrm{Fortran_order}\right]\right)$
 ${A}{≔}\left[\begin{array}{ccccc}{-41}& {-22}& {21}& {41}& {-23}\\ {-53}& {56}& {30}& {-80}& {36}\\ {97}& {92}& {-84}& {85}& {-4}\\ {-69}& {-92}& {7}& {-57}& {86}\end{array}\right]$ (11)
 > $B≔\mathrm{Vector}\left[\mathrm{row}\right]\left(5,\mathrm{datatype}=\mathrm{integer}\right)$
 ${B}{≔}\left[\begin{array}{ccccc}{0}& {0}& {0}& {0}& {0}\end{array}\right]$ (12)

Copy first row of A to B.

 > $\mathrm{Copy}\left(A,0,4,B\right)$
 > $B$
 $\left[\begin{array}{ccccc}{-41}& {-22}& {21}& {41}& {-23}\end{array}\right]$ (13)

Copy fourth row of A to B.

 > $\mathrm{Copy}\left(A,4-1,4,B\right)$
 > $B$
 $\left[\begin{array}{ccccc}{-69}& {-92}& {7}& {-57}& {86}\end{array}\right]$ (14)

Copy third column of A to C.

 > $C≔\mathrm{Vector}\left[\mathrm{row}\right]\left(4,\mathrm{datatype}=\mathrm{integer}\right):$
 > $\mathrm{Copy}\left(A,\left(3-1\right)\cdot 4,C\right)$
 > $C,A\left[1..4,3\right]$
 $\left[\begin{array}{cccc}{21}& {30}& {-84}& {7}\end{array}\right]{,}\left[\begin{array}{c}{21}\\ {30}\\ {-84}\\ {7}\end{array}\right]$ (15)

Copy all contents of Matrix to a Vector. Note that order is important here.

C_order

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(3,4,\mathrm{generator}=-100..100,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{integer},\mathrm{order}=\mathrm{C_order}\right]\right)$
 ${A}{≔}\left[\begin{array}{cccc}{-63}& {100}& {28}& {18}\\ {-23}& {-83}& {-82}& {17}\\ {65}& {59}& {-4}& {-80}\end{array}\right]$ (16)
 > $B≔\mathrm{Vector}\left[\mathrm{row}\right]\left(12,\mathrm{datatype}=\mathrm{integer}\right):$
 > $\mathrm{Copy}\left(A,B\right)$
 > $B$
 $\left[\begin{array}{cccccccccccc}{-63}& {100}& {28}& {18}& {-23}& {-83}& {-82}& {17}& {65}& {59}& {-4}& {-80}\end{array}\right]$ (17)

Fortran_order

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(3,4,\mathrm{generator}=-100..100,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{integer},\mathrm{order}=\mathrm{Fortran_order}\right]\right)$
 ${A}{≔}\left[\begin{array}{cccc}{75}& {32}& {86}& {-37}\\ {-36}& {72}& {-78}& {60}\\ {67}& {-10}& {45}& {-78}\end{array}\right]$ (18)
 > $\mathrm{Copy}\left(A,B\right)$
 > $B$
 $\left[\begin{array}{cccccccccccc}{75}& {-36}& {67}& {32}& {72}& {-10}& {86}& {-78}& {45}& {-37}& {60}& {-78}\end{array}\right]$ (19)