PyPO User Manual
GUtils.h File Reference

Linear algebra functions for the CUDA version of PyPO. More...

#include <math.h>
#include <cuda.h>
#include <cuComplex.h>

Go to the source code of this file.

Functions

__device__ __inline__ void dot (float(&v1)[3], float(&v2)[3], float &out)
 
__device__ __inline__ void dot (cuFloatComplex(&cv1)[3], cuFloatComplex(&cv2)[3], cuFloatComplex &out)
 
__device__ __inline__ void dot (cuFloatComplex(&cv1)[3], float(&v2)[3], cuFloatComplex &out)
 
__device__ __inline__ void dot (float(&v1)[3], cuFloatComplex(&cv2)[3], cuFloatComplex &out)
 
__device__ __inline__ void ext (float(&v1)[3], float(&v2)[3], float(&out)[3])
 
__device__ __inline__ void ext (cuFloatComplex(&cv1)[3], cuFloatComplex(&cv2)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void ext (cuFloatComplex(&cv1)[3], float(&v2)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void ext (float(&v1)[3], cuFloatComplex(&cv2)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void diff (float(&v1)[3], float(&v2)[3], float(&out)[3])
 
__device__ __inline__ void diff (cuFloatComplex(&cv1)[3], cuFloatComplex(&cv2)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void abs (float(&v)[3], float &out)
 
__device__ __inline__ void conja (cuFloatComplex(&cv)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void normalize (float(&v)[3], float(&out)[3])
 
__device__ __inline__ void add (float(&v1)[3], float(&v2)[3], float(&out)[3])
 
__device__ __inline__ void s_mult (float(&v)[3], float &s, float(&out)[3])
 
__device__ __inline__ void s_mult (cuFloatComplex(&cv)[3], cuFloatComplex &cs, cuFloatComplex(&out)[3])
 
__device__ __inline__ void s_mult (float(&v)[3], cuFloatComplex &cs, cuFloatComplex(&out)[3])
 
__device__ __inline__ void s_mult (cuFloatComplex(&cv)[3], const float &s, cuFloatComplex(&out)[3])
 
__device__ __inline__ void snell (cuFloatComplex(&cvin)[3], float(&normal)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void snell (float(&vin)[3], float(&normal)[3], float(&out)[3])
 
__device__ __inline__ void snell_t (float(&vin)[3], float(&normal)[3], float mu, float(&out)[3])
 
__device__ __inline__ void dyad (float(&v1)[3], float(&v2)[3], float(&out)[3][3])
 
__device__ __inline__ void matDiff (float(&m1)[3][3], float(&m2)[3][3], float(&out)[3][3])
 
__device__ __inline__ void matVec (float(&m1)[3][3], float(&v1)[3], float(&out)[3])
 
__device__ __inline__ void matVec (float(&m1)[3][3], cuFloatComplex(&cv1)[3], cuFloatComplex(&out)[3])
 
__device__ __inline__ void matVec4 (float(&mat)[16], float(&cv1)[3], float(&out)[3], bool vec=false)
 
__device__ __inline__ void invmatVec4 (float(&mat)[16], float(&cv1)[3], float(&out)[3], bool vec=false)
 
__device__ __inline__ cuFloatComplex cuCexpf (cuFloatComplex z)
 
__device__ __inline__ cuFloatComplex cuCaddSf (cuFloatComplex a, float b)
 
__device__ __inline__ cuFloatComplex cuCaddSf (float a, cuFloatComplex b)
 
__device__ __inline__ cuFloatComplex cuCsubSf (cuFloatComplex a, float b)
 
__device__ __inline__ cuFloatComplex cuCsubSf (float a, cuFloatComplex b)
 
__device__ __inline__ cuFloatComplex cuCmulSf (cuFloatComplex a, float b)
 
__device__ __inline__ cuFloatComplex cuCmulSf (float a, cuFloatComplex b)
 
__device__ __inline__ cuFloatComplex cuCdivSf (cuFloatComplex a, float b)
 
__device__ __inline__ cuFloatComplex cuCdivSf (float a, cuFloatComplex b)
 

Detailed Description

Linear algebra functions for the CUDA version of PyPO.

Contains float overloaded functions for doing basic 3D vector operations. For the CUDA complex valued linear algebra, we employ the cuComplex.h library.

Function Documentation

◆ abs()

__device__ __inline__ void abs ( float(&)  v[3],
float &  out 
)

Absolute value.

Calculate absolute value of real valued vector of size 3.

Parameters
vArray of 3 float.
outScalar float.

◆ add()

__device__ __inline__ void add ( float(&)  v1[3],
float(&)  v2[3],
float(&)  out[3] 
)

Vector addition.

Add two real valued vectors of size 3 element-wise.

Parameters
v1Array of 3 float.
v2Array of 3 float.
outArray of 3 complex float.

◆ conja()

__device__ __inline__ void conja ( cuFloatComplex(&)  cv[3],
cuFloatComplex(&)  out[3] 
)

Conjugate.

Conjugate complex valued vector of size 3.

Parameters
cvArray of 3 complex float.
outArray of 3 complex float.

◆ cuCaddSf() [1/2]

__device__ __inline__ cuFloatComplex cuCaddSf ( cuFloatComplex  a,
float  b 
)

Add scalar float to complex number.

Returns
res cuFloatComplex number.

◆ cuCaddSf() [2/2]

__device__ __inline__ cuFloatComplex cuCaddSf ( float  a,
cuFloatComplex  b 
)

Add complex number to scalar float.

Returns
res cuFloatComplex number.

◆ cuCdivSf() [1/2]

__device__ __inline__ cuFloatComplex cuCdivSf ( cuFloatComplex  a,
float  b 
)

Divide complex number by scalar float.

Returns
res cuFloatComplex number.

◆ cuCdivSf() [2/2]

__device__ __inline__ cuFloatComplex cuCdivSf ( float  a,
cuFloatComplex  b 
)

Divide scalar by complex float.

Returns
res cuFloatComplex number.

◆ cuCexpf()

__device__ __inline__ cuFloatComplex cuCexpf ( cuFloatComplex  z)

Take complex exponential.

Take complex exponential by decomposing into sine and cosine.

Returns
res cuFloatComplex number.

◆ cuCmulSf() [1/2]

__device__ __inline__ cuFloatComplex cuCmulSf ( cuFloatComplex  a,
float  b 
)

Multiply complex number by scalar float.

Returns
res cuFloatComplex number.

◆ cuCmulSf() [2/2]

__device__ __inline__ cuFloatComplex cuCmulSf ( float  a,
cuFloatComplex  b 
)

Multiply complex number by scalar float.

Returns
res cuFloatComplex number.

◆ cuCsubSf() [1/2]

__device__ __inline__ cuFloatComplex cuCsubSf ( cuFloatComplex  a,
float  b 
)

Subtract scalar float from complex number.

Returns
res cuFloatComplex number.

◆ cuCsubSf() [2/2]

__device__ __inline__ cuFloatComplex cuCsubSf ( float  a,
cuFloatComplex  b 
)

Add complex number to scalar float.

Returns
res cuFloatComplex number.

◆ diff() [1/2]

__device__ __inline__ void diff ( cuFloatComplex(&)  cv1[3],
cuFloatComplex(&)  cv2[3],
cuFloatComplex(&)  out[3] 
)

Component-wise vector difference.

Subtract two complex valued vectors of size 3, element-wise.

Parameters
cv1Array of 3 complex float.
cv2Array of 3 complex float.
outArray of 3 complex float.

◆ diff() [2/2]

__device__ __inline__ void diff ( float(&)  v1[3],
float(&)  v2[3],
float(&)  out[3] 
)

Component-wise vector difference.

Subtract two real valued vectors of size 3, element-wise.

Parameters
v1Array of 3 float.
v2Array of 3 float.
outArray of 3 float.

◆ dot() [1/4]

__device__ __inline__ void dot ( cuFloatComplex(&)  cv1[3],
cuFloatComplex(&)  cv2[3],
cuFloatComplex &  out 
)

Dot product.

Take the dot (inner) product of two complex valued float arrays of size 3.

Parameters
cv1Array of 3 complex float.
cv2Array of 3 complex float.
outScalar complex float.

◆ dot() [2/4]

__device__ __inline__ void dot ( cuFloatComplex(&)  cv1[3],
float(&)  v2[3],
cuFloatComplex &  out 
)

Dot product.

Take the dot (inner) product of one complex valued and one real valued float array of size 3.

Parameters
cv1Array of 3 complex float.
v2Array of 3 float.
outScalar complex float.

◆ dot() [3/4]

__device__ __inline__ void dot ( float(&)  v1[3],
cuFloatComplex(&)  cv2[3],
cuFloatComplex &  out 
)

Dot product.

Take the dot (inner) product of one real valued and one complex valued float array of size 3.

Parameters
v1Array of 3 float.
cv2Array of 3 complex float.
outScalar complex float.

◆ dot() [4/4]

__device__ __inline__ void dot ( float(&)  v1[3],
float(&)  v2[3],
float &  out 
)

Dot product.

Take the dot (inner) product of two real valued arrays of size 3.

Parameters
v1Array of 3 float.
v2Array of 3 float.
outScalar float.

◆ dyad()

__device__ __inline__ void dyad ( float(&)  v1[3],
float(&)  v2[3],
float(&)  out[3][3] 
)

Dyadic product.

Calculate dyadic product between two real valued float vectors of size 3.

Parameters
v1Array of 3 float.
v2Array of 3 float.
outArray of 3 float, nested inside array of size 3.

◆ ext() [1/4]

__device__ __inline__ void ext ( cuFloatComplex(&)  cv1[3],
cuFloatComplex(&)  cv2[3],
cuFloatComplex(&)  out[3] 
)

Cross product.

Take the cross (outer) product of two complex valued float arrays of size 3.

Parameters
cv1Array of 3 complex float.
cv2Array of 3 complex float.
outArray of 3 complex float.

◆ ext() [2/4]

__device__ __inline__ void ext ( cuFloatComplex(&)  cv1[3],
float(&)  v2[3],
cuFloatComplex(&)  out[3] 
)

Cross product.

Take the cross (outer) product of one complex valued and one real valued float array of size 3.

Parameters
cv1Array of 3 complex float.
v2Array of 3 float.
outArray of 3 complex float.

◆ ext() [3/4]

__device__ __inline__ void ext ( float(&)  v1[3],
cuFloatComplex(&)  cv2[3],
cuFloatComplex(&)  out[3] 
)

Cross product.

Take the cross (outer) product of one real valued and one complex valued float array of size 3.

Parameters
v1Array of 3 float.
cv2Array of 3 complex float.
outArray of 3 complex float.

◆ ext() [4/4]

__device__ __inline__ void ext ( float(&)  v1[3],
float(&)  v2[3],
float(&)  out[3] 
)

Cross product.

Take the cross (outer) product of two real valued float arrays of size 3.

Parameters
v1Array of 3 float.
v2Array of 3 float.
outArray of 3 float.

◆ invmatVec4()

__device__ __inline__ void invmatVec4 ( float(&)  mat[16],
float(&)  cv1[3],
float(&)  out[3],
bool  vec = false 
)

Matrix-vector multiplication.

Multiply a vector by the inverse of a matrix.

Parameters
cv1Array of 3 float.
outArray of 3 float.
vecWhether to rotate as a vector or as a point.

◆ matDiff()

__device__ __inline__ void matDiff ( float(&)  m1[3][3],
float(&)  m2[3][3],
float(&)  out[3][3] 
)

Matrix difference, element wise.

Subtract two 3x3 matrices, element wise.

Parameters
m1Array of 3 float, nested inside array of size 3.
m2Array of 3 float, nested inside array of size 3.
outArray of 3 float, nested inside array of size 3.

◆ matVec() [1/2]

__device__ __inline__ void matVec ( float(&)  m1[3][3],
cuFloatComplex(&)  cv1[3],
cuFloatComplex(&)  out[3] 
)

Matrix-vector product.

Multiply a real valued 3x3 matrix and a complex valued size 3 vector to generate a new complex valued size 3 vector.

Parameters
m1Array of 3 float, nested inside array of size 3.
cv1Array of 3 complex float.
outArray of 3 complex float.

◆ matVec() [2/2]

__device__ __inline__ void matVec ( float(&)  m1[3][3],
float(&)  v1[3],
float(&)  out[3] 
)

Matrix-vector product.

Multiply a real valued 3x3 matrix and a real valued size 3 vector to generate a new real valued size 3 vector.

Parameters
m1Array of 3 float, nested inside array of size 3.
v1Array of 3 float.
outArray of 3 float.

◆ matVec4()

__device__ __inline__ void matVec4 ( float(&)  mat[16],
float(&)  cv1[3],
float(&)  out[3],
bool  vec = false 
)

Matrix-vector multiplication.

Uses mat from constant memory.

Parameters
cv1Array of 3 float.
outArray of 3 float.
vecWhether to rotate as a vector or as a point.

◆ normalize()

__device__ __inline__ void normalize ( float(&)  v[3],
float(&)  out[3] 
)

Normalize vector.

Normalize real valued vector of size 3.

Parameters
vArray of 3 float.
outArray of 3 float.

◆ s_mult() [1/4]

__device__ __inline__ void s_mult ( cuFloatComplex(&)  cv[3],
const float &  s,
cuFloatComplex(&)  out[3] 
)

Scalar multiplication.

Multiply complex valued vector of size 3 by real scalar, element-wise.

Parameters
cvArray of 3 complex float.
sScalar float.
outArray of 3 complex float.

◆ s_mult() [2/4]

__device__ __inline__ void s_mult ( cuFloatComplex(&)  cv[3],
cuFloatComplex &  cs,
cuFloatComplex(&)  out[3] 
)

Scalar multiplication.

Multiply complex valued vector of size 3 by complex scalar, element-wise.

Parameters
cvArray of 3 complex float.
csScalar complex float.
outArray of 3 complex float.

◆ s_mult() [3/4]

__device__ __inline__ void s_mult ( float(&)  v[3],
cuFloatComplex &  cs,
cuFloatComplex(&)  out[3] 
)

Scalar multiplication.

Multiply real valued vector of size 3 by complex scalar, element-wise.

Parameters
vArray of 3 float.
csScalar complex float.
outArray of 3 complex float.

◆ s_mult() [4/4]

__device__ __inline__ void s_mult ( float(&)  v[3],
float &  s,
float(&)  out[3] 
)

Scalar multiplication.

Multiply real valued vector of size 3 by real scalar, element-wise.

Parameters
vArray of 3 float.
sScalar float.
outArray of 3 float.

◆ snell() [1/2]

__device__ __inline__ void snell ( cuFloatComplex(&)  cvin[3],
float(&)  normal[3],
cuFloatComplex(&)  out[3] 
)

Snell's law reflection.

Calculate reflected direction vector from incoming direction and normal vector.

Parameters
cvinArray of 3 complex float, incoming direction vector.
normalArray of 3 float, normal vector of surface.
outArray of 3 complex float.

◆ snell() [2/2]

__device__ __inline__ void snell ( float(&)  vin[3],
float(&)  normal[3],
float(&)  out[3] 
)

Snell's law reflection.

Calculate reflected direction vector from incoming direction and normal vector.

Parameters
vinArray of 3 float, incoming direction vector.
normalArray of 3 float, normal vector of surface.
outArray of 3 float.

◆ snell_t()

__device__ __inline__ void snell_t ( float(&)  vin[3],
float(&)  normal[3],
float  mu,
float(&)  out[3] 
)

Snell's law refraction.

Calculate refracted direction vector from incoming direction and normal vector.

Parameters
vinArray of 3 double/float, incoming direction vector.
normalArray of 3 double/float, normal vector of surface.
muRatio of n1 to n2.
outArray of 3 double/float.