Copy - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ArrayTools

  

Copy

  

copy portion of Matrix, Vector, or Array to another

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Compatibility

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 i1m+31 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 nxm Fortran_order Matrix corresponds to accessing the elements i1+31n 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](..).

Thread Safety

• 

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.

Examples

withArrayTools:

Vector to Vector

ALinearAlgebra:-RandomVectorrow10,generator=100..100,outputoptions=datatype=integer

A−99931687951−2526−7050

(1)

BVectorrow10,datatype=integer

B0000000000

(2)

Direct copy from A to B

CopyA,B

B

−99931687951−2526−7050

(3)

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

Fill0,B

Copy5,A,B

B

−99931687900000

(4)

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

Fill0,B

Copy5,A,0,2,B

B

−93179−25−7000000

(5)

Copying part of a C_order Matrix to a Vector

ALinearAlgebra:-RandomMatrix4,5,generator=100..100,outputoptions=datatype=integer,order=C_order

A−53−8081−69157−5971−6534551373−3387−73−1992893

(6)

BVectorrow5,datatype=integer

B00000

(7)

Copy first row of A to B.

CopyA,B

B

−53−8081−691

(8)

Copy fourth row of A to B.

CopyA,415,B

B

−73−1992893

(9)

Copy third column of A to C.

CVectorrow4,datatype=integer:

CopyA,31,5,C

C,A1..4,3

81717392,81717392

(10)

Copying part of a Fortran_order Matrix to a Vector

ALinearAlgebra:-RandomMatrix4,5,generator=100..100,outputoptions=datatype=integer,order=Fortran_order

A−41−222141−23−535630−80369792−8485−4−69−927−5786

(11)

BVectorrow5,datatype=integer

B00000

(12)

Copy first row of A to B.

CopyA,0,4,B

B

−41−222141−23

(13)

Copy fourth row of A to B.

CopyA,41,4,B

B

−69−927−5786

(14)

Copy third column of A to C.

CVectorrow4,datatype=integer:

CopyA,314,C

C,A1..4,3

2130−847,2130−847

(15)

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

C_order

ALinearAlgebra:-RandomMatrix3,4,generator=100..100,outputoptions=datatype=integer,order=C_order

A−631002818−23−83−82176559−4−80

(16)

BVectorrow12,datatype=integer:

CopyA,B

B

−631002818−23−83−82176559−4−80

(17)

Fortran_order

ALinearAlgebra:-RandomMatrix3,4,generator=100..100,outputoptions=datatype=integer,order=Fortran_order

A753286−37−3672−786067−1045−78

(18)

CopyA,B

B

75−36673272−1086−7845−3760−78

(19)

You can copy a segment from one rtable to another in reverse if you use a negative value for either skipA or skipB (but not for both: that would cancel the reversion). Here, we copy the six middle entries from A to B. We start at offset 3 in A and at offset 5 in B, and for each next entry, we move forward one position in A and backward one position in B.

AVector12,symbol=a

BVector6

B000000

(20)

CopyA,3,1,B,5,1

Specifying 0 for skipA means that the same value is copied into every position of the target rtable that is overwritten, similar to the ArrayTools:-Fill command. In this example, we copy the second entry of B to all odd-numbered entries of A.

CopyB,1,0,A,0,2

A

Compatibility

• 

The ArrayTools[Copy] command was updated in Maple 2024.

• 

The skipA parameter was updated in Maple 2024.

See Also

ArrayTools

ArrayTools[BlockCopy]

ArrayTools[Fill]

C_order

Fortran_order

interface

LinearAlgebra[RandomMatrix]

Vector