 Sparse Matrices and Vectors - Maple Help

Home : Support : Online Help : System : Information : Updates : Maple 17 : Sparse Matrices and Vectors

Sparse Matrices and Vectors

Enhancements have been made in Maple 17 for the performance of stacking and augmenting sparse floating-point, hardware datatype Matrices and Vectors. Computing linear combinations of pairs of sparse floating-point, hardware datatype Matrices using the LinearAlgebra:-MatrixAdd command has also been improved.

In the examples below, the Matrix and Vector constructors are used for stacking or augmentation (concatenation).

Benchmarks computed in 64-bit Maple 17 for Linux on an Intel Core i5 CPU 760 @ 2.80GHz. Sparse Vector concatenation

In Maple 16, the concatenation of Vector V with itself three times would take approximately 28 seconds and would result in an output Vector with full rectangular storage. The allocated memory would increase by 1.27GiB.

In Maple 17, it takes less than 0.2 seconds and produces a Vector with sparse storage. Memory allocation increases by 30.5MiB.

Example

 > $\mathrm{restart}:$
 > $\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$
 > $V:=\mathrm{RandomVector}\left({10}^{7},\mathrm{generator}=0.0..1.0,\mathrm{density}=0.05,\mathrm{storage}=\mathrm{sparse},\mathrm{datatype}={\mathrm{float}}_{8}\right)$
 ${V}{:=}\left[\begin{array}{c}{\mathrm{1 .. 10000000}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (1.1)
 > $\mathrm{rtable_num_elems}\left(V,\mathrm{NonZeroStored}\right)$
 ${500366}$ (1.2)
 > $\mathrm{biggerV}:=\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{Vector}\left(\left[V,V,V,V\right]\right)\right)$
 memory used=76.37MiB, alloc change=30.54MiB, cpu time=100.00ms, real time=121.00ms
 ${\mathrm{biggerV}}{:=}\left[\begin{array}{c}{\mathrm{1 .. 40000000}}{{\mathrm{Vector}}}_{{\mathrm{column}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (1.3)
 > $\mathrm{rtable_num_elems}\left(\mathrm{biggerV},\mathrm{NonZeroStored}\right)$
 ${2001464}$ (1.4) Sparse Matrix concatenation

In Maple 16, the concatenation of Matrix M with itself as performed below would take approximately 20 seconds and would result in an output Matrix with full rectangular storage.

In Maple 17, it takes less than 0.1 seconds and produces a Matrix with sparse storage. Memory allocation increases by 48MiB.

Example

 > $\mathrm{restart}:$$\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$$M:=\mathrm{RandomMatrix}\left({10}^{3},{10}^{3},\mathrm{generator}=0.0..1.0,\mathrm{density}=0.01,\mathrm{storage}=\mathrm{sparse},\mathrm{datatype}={\mathrm{float}}_{8}\right)$
 ${M}{:=}\left[\begin{array}{c}{\mathrm{1000 x 1000}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (2.1)
 > $\mathrm{rtable_num_elems}\left(M,\mathrm{NonZeroStored}\right)$
 ${10053}$ (2.2)
 > $\mathrm{biggerM}:=\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{Matrix}\left(\left[M,M\right]\right)\right)$
 memory used=0.76MiB, alloc change=48.00MiB, cpu time=30.00ms, real time=55.00ms
 ${\mathrm{biggerM}}{:=}\left[\begin{array}{c}{\mathrm{1000 x 2000}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (2.3)
 > $\mathrm{rtable_num_elems}\left(\mathrm{biggerM},\mathrm{NonZeroStored}\right)$
 ${20106}$ (2.4) Simple linear combinations of sparse Matrices

In Maple 16, the following command would take 3 minutes and allocated memory would increase by 400MiB.

In Maple 17, it takes less than 1 second and allocated memory increases by 76MiB.

Example

 > $\mathrm{restart}:$$\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$$M:=\mathrm{RandomMatrix}\left({10}^{4},{10}^{4},\mathrm{generator}=0.0..1.0,\mathrm{density}=0.01,\mathrm{storage}=\mathrm{sparse},\mathrm{datatype}={\mathrm{float}}_{8}\right);$$\mathrm{CodeTools}:-\mathrm{Usage}\left(\mathrm{MatrixAdd}\left(M,M,2,-3.3\right)\right)$
 ${M}{:=}\left[\begin{array}{c}{\mathrm{10000 x 10000}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$
 memory used=76.67MiB, alloc change=76.35MiB, cpu time=360.00ms, real time=417.00ms
 $\left[\begin{array}{c}{\mathrm{10000 x 10000}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{sparse}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3.1) See Also