The system library for Quasar: contains functions that are not built-in, but that are very often used.
If the function you are looking for, cannot be found in system.q (or any of the other .q files located in the Library directory), please feel free to implement this function, and send a copy of the code to bart.g@telin.u gent.be. This way, I can make sure that the function is distributed automatically in later versions of Quasar. oossens
system.q | The system library for Quasar: contains functions that are not built-in, but that are very often used. |
type-checking functions | |
isreal | returns 1 if x is real-valued, 0 otherwise |
iscomplex | returns 1 if x is complex-valued, 0 otherwise |
isscalar | returns 1 if x is scalar, 0 otherwise |
isvector | returns 1 if x is a vector (max. |
ismatrix | returns 1 if x is a matrix (max. |
iscube | returns 1 if x is a cube (max. |
isfunction | returns 1 if x is a function, 0 otherwise |
isstring | returns 1 if x is a string, 0 otherwise |
isobject | returns 1 if x is an object, 0 otherwise |
iskernel | returns 1 if x is a kernel function, 0 otherwise |
iscell | returns 1 if x is a cell matrix, 0 otherwise |
mathematical functions | |
nextpow2 | returns the next integer power of two |
prevpow2 | returns the previous integer power of two |
std | computes the standard deviation of all elements in a matrix |
lerp | performs linear interpolation between a and b (with weight d) |
conversion functions | |
num2str | converts a number to string |
str2num | converts the string to a numerical value |
general matrix functions | |
isempty | returns 1 if the number of elements of x is 0 and 0 otherwise. |
ndims | returns the number of dimensions of x |
flipup | flips a two dimensional matrix upside-down (vertically) |
fliplr | flips a two dimensional matrix horizontally |
any | returns 1 if at least one element of x is non-zero, otherwise 0. |
all | returns 1 if all elements of x are non-zero, otherwise 0. |
diag | Creates a diagonal matrix from a one dimensional vector. |
diag | Creates a diagonal matrix from a one dimension |
diag | Extracts the diagonal elements of a square real-valued matrix |
diag | Extracts the diagonal elements of a square complex-valued matrix |
trace | Computes the trace of a matrix (i.e. |
circshift | Applies circular (periodic) shifting of a given vector, according to the relationship y[p] = x[p+d] |
circshift | Applies circular (periodic) shifting of a given matrix, according to the relationship y[p] = x[p+d] |
circshift | Applies circular (periodic) shifting of a given cube, according to the relationship y[p] = x[p+d] |
circshift | Applies circular (periodic) shifting of a given complex-valued vector, according to the relationship y[p] = x[p+d] |
circshift | Applies circular (periodic) shifting of a given complex-valued matrix, according to the relationship y[p] = x[p+d] |
circshift | Applies circular (periodic) shifting of a given complex-valued cube, according to the relationship y[p] = x[p+d] |
fftshift1 | Moves the DC components of a 1D discrete Fourier transform (DFT) to the center of the data. |
ifftshift1 | The inverse operation of fftshift1 |
fftshift2 | Moves the DC components of a 2D discrete Fourier transform (DFT) to the center of the data |
ifftshift2 | The inverse operation of fftshift2 |
fftshift3 | Moves the DC components of a 3D discrete Fourier transform (DFT) to the center of the data |
ifftshift3 | The inverse operation of fftshift3 |
binsearch1d | A 1D binary search algorithm: given a sorted vector x0, find the index of the element that is closest to ‘value’. |
interp1_function | Get a device function that can be used for one-dimensional interpolation |
interp1 | Performs one-dimensional interpolation |
interp2_function | Get a device function that can be used for two-dimensional interpolation |
interp2 | Performs two-dimensional interpolation |
invert_function | Computes the inverse of a function |
meshgrid | Generate matrices with coordinates for a 2D Cartesian grid |
meshgrid | Generate matrices with coordinates for a 3D Cartesian grid |
swap | Swaps the values of two variables |
dotprod | Computes the dot product between two vectors |
isnan | Check which elements of the matrix are NaN The isnan function is available as a built-in function inside kernel or device functions. |
isinf | Check which elements of the matrix are infinite The isnan function is available as a built-in function inside kernel or device functions. |
isfinite | Check which elements of the matrix are finite The isnan function is available as a built-in function inside kernel or device functions. |
sort | inplace sort along the rows (currently: ascending sort). |
sort2 | a non-inplace sort along the rows that also returns the indices (ascending sort) Internally uses a parallel bitsort algorithm. |
median | compute the median along the rows... |
cat | Horizontal concatenation function: works for matrix, complex matrices and cell matrices |
vertcat | Vertical concatenation function: works for matrix, complex matrices and cell matrices |
find | Finds the location of the non-zero elements of x. |
sinc | The normalized sinc function, defined as sin(pi*x)/(pi*x) |
herm_transpose | Hermitian transpose of a matrix |
kron | Computes the Kronecker product of two matrices |
periodize | Computes x modulo a: but in a sense that the result is in the range [0, a[, even for negative numbers |
mirror_ext | Performs mirror reflection of the input coordinate |
Moves the DC components of a 1D discrete Fourier transform (DFT) to the center of the data. For higher dimensional data - it is presumed that the FFT data is stored in the last dimension
function y : cube = fftshift1(x : cube) function y : ccube = fftshift1(x : ccube)
x | the input data |
Get a device function that can be used for one-dimensional interpolation
function fn : [__device__ scalar->scalar] = interp1_function( x0 : vec'unchecked, y0 : vec'unchecked, interpolation : string = "linear", uniform = 1)
x0 | x-values of the input vector |
y0 | y-values of the input vector interpolation : the interpolation method to use |
The function returns a device function that can subsequently be used in other kernel functions. Function closures are used to store the data [x0, y0] Note that x0 does not have to be uniformly-spaced. In case of other spacings, a binary search algorithm is employed for the look-up.
Performs one-dimensional interpolation
function y = interp1(x0 : vec,y0 : vec,x,interpolation="linear",uniform=1)
x0 | x-values of the input vector |
y0 | y-values of the input vector |
x | the x-values to interpolate interpolation : the interpolation method to use |
Get a device function that can be used for two-dimensional interpolation
function fn : [__device__ vec2->scalar] = interp2_function(
x0 : vec’unchecked, y0 : vec’unchecked, z0 : mat’unchecked, interpolation : string = “linear”)
x0 | x-values of the input vector (along the 2nd dimension) |
y0 | y-values of the input vector (along the 1st dimension) interpolation : the interpolation method to use |
The function returns a device function that can subsequently be used in other kernel functions. Function closures are used to store the data [x0, y0]
Performs two-dimensional interpolation
function z : cube = interp2(x0:vec,y0:vec,z0:mat,x:cube,y:cube,interpolation="linear")
x0 | vector of x-values |
y0 | vector of y-values |
z0 | matrix with z-values - the points (x0,y0,z0) define a surface |
x | the x-values to interpolate |
y | the y-values to interpolate interpolation : the interpolation method to use |
Generate matrices with coordinates for a 2D Cartesian grid
function [x : mat, y : mat] = meshgrid(range_x : vec, range_y : vec)
Note: the matrix indexing is as follows: Y x X
range_x | values for the x-axis of the Cartesian grid |
range_y | values for the y-axis of the Cartesian grid |
x | output matrix with x-coordinates |
y | output matrix with y-coordinates |
Generate matrices with coordinates for a 3D Cartesian grid
function [x : cube, y : cube, z : cube] = meshgrid( range_x : vec, range_y : vec, range_z : vec)
range_x | values for the x-axis of the Cartesian grid |
range_y | values for the y-axis of the Cartesian grid |
range_z | values for the z-axis of the Cartesian grid |
x | output matrix with x-coordinates |
y | output matrix with y-coordinates |
z | output matrix with z-coordinates |
Finds the location of the non-zero elements of x. The result is a list of positions [[x0, y0, z0], [x1, y1, z1], ...].
function y : mat = find(x : cube, mode : string = "all", dim : int = 0)
x | a data cube |
y | a matrix with coordinates of the positions of size Nx3 where N is the number of elements of x != 1, i.e. sum(x!=1) |
mode | the search mode |