JWS C Library
C language utility library
blas.c File Reference

Definitions for a C interface to the functions from BLAS levels 1, 2, and 3. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <assert.h>
#include <Accelerate/Accelerate.h>
#include "jwsc/math/complex.h"
#include "jwsc/math/blas.h"
Include dependency graph for blas.c:

Go to the source code of this file.

Functions

[sdcz]swap

Swaps the elements of two vectors.

void blas_sswap (int n, float *x, int inc_x, float *y, int inc_y)
 Single precision.
void blas_dswap (int n, double *x, int inc_x, double *y, int inc_y)
 Double precision.
void blas_cswap (int n, Complex_f *x, int inc_x, Complex_f *y, int inc_y)
 Complex single precision.
void blas_zswap (int n, Complex_d *x, int inc_x, Complex_d *y, int inc_y)
 Complex double precision.
[sdcz]scal

Multiplies a vector by a scalar.

void blas_sscal (int n, float a, float *x, int inc_x)
 Single precision.
void blas_dscal (int n, double a, double *x, int inc_x)
 Double precision vector by a scalar.
void blas_cscal (int n, Complex_f a, Complex_f *x, int inc_x)
 Complex single precision.
void blas_zscal (int n, Complex_d a, Complex_d *x, int inc_x)
 Complex double precision.
[sdcz]copy

Copies a vector into another.

void blas_scopy (int n, const float *x, int inc_x, float *y, int inc_y)
 Single precision.
void blas_dcopy (int n, const double *x, int inc_x, double *y, int inc_y)
 Double precision.
void blas_ccopy (int n, const Complex_f *x, int inc_x, Complex_f *y, int inc_y)
 Complex single precision.
void blas_zcopy (int n, const Complex_d *x, int inc_x, Complex_d *y, int inc_y)
 Complex double precision.
[sdcz]axpy

Constant times a vector plus a vector.

void blas_saxpy (int n, float a, const float *x, int inc_x, float *y, int inc_y)
 Single precision.
void blas_daxpy (int n, double a, const double *x, int inc_x, double *y, int inc_y)
 Double precision.
void blas_caxpy (int n, Complex_f a, const Complex_f *x, int inc_x, Complex_f *y, int inc_y)
 Complex single precision.
void blas_zaxpy (int n, Complex_d a, const Complex_d *x, int inc_x, Complex_d *y, int inc_y)
 Complex double precision.
[sd]dot

Vector dot (inner) product.

float blas_sdot (int n, const float *x, int inc_x, const float *y, int inc_y)
 Single precision.
double blas_ddot (int n, const double *x, int inc_x, const double *y, int inc_y)
 Double precision.
[sd]nrm2

Vector magnitude (Euclidean norm).

float blas_snrm2 (int n, const float *x, int inc_x)
 Single precision.
double blas_dnrm2 (int n, const double *x, int inc_x)
 Double precision.
[sd]asum

Sum of the magnitudes of the elements of a vector.

float blas_sasum (int n, const float *x, int inc_x)
 Single precision.
double blas_dasum (int n, const double *x, int inc_x)
 Double precision.
i[sdcz]amax

Maximum absolute value in a vector.

int blas_isamax (int n, const float *x, int inc_x)
 Single precision.
int blas_idamax (int n, const double *x, int inc_x)
 Double precision.
int blas_icamax (int n, const Complex_f *x, int inc_x)
 Complex single precision.
int blas_izamax (int n, const Complex_d *x, int inc_x)
 Complex double precision.
[sdcz]gemv

General matrix-vector multiplication.

void blas_sgemv (char trans, int m, int n, float alpha, const float *A, int lda, const float *x, int inc_x, float beta, float *y, int inc_y)
 Single precision.
void blas_dgemv (char trans, int m, int n, double alpha, const double *A, int lda, const double *x, int inc_x, double beta, double *y, int inc_y)
 Double precision.
void blas_cgemv (char trans, int m, int n, Complex_f alpha, const Complex_f *A, int lda, const Complex_f *x, int inc_x, Complex_f beta, Complex_f *y, int inc_y)
 Complex single precision.
void blas_zgemv (char trans, int m, int n, Complex_d alpha, const Complex_d *A, int lda, const Complex_d *x, int inc_x, Complex_d beta, Complex_d *y, int inc_y)
 Complex double precision.
[sdcz]gemm

General matrix multiplication.

void blas_sgemm (char trans_a, char trans_b, int m, int n, int k, float alpha, const float *A, int lda, const float *B, int ldb, float beta, float *C, int ldc)
 Single precision.
void blas_dgemm (char trans_a, char trans_b, int m, int n, int k, double alpha, const double *A, int lda, const double *B, int ldb, double beta, double *C, int ldc)
 Double precision.
void blas_cgemm (char trans_a, char trans_b, int m, int n, int k, Complex_f alpha, const Complex_f *A, int lda, const Complex_f *B, int ldb, Complex_f beta, Complex_f *C, int ldc)
 Complex single precision.
void blas_zgemm (char trans_a, char trans_b, int m, int n, int k, Complex_d alpha, const Complex_d *A, int lda, const Complex_d *B, int ldb, Complex_d beta, Complex_d *C, int ldc)
 Complex double precision.

Detailed Description

Definitions for a C interface to the functions from BLAS levels 1, 2, and 3.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Wraps levels 1, 2, and 3 of the BLAS library (standard) from netlib. Not all functions are wrapped, just the ones I find useful.

Manipulates the transpose parameters so that all matrices can be passed as row-major ordered.

Definition in file blas.c.


Function Documentation

void blas_sswap ( int  n,
float *  x,
int  inc_x,
float *  y,
int  inc_y 
)

Single precision.

Definition at line 74 of file blas.c.

void blas_dswap ( int  n,
double *  x,
int  inc_x,
double *  y,
int  inc_y 
)

Double precision.

Definition at line 79 of file blas.c.

void blas_cswap ( int  n,
Complex_f x,
int  inc_x,
Complex_f y,
int  inc_y 
)

Complex single precision.

Definition at line 84 of file blas.c.

void blas_zswap ( int  n,
Complex_d x,
int  inc_x,
Complex_d y,
int  inc_y 
)

Complex double precision.

Definition at line 89 of file blas.c.

void blas_sscal ( int  n,
float  a,
float *  x,
int  inc_x 
)

Single precision.

Definition at line 106 of file blas.c.

void blas_dscal ( int  n,
double  a,
double *  x,
int  inc_x 
)

Double precision vector by a scalar.

Definition at line 111 of file blas.c.

void blas_cscal ( int  n,
Complex_f  a,
Complex_f x,
int  inc_x 
)

Complex single precision.

Definition at line 116 of file blas.c.

void blas_zscal ( int  n,
Complex_d  a,
Complex_d x,
int  inc_x 
)

Complex double precision.

Definition at line 121 of file blas.c.

void blas_scopy ( int  n,
const float *  x,
int  inc_x,
float *  y,
int  inc_y 
)

Single precision.

Definition at line 138 of file blas.c.

void blas_dcopy ( int  n,
const double *  x,
int  inc_x,
double *  y,
int  inc_y 
)

Double precision.

Definition at line 143 of file blas.c.

void blas_ccopy ( int  n,
const Complex_f x,
int  inc_x,
Complex_f y,
int  inc_y 
)

Complex single precision.

Definition at line 148 of file blas.c.

void blas_zcopy ( int  n,
const Complex_d x,
int  inc_x,
Complex_d y,
int  inc_y 
)

Complex double precision.

Definition at line 153 of file blas.c.

void blas_saxpy ( int  n,
float  a,
const float *  x,
int  inc_x,
float *  y,
int  inc_y 
)

Single precision.

Definition at line 171 of file blas.c.

void blas_daxpy ( int  n,
double  a,
const double *  x,
int  inc_x,
double *  y,
int  inc_y 
)

Double precision.

Definition at line 184 of file blas.c.

void blas_caxpy ( int  n,
Complex_f  a,
const Complex_f x,
int  inc_x,
Complex_f y,
int  inc_y 
)

Complex single precision.

Definition at line 197 of file blas.c.

void blas_zaxpy ( int  n,
Complex_d  a,
const Complex_d x,
int  inc_x,
Complex_d y,
int  inc_y 
)

Complex double precision.

Definition at line 210 of file blas.c.

float blas_sdot ( int  n,
const float *  x,
int  inc_x,
const float *  y,
int  inc_y 
)

Single precision.

Definition at line 234 of file blas.c.

double blas_ddot ( int  n,
const double *  x,
int  inc_x,
const double *  y,
int  inc_y 
)

Double precision.

Definition at line 239 of file blas.c.

float blas_snrm2 ( int  n,
const float *  x,
int  inc_x 
)

Single precision.

Definition at line 256 of file blas.c.

double blas_dnrm2 ( int  n,
const double *  x,
int  inc_x 
)

Double precision.

Definition at line 261 of file blas.c.

float blas_sasum ( int  n,
const float *  x,
int  inc_x 
)

Single precision.

Definition at line 278 of file blas.c.

double blas_dasum ( int  n,
const double *  x,
int  inc_x 
)

Double precision.

Definition at line 283 of file blas.c.

int blas_isamax ( int  n,
const float *  x,
int  inc_x 
)

Single precision.

Definition at line 300 of file blas.c.

int blas_idamax ( int  n,
const double *  x,
int  inc_x 
)

Double precision.

Definition at line 305 of file blas.c.

int blas_icamax ( int  n,
const Complex_f x,
int  inc_x 
)

Complex single precision.

Definition at line 310 of file blas.c.

int blas_izamax ( int  n,
const Complex_d x,
int  inc_x 
)

Complex double precision.

Definition at line 315 of file blas.c.

void blas_sgemv ( char  trans,
int  m,
int  n,
float  alpha,
const float *  A,
int  lda,
const float *  x,
int  inc_x,
float  beta,
float *  y,
int  inc_y 
)

Single precision.

Performs the matrix-vector operation

 y := alpha*A*x + beta*y,   or   y := alpha*A'*x + beta*y 
Parameters:
transSet to 'N', or 'T' for no transpose or transpose of A.
mNumber of rows in A (before applying trans).
nNumber of columns in A (before applying trans).
alphaScalar for A.
AMatrix.
ldaNumber of columns in A (before applying trans). Also referred to as the leading dimension of A.
xArray of length (1 + (n - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_xIncrement for x, usually 1.
betaScalar for y. If set to zero, y is not added to the operation.
yArray of length (1 + (m - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_yIncrement for y, usually 1.
Note:
m, n, and lda specify matrix dimensions before the transpose operation is applied (if set to 'T').

Definition at line 359 of file blas.c.

void blas_dgemv ( char  trans,
int  m,
int  n,
double  alpha,
const double *  A,
int  lda,
const double *  x,
int  inc_x,
double  beta,
double *  y,
int  inc_y 
)

Double precision.

Performs the matrix-vector operation

 y := alpha*A*x + beta*y,   or   y := alpha*A'*x + beta*y 
Parameters:
transSet to 'N', or 'T' for no transpose or transpose of A.
mNumber of rows in A (before applying trans).
nNumber of columns in A (before applying trans).
alphaScalar for A.
AMatrix.
ldaNumber of columns in A (before applying trans). Also referred to as the leading dimension of A.
xArray of length (1 + (n - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_xIncrement for x, usually 1.
betaScalar for y. If set to zero, y is not added to the operation.
yArray of length (1 + (m - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_yIncrement for y, usually 1.
Note:
m, n, and lda specify matrix dimensions before the transpose operation is applied (if set to 'T').

Definition at line 402 of file blas.c.

void blas_cgemv ( char  trans,
int  m,
int  n,
Complex_f  alpha,
const Complex_f A,
int  lda,
const Complex_f x,
int  inc_x,
Complex_f  beta,
Complex_f y,
int  inc_y 
)

Complex single precision.

Performs the matrix-vector operation

 y := alpha*A*x + beta*y,   or   y := alpha*A'*x + beta*y 
Parameters:
transSet to 'N', or 'T' for no transpose or transpose of A.
mNumber of rows in A (before applying trans).
nNumber of columns in A (before applying trans).
alphaScalar for A.
AMatrix.
ldaNumber of columns in A (before applying trans). Also referred to as the leading dimension of A.
xArray of length (1 + (n - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_xIncrement for x, usually 1.
betaScalar for y. If set to zero, y is not added to the operation.
yArray of length (1 + (m - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_yIncrement for y, usually 1.
Note:
m, n, and lda specify matrix dimensions before the transpose operation is applied (if set to 'T').

Definition at line 445 of file blas.c.

void blas_zgemv ( char  trans,
int  m,
int  n,
Complex_d  alpha,
const Complex_d A,
int  lda,
const Complex_d x,
int  inc_x,
Complex_d  beta,
Complex_d y,
int  inc_y 
)

Complex double precision.

Performs the matrix-vector operation

 y := alpha*A*x + beta*y,   or   y := alpha*A'*x + beta*y 
Parameters:
transSet to 'N', or 'T' for no transpose or transpose of A.
mNumber of rows in A (before applying trans).
nNumber of columns in A (before applying trans).
alphaScalar for A.
AMatrix.
ldaNumber of columns in A (before applying trans). Also referred to as the leading dimension of A.
xArray of length (1 + (n - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_xIncrement for x, usually 1.
betaScalar for y. If set to zero, y is not added to the operation.
yArray of length (1 + (m - 1)*abs(INCX)) if trans == 'N'; (1 + (m - 1)*abs(INCX)) otherwise.
inc_yIncrement for y, usually 1.
Note:
m, n, and lda specify matrix dimensions before the transpose operation is applied (if set to 'T').

Definition at line 488 of file blas.c.

void blas_sgemm ( char  trans_a,
char  trans_b,
int  m,
int  n,
int  k,
float  alpha,
const float *  A,
int  lda,
const float *  B,
int  ldb,
float  beta,
float *  C,
int  ldc 
)

Single precision.

Performs the matrix operation

 C := alpha*op( A )*op( B ) + beta*C 

where op( X ) is one of

 op( X ) = X   or   op( X ) = X' 
Parameters:
trans_aSet to 'N', or 'T' for no transpose or transpose of A.
trans_bSet to 'N', or 'T' for no transpose or transpose of B.
mNumber of rows in A (after applying trans_a).
nNumber of columns in B (after applying trans_b).
kNumber of columns in A and number of rows in B (after applying trans_a and trans_b).
alphaScalar for op( A )*op( B ).
AMatrix.
ldaNumber of columns in A (after applying trans_a). Also referred to as the leading dimension of A.
BMatrix.
ldbNumber of columns in B (after applying trans_b). Also referred to as the leading dimension of B.
betaScalar for C. If set to zero, C is not added to the operation.
CMatrix.
ldcNumber of columns in C. Also referred to as the leading dimension of C.
Note:
m, n, k, lda, and ldb specify matrix dimensions after the transpose operation is applied (if set to 'T').

Definition at line 554 of file blas.c.

void blas_dgemm ( char  trans_a,
char  trans_b,
int  m,
int  n,
int  k,
double  alpha,
const double *  A,
int  lda,
const double *  B,
int  ldb,
double  beta,
double *  C,
int  ldc 
)

Double precision.

Performs the matrix operation

 C := alpha*op( A )*op( B ) + beta*C 

where op( X ) is one of

 op( X ) = X   or   op( X ) = X' 
Parameters:
trans_aSet to 'N', or 'T' for no transpose or transpose of A.
trans_bSet to 'N', or 'T' for no transpose or transpose of B.
mNumber of rows in A (after applying trans_a).
nNumber of columns in B (after applying trans_b).
kNumber of columns in A and number of rows in B (after applying trans_a and trans_b).
alphaScalar for op( A )*op( B ).
AMatrix.
ldaNumber of columns in A (after applying trans_a). Also referred to as the leading dimension of A.
BMatrix.
ldbNumber of columns in B (after applying trans_b). Also referred to as the leading dimension of B.
betaScalar for C. If set to zero, C is not added to the operation.
CMatrix.
ldcNumber of columns in C. Also referred to as the leading dimension of C.
Note:
m, n, k, lda, and ldb specify matrix dimensions after the transpose operation is applied (if set to 'T').

Definition at line 608 of file blas.c.

void blas_cgemm ( char  trans_a,
char  trans_b,
int  m,
int  n,
int  k,
Complex_f  alpha,
const Complex_f A,
int  lda,
const Complex_f B,
int  ldb,
Complex_f  beta,
Complex_f C,
int  ldc 
)

Complex single precision.

Performs the matrix operation

 C := alpha*op( A )*op( B ) + beta*C 

where op( X ) is one of

 op( X ) = X   or   op( X ) = X' 
Parameters:
trans_aSet to 'N', or 'T' for no transpose or transpose of A.
trans_bSet to 'N', or 'T' for no transpose or transpose of B.
mNumber of rows in A (after applying trans_a).
nNumber of columns in B (after applying trans_b).
kNumber of columns in A and number of rows in B (after applying trans_a and trans_b).
alphaScalar for op( A )*op( B ).
AMatrix.
ldaNumber of columns in A (after applying trans_a). Also referred to as the leading dimension of A.
BMatrix.
ldbNumber of columns in B (after applying trans_b). Also referred to as the leading dimension of B.
betaScalar for C. If set to zero, C is not added to the operation.
CMatrix.
ldcNumber of columns in C. Also referred to as the leading dimension of C.
Note:
m, n, k, lda, and ldb specify matrix dimensions after the transpose operation is applied (if set to 'T').

Definition at line 662 of file blas.c.

void blas_zgemm ( char  trans_a,
char  trans_b,
int  m,
int  n,
int  k,
Complex_d  alpha,
const Complex_d A,
int  lda,
const Complex_d B,
int  ldb,
Complex_d  beta,
Complex_d C,
int  ldc 
)

Complex double precision.

Performs the matrix operation

 C := alpha*op( A )*op( B ) + beta*C 

where op( X ) is one of

 op( X ) = X   or   op( X ) = X' 
Parameters:
trans_aSet to 'N', or 'T' for no transpose or transpose of A.
trans_bSet to 'N', or 'T' for no transpose or transpose of B.
mNumber of rows in A (after applying trans_a).
nNumber of columns in B (after applying trans_b).
kNumber of columns in A and number of rows in B (after applying trans_a and trans_b).
alphaScalar for op( A )*op( B ).
AMatrix.
ldaNumber of columns in A (after applying trans_a). Also referred to as the leading dimension of A.
BMatrix.
ldbNumber of columns in B (after applying trans_b). Also referred to as the leading dimension of B.
betaScalar for C. If set to zero, C is not added to the operation.
CMatrix.
ldcNumber of columns in C. Also referred to as the leading dimension of C.
Note:
m, n, k, lda, and ldb specify matrix dimensions after the transpose operation is applied (if set to 'T').

Definition at line 716 of file blas.c.