我要评分
获取效率
正确性
完整性
易理解

?axpy

Sum up the product of the scaled vector and another vector, that is, .

Alpha is a multiplication coefficient, and x and y are vectors with a length of n.

Interface Definition

C interface:

void cblas_saxpy(const BLASINT n, const float alpha, const float *x, const BLASINT incx, float *y, const BLASINT incy);

void cblas_daxpy(const BLASINT n, const double alpha, const double *x, const BLASINT incx, double *y, const BLASINT incy);

void cblas_caxpy(const BLASINT n, const void *alpha, const void *x, const BLASINT incx, void *y, const BLASINT incy);

void cblas_zaxpy(const BLASINT n, const void *alpha, const void *x, const BLASINT incx, void *y, const BLASINT incy);

Fortran interface:

CALL SAXPY(N, ALPHA, X, INCX, Y, INCY)

CALL DAXPY(N, ALPHA, X, INCX, Y, INCY)

CALL CAXPY(N, ALPHA, X, INCX, Y, INCY)

CALL ZAXPY(N, ALPHA, X, INCX, Y, INCY)

Parameters

Parameter

Type

Description

Input/Output

n

Integer

Number of elements in vector x

Input

alpha

  • Double-precision floating-point type for daxpy
  • Single-precision floating-point type for saxpy
  • Single-precision complex type for caxpy
  • Double-precision complex type for zaxpy

Multiplication coefficient

Input

x

  • For daxpy, x is of double-precision floating-point type.
  • For saxpy, x is of single-precision floating-point type.
  • For caxpy, x is of single-precision complex number type.
  • For zaxpy, x is of double-precision complex number type.

Vector x. The vector size is at least (1+(n-1)*abs(incx)).

Input

incx

Integer

Increment for the elements of vector x

Input

y

  • For daxpy, y is of double-precision floating-point type.
  • For saxpy, y is of single-precision floating-point type.
  • For caxpy, y is of single-precision complex number type.
  • For zaxpy, y is of double-precision complex number type.

Vector y. The vector size is at least (1+(n-1)*abs(incy)).

Input/Output

incy

Integer

Increment for the elements of vector y

Input

Dependencies

#include "kblas.h"

Examples

C interface:

    float alpha = 2.0; 
    int n = 5, incx = 1, incy = 1; 
    /** 
     *    X:f 0.340188, -0.105617, 0.283099, 0.298440, 0.411647 
     *    Y: -0.302449, -0.164777, 0.268230, -0.222225, 0.053970 
     */ 
    float x[5] = {0.340188, -0.105617, 0.283099, 0.298440, 0.411647}; 
    float y[5] = {-0.302449, -0.164777, 0.268230, -0.222225, 0.053970}; 
 
    cblas_saxpy(n, alpha, x, incx, y, incy); 
    /** 
     *    Output Y: 0.377927, -0.376011, 0.834428, 0.374655, 0.877264 
     */

Fortran interface:

      REAL(4) :: ALPHA=2.0 
      INTEGER :: N=5 
      INTEGER :: INCX=1 
      INTEGER :: INCY=1 
      REAL(4) :: X(5) 
      DATA X /0.340188, -0.105617, 0.283099, 0.298440, 0.411647/ 
      REAL(4) :: Y(5) 
      DATA Y /-0.302449, -0.164777, 0.268230, -0.222225, 0.053970/ 
      CALL SAXPY(N, ALPHA, X, INCX, Y, INCY) 
 
*     Output Y : 0.377927, -0.376011, 0.834428, 0.374655, 0.877264