Next Article in Journal
Hedging Crop Yields Against Weather Uncertainties—A Weather Derivative Perspective
Previous Article in Journal
On the Modeling of Five-Layer Thin Prismatic Bodies
Article Menu

Export Article

Open AccessFeature PaperArticle

Practical Sparse Matrices in C++ with Hybrid Storage and Template-Based Expression Optimisation

1,2,3,* and 3,4
Data61/CSIRO, Brisbane, QLD 4006, Australia
School of Information Technology & Electrical Engineering, University of Queensland, Brisbane, QLD 4072, Australia
Arroyo Consortium, San Francisco, CA, USA
RelationalAI, Atlanta, GA 30318, USA
Author to whom correspondence should be addressed.
This paper is an extended version of our paper published in International Congress on Mathematical Software 2018.
Math. Comput. Appl. 2019, 24(3), 70;
Received: 2 June 2019 / Revised: 9 July 2019 / Accepted: 17 July 2019 / Published: 19 July 2019
PDF [402 KB, uploaded 19 July 2019]


Despite the importance of sparse matrices in numerous fields of science, software implementations remain difficult to use for non-expert users, generally requiring the understanding of the underlying details of the chosen sparse matrix storage format. In addition, to achieve good performance, several formats may need to be used in one program, requiring explicit selection and conversion between the formats. This can be both tedious and error-prone, especially for non-expert users. Motivated by these issues, we present a user-friendly and open-source sparse matrix class for the C++ language, with a high-level application programming interface deliberately similar to the widely-used MATLAB language. This facilitates prototyping directly in C++ and aids the conversion of research code into production environments. The class internally uses two main approaches to achieve efficient execution: (i) a hybrid storage framework, which automatically and seamlessly switches between three underlying storage formats (compressed sparse column, red-black tree, coordinate list) depending on which format is best suited and/or available for specific operations, and (ii) a template-based meta-programming framework to automatically detect and optimise the execution of common expression patterns. Empirical evaluations on large sparse matrices with various densities of non-zero elements demonstrate the advantages of the hybrid storage framework and the expression optimisation mechanism. View Full-Text
Keywords: mathematical software; C++ language; sparse matrix; numerical linear algebra mathematical software; C++ language; sparse matrix; numerical linear algebra

Figure 1

This is an open access article distributed under the Creative Commons Attribution License which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited (CC BY 4.0).

Share & Cite This Article

MDPI and ACS Style

Sanderson, C.; Curtin, R. Practical Sparse Matrices in C++ with Hybrid Storage and Template-Based Expression Optimisation. Math. Comput. Appl. 2019, 24, 70.

Show more citation formats Show less citations formats

Note that from the first issue of 2016, MDPI journals use article numbers instead of page numbers. See further details here.

Article Metrics

Article Access Statistics



[Return to top]
Math. Comput. Appl. EISSN 2297-8747 Published by MDPI AG, Basel, Switzerland RSS E-Mail Table of Contents Alert
Back to Top