Skip to main content

A User-Friendly Hybrid Sparse Matrix Class in C++

  • Conference paper
  • First Online:
Mathematical Software – ICMS 2018 (ICMS 2018)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 10931))

Included in the following conference series:

Abstract

When implementing functionality which requires sparse matrices, there are numerous storage formats to choose from, each with advantages and disadvantages. 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 this issue, we present a user-friendly sparse matrix class for the C++ language, with a high-level application programming interface deliberately similar to the widely used MATLAB language. 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, coordinate list, Red-Black tree) depending on which format is best suited for specific operations, and (ii) template-based meta-programming to automatically detect and optimise execution of common expression patterns. To facilitate relatively quick conversion of research code into production environments, the class and its associated functions provide a suite of essential sparse linear algebra functionality (eg., arithmetic operations, submatrix manipulation) as well as high-level functions for sparse eigendecompositions and linear equation solvers. The latter are achieved by providing easy-to-use abstractions of the low-level ARPACK and SuperLU libraries. The source code is open and provided under the permissive Apache 2.0 license, allowing unencumbered use in commercial products.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Anderson, E., Bai, Z., Bischof, C., Blackford, S., Demmel, J., Dongarra, J., Du Croz, J., Greenbaum, A., Hammarling, S., et al.: LAPACK Users’ Guide. SIAM, Philadelphia (1999)

    Book  Google Scholar 

  2. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. MIT Press, Cambridge (2009)

    MATH  Google Scholar 

  3. Curtin, R., Cline, J., Slagle, N., March, W., Ram, P., Mehta, N., Gray, A.: MLPACK: a scalable C++ machine learning library. J. Mach. Learn. Res. 14, 801–805 (2013)

    MathSciNet  MATH  Google Scholar 

  4. Duff, I.S., Erisman, A.M., Reid, J.K.: Direct Methods for Sparse Matrices, 2nd edn. Oxford University Press, Oxford (2017)

    Book  Google Scholar 

  5. Eaton, J.W., Bateman, D., Hauberg, S., Wehbring, R.: GNU Octave 4.2 Reference Manual. Samurai Media Limited (2017)

    Google Scholar 

  6. Eddelbuettel, D., Sanderson, C.: RcppArmadillo: accelerating R with high-performance C++ linear algebra. Comput. Stat. Data Anal. 71, 1054–1063 (2014)

    Article  MathSciNet  Google Scholar 

  7. Lehoucq, R.B., Sorensen, D.C., Yang, C.: ARPACK Users’ Guide: Solution of Large-Scale Eigenvalue Problems with Implicitly Restarted Arnoldi Methods. SIAM, Philadelphia (1998)

    Book  Google Scholar 

  8. Li, X.S.: An overview of SuperLU: algorithms, implementation, and user interface. ACM Trans. Mathe. Softw. (TOMS) 31(3), 302–325 (2005)

    Article  MathSciNet  Google Scholar 

  9. MathWorks: MATLAB Documentation - Accessing Sparse Matrices (2018). https://www.mathworks.com/help/matlab/math/accessing-sparse-matrices.html

  10. Nunez-Iglesias, J., van der Walt, S., Dashnow, H.: Elegant SciPy: The Art of Scientific Python. O’Reilly Media (2017)

    Google Scholar 

  11. Rosen, L.: Open Source Licensing. Prentice Hall, Upper Saddle River (2004)

    Google Scholar 

  12. Saad, Y.: SPARSKIT: A basic tool kit for sparse matrix computations. Technical report, NASA-CR-185876, NASA Ames Research Center (1990)

    Google Scholar 

  13. Sanderson, C., Curtin, R.: Armadillo: a template-based C++ library for linear algebra. J. Open Source Softw. 1, 26 (2016)

    Article  Google Scholar 

  14. Stroustrup, B.: The C++ Programming Language, 4th edn. Addison-Wesley, Boston (2013)

    MATH  Google Scholar 

  15. Vandevoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide, 2nd edn. Addison-Wesley, Boston (2017)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Conrad Sanderson .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Sanderson, C., Curtin, R. (2018). A User-Friendly Hybrid Sparse Matrix Class in C++. In: Davenport, J., Kauers, M., Labahn, G., Urban, J. (eds) Mathematical Software – ICMS 2018. ICMS 2018. Lecture Notes in Computer Science(), vol 10931. Springer, Cham. https://doi.org/10.1007/978-3-319-96418-8_50

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-96418-8_50

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-96417-1

  • Online ISBN: 978-3-319-96418-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics