[NMR Home] [NMR Software Home] [libCMatrix Home] [Download] [Dependencies] [Design] [Usage] [FAQ] [Contact]

CMatrix

A templatised C++ class providing mathematical matrix and volume usage


These pages describe a template C++ matrix library class, cmatrix, that provides a straightforward API for creating and using matrices and higher dimensional volumes (up to five dimensions). The library not only provides its own internal rich set of matrix manipulation methods, but it can also interface with the GNU Scientific Library. For increased speed, it is also Intel Math Kernel Library aware.

cmatrix offers a template class interface that is designed to provide a type-safe and bounds-aware mechanism for conceptualizing mathematical matrix operations as well as acting as a numerical-based "container" class. This cmatrix class was originally based on an example class published by Bruce Eckel (see here) and significantly expanded on by the author. By using a simple reference-counting mechanism, it is both memory and speed efficient. Moreover, it is bounds-safe - removing a commonplace source of errors and bugs when using arrays in C / C++.

Internally, the data component of the class is quite simple. It merely comprises a doubly indirected pointer to the data of the matrix, as well as information on the size and dimensionality of the matrix (rows and columns). Furthermore, each instance of a matrix maintains a reference counter to minimize the repitition of multiple instances of the same core data.

Conventional C / C++ provides no native "matrix" type, and hence a programmer needs to either use a third-party matrix class library, or develop his/her own. Most third party matrix classes I examined seemed to either be too complex for simple "quick and dirty" use, or, alternatively, far too primitive to really be of any value. This class was designed to strike a midpoint between richness of API and ease of use. No specific compilers or setup is required, merely the header file and the compiled library itself.

The cmatrix API is divided into several sections:

  • type-definition enumerations.

    These define several enumerations for programmer readability, including type of matrix (vector - row or column, square matrix), sort preferences, normalization preferences, etc.

  • constructor / destructor / initializations.

    Several different constructors and initializers are defined. Matrices can be constructed from saved files, from blocks of unstructured memory, with default (or specified) uniform values, with random values, with chosen values randomly distributed over the matrix data, with values quantized between specified limits, etc.

  • access.

    Matrix data can be accessed in "individual" row column addressing, or in whole row or whole column forms.

  • output.

    Matrix contents can be output in a variety of forms (variable precision or integer), offset with leading tabs, and to a variety of "streams" - console based or file based.

  • informational routines.

    Several methods exist to provide information about matrix size and type. These include row or column vector types, size of matrices, compatability between matrices, etc.

  • structural manipulation routines.

    Various manipulation methods can be used to remove / insert / replace / sort / etc. the contents of matrices. These can be applied on a row-specific, column-specific, or sub-matrix-specific manner.

  • find.

    Several search and "find and replace" methods are available.

  • mathematical operations.

    Indeed, this constitutes one of the main reasons for this class. Some simple statistical methods are provided (max., min, mean, average, sum, standard deviation), as well as more traditional matrix-based operations, including determinants, and operator overloads (+ - / * etc.).

Site Navigation

  • Download.

    See here for source and binary downloads of cppmatrixt.

  • Dependencies.

    Several external dependencies are required by the software (including the Intel Math Kernel Libraries, and the GNU Scientific Library). This page offers links to these dependencies, as well as some instructions as to setting up a basic environment for running the software.

  • Design.

    This page provides a conceptual overview of the design and major components of cppmatrixt.

  • Usage.

    Usage instructions and example code snippets are available here.

  • FAQ.

    A simple FAQ.

  • Contact.

    How to contact me.

News

August 2004

Initial deployment of these pages.