copy portion of Matrix, Vector, or Array to another
Copy(num, A, offsetA, skipA, B, offsetB, skipB)
(optional) number of elements to copy
source; rectangular storage Matrix, Vector, or Array of any data type and ordering
(optional) offset for source
(optional) increment for source. Can be specified only if offsetA is specified
target; rectangular storage Matrix, Vector, or Array of matching data type and any ordering
(optional) offset for target
(optional) increment for target. Can be specified only if offsetB is specified
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 n⁢x⁢m Matrix to a n⁢m 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 n⁢x⁢m C_order Matrix A corresponds to accessing the elements i−1⁢m+3−1 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 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 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 n⁢x⁢m Fortran_order Matrix corresponds to accessing the elements i−1+3−1⁢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 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](..).
The Copy command is thread safe as of Maple 2023, provided that the rtables A and B are not shared between threads.
For more information on thread safety, see index/threadsafe.
Vector to Vector
A ≔ LinearAlgebra:-RandomVectorrow⁡10,generator=−100..100,outputoptions=datatype=integer
B ≔ Vectorrow⁡10,datatype=integer
Direct copy from A to B
Clear B and copy first 5 elements of A to B.
Clear B and copy every second element of A to first 5 elements of B.
Copying part of a C_order Matrix to a Vector
A ≔ LinearAlgebra:-RandomMatrix⁡4,5,generator=−100..100,outputoptions=datatype=integer,order=C_order
B ≔ Vectorrow⁡5,datatype=integer
Copy first row of A to B.
Copy fourth row of A to B.
Copy third column of A to C.
C ≔ Vectorrow⁡4,datatype=integer:
Copying part of a Fortran_order Matrix to a Vector
A ≔ LinearAlgebra:-RandomMatrix⁡4,5,generator=−100..100,outputoptions=datatype=integer,order=Fortran_order
Copy all contents of Matrix to a Vector. Note that order is important here.
A ≔ LinearAlgebra:-RandomMatrix⁡3,4,generator=−100..100,outputoptions=datatype=integer,order=C_order
B ≔ Vectorrow⁡12,datatype=integer:
A ≔ LinearAlgebra:-RandomMatrix⁡3,4,generator=−100..100,outputoptions=datatype=integer,order=Fortran_order
Download Help Document