PARP Research Group Universidad de Murcia

Interoperability with the GSL library

QVision applications will automatically link to the include and binary files for the GSL library.

Converting QVision objects from and to GSL library types

The QVision includes functionality to convert QVMatrix and QVVector objects from and to GSL matrices and vectors objects. To convert a QVMatrix object from and to a GSL matrix object, the developer can use the QVMatrix constructor and conversion operators:

// First create a GSL matrix
gsl_matrix *gslMatrix = gsl_matrix_alloc(rows, cols);

// Next, init the contents of the GSL matrix.

// Convert the GSL matrix to a QVision matrix
QVMatrix qvMatrix = gslMatrix;

// Do things with the QVision matrix

// Convert back the QVision matrix to a new Octave matrix
gsl_matrix *gslMatrix2 = qvMatrix;

// Free GSL matrices

A similar procedure can be used to convert QVVector objects from and to the GSL vector datatype:

// First create a GSL matrix
gsl_vector *gslVector = gsl_vector_alloc(size);

// Next, init the contents of the GSL vector.

// Convert the GSL vector to a QVision vector
QVVector qvVector = gslVector;

// Do things with the QVision vector

// Convert back the QVision vector to a new GSL vector
gsl_matrix *gslVector2 = qvVector;

// Free GSL matrices

Interoperation between QVision and GSL functions

The following is an example of using the GSL functionality for SVD decomposition, using the data from a QVision matrix, and storing the results on QVision matrices:

// Create a QVision matrix.
QVMatrix M;

// Init contents of the M matrix.
[ ... ]

// Get the second dimension of 'M'.
const int dim = M.getCols();

// Create the input vectors and matrices for the SVD method of the GSL.
gsl_matrix *u = M;
gsl_vector *s = gsl_vector_alloc (dim);
gsl_matrix *v = gsl_matrix_alloc (dim, dim);
gsl_vector *work = gsl_vector_alloc (dim);
gsl_matrix *X = gsl_matrix_alloc (dim,dim);

// Call the SVD method of the GSL
gsl_linalg_SV_decomp_mod(u, X, v, s, work);

// Create QVision matrices, containing the results of the SVD.
const QVMatrix  U = u,
                V = v,
                S = QVMatrix::diagonal(s);

// Free GSL matrices and vectors.

QVision framework. PARP research group. Copyright © 2007, 2008, 2009, 2010, 2011.