IDL

BLAS_AXPY

BLAS_AXPY

The BLAS_AXPY procedure updates an existing array by adding a multiple of another array. It can also be used to update one or more one-dimensional subvectors of an array according to the following vector operation:

where a is a scale factor and X is an input vector.

BLAS_AXPY can be faster and use less memory than the usual IDL array notation
(e.g. Y=Y+A*X) for updating existing arrays.

Note: BLAS_AXPY is much faster when operating on entire arrays and rows, than when used on columns or higher dimensions.

Syntax


BLAS_AXPY, Y, A, X [, D1, Loc1 [, D2, Range]]

Arguments


Y

The array to be updated. Y can be of any numeric type. BLAS_AXPY does not change the size and type of Y.

A

The scaling factor to be multiplied with X. A may be any scalar or one-element array that IDL can convert to the type of X. BLAS_AXPY does not change A.

X

The array to be scaled and added to array Y, or the vector to be scaled and added to subvectors of Y.

D1

An optional parameter indicating which dimension of Y is to be updated.

Loc1

A variable with the same number of elements as the number of dimensions of Y. The Loc1 and D1 arguments together determine which one-dimensional subvector (or subvectors, if D2 and Range are provided) of Y is to be updated.

D2

An optional parameter, indicating in which dimension of Y a group of one-dimensional subvectors are to be updated. D2 should be different from D1.

Range

A variable containing D2 indices indicating where to put one-dimensional updates of Y.

Keywords


None

Examples


The following examples show how to use the BLAS_AXPY procedure to add a multiple of an array, add a constant, and a group of subvectors.

seed = 5L

Create a multidimensional array:

A = FINDGEN(4, 5, 2)

Print A:

PRINT, A

IDL prints:

     0.000000      1.00000      2.00000      3.00000
      4.00000      5.00000      6.00000      7.00000
      8.00000      9.00000      10.0000      11.0000
      12.0000      13.0000      14.0000      15.0000
      16.0000      17.0000      18.0000      19.0000
 
      20.0000      21.0000      22.0000      23.0000
      24.0000      25.0000      26.0000      27.0000
      28.0000      29.0000      30.0000      31.0000
      32.0000      33.0000      34.0000      35.0000
      36.0000      37.0000      38.0000      39.0000

Create a random update:

B = RANDOMU(seed, 4, 5, 2)

Print B

PRINT, B

IDL prints:

     0.172861     0.680409     0.917078     0.917510
     0.766779     0.648501     0.334211     0.505953
     0.652182     0.158174     0.912751     0.257593
     0.810990     0.267308     0.188872     0.237323
     0.312265     0.551604     0.944883     0.673464
 
     0.613302    0.0874299     0.782052     0.374534
    0.0799968     0.581460     0.433864     0.459824
     0.634644     0.182057     0.832474     0.235194
     0.432587     0.453664     0.738821     0.355747
     0.933211     0.388659     0.269595     0.796325

Add a multiple of B to A (i.e., A = A + 4.5*B):

BLAS_AXPY, A, 4.5, B

Print A:

PRINT, A

IDL prints:

     0.777872      4.06184      6.12685      7.12880
      7.45051      7.91825      7.50395      9.27679
      10.9348      9.71178      14.1074      12.1592
      15.6495      14.2029      14.8499      16.0680
      17.4052      19.4822      22.2520      22.0306
 
      22.7599      21.3934      25.5192      24.6854
      24.3600      27.6166      27.9524      29.0692
      30.8559      29.8193      33.7461      32.0584
      33.9466      35.0415      37.3247      36.6009
      40.1994      38.7490      39.2132      42.5835

Add a constant to a subvector of A (i.e. A[*, 3, 1] = A[*, 3, 1] + 4.3):

BLAS_AXPY, A, 1., REPLICATE(4.3, 4), 1, [0, 3, 1]

Print A:

PRINT, A

IDL prints:

     0.777872      4.06184      6.12685      7.12880
      7.45051      7.91825      7.50395      9.27679
      10.9348      9.71178      14.1074      12.1592
      15.6495      14.2029      14.8499      16.0680
      17.4052      19.4822      22.2520      22.0306
 
      22.7599      21.3934      25.5192      24.6854
      24.3600      27.6166      27.9524      29.0692
      30.8559      29.8193      33.7461      32.0584
      38.2466      39.3415      41.6247      40.9009
      40.1994      38.7490      39.2132      42.5835

Create a vector update and print:

C = FINDGEN(5)
PRINT, C

IDL prints:

     0.000000      1.00000      2.00000      3.00000      4.00000

Add C to a group of subvectors of A (i.e. FOR i = 0, 1 DO A[1, *, i] = A[1, *, i] + C) and print:

BLAS_AXPY, A, 1., C, 2, [1, 0, 0], 3, LINDGEN(2)
PRINT, A

IDL prints:

     0.777872      4.06184      6.12685      7.12880
      7.45051      8.91825      7.50395      9.27679
      10.9348      11.7118      14.1074      12.1592
      15.6495      17.2029      14.8499      16.0680
      17.4052      23.4822      22.2520      22.0306
 
      22.7599      21.3934      25.5192      24.6854
      24.3600      28.6166      27.9524      29.0692
      30.8559      31.8193      33.7461      32.0584
      38.2466      42.3415      41.6247      40.9009
      40.1994      42.7490      39.2132      42.5835

Version History


5.1

Introduced

See Also


REPLICATE_INPLACE

Notes


This page has no user notes yet. Be the first one!


This information is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). However, it may be restricted from transfer to various embargoed countries under U.S. laws and regulations.
© 2014 Exelis Visual Information Solutions