1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) XXXX-2008 - INRIA
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
18 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
19 xml:lang="en" xml:id="sparse">
21 <refname>sparse</refname>
22 <refpurpose>sparse matrix definition</refpurpose>
29 sp = sparse(ij, v, mn)
33 <title>Arguments</title>
38 <para>real or complex or boolean full (or sparse) matrix</para>
44 <para>two columns integer matrix (indices of non-zeros entries)</para>
56 <para>integer vector with two entries (row-dimension, column-dimension)</para>
62 <para>sparse matrix</para>
68 <title>Description</title>
70 <literal>sparse</literal> is used to build a sparse matrix. Only non-zero entries
74 <literal>sp = sparse(X)</literal> converts a full matrix to sparse form by
75 squeezing out any zero elements. (If <literal>X</literal> is already sparse
76 <literal>sp</literal> is <literal>X</literal>).
79 <literal>sp=sparse(ij,v [,mn])</literal> builds an <literal>mn(1)</literal>-by-<literal>mn(2)</literal>
80 sparse matrix with <literal>sp(ij(k,1),ij(k,2))=v(k)</literal>.
81 <literal>ij</literal> and <literal>v</literal> must have the same column dimension.
82 If optional <literal>mn</literal> parameter is not given the <literal>sp</literal>
83 matrix dimensions are the max value of <literal>ij(:,1)</literal> and <literal>ij(:,2)</literal>
84 respectively. If many values are given for same position, theses values are summed.
87 Operations (concatenation, addition, etc,) with sparse matrices are
88 made using the same syntax as for full matrices.
91 Elementary functions are also available (<literal>abs,maxi,sum,diag,...</literal>)
95 Mixed operations (full-sparse) are allowed. Results are full or sparse
96 depending on the operations.
99 Note : Any operation involving dense matrices of the same size, either as argument (e.g. <literal>sp=sparse(d)</literal>)
100 or as result (e.g. <literal>d= sp + 1.</literal>) is provided for convenience purposes but should of course be avoided.
101 Furthermore, random access to elements (<literal>sp(r,c)</literal>), especially for insertions, is not efficient, so
102 any performance-constrained access should be done in batches with <link linkend="spget">spget</link> for read access
103 and the three arguments constructor <literal>sp=sparse(ij, v, mn)</literal> for write access.
107 <title>Examples</title>
108 <programlisting role="example"><![CDATA[
109 sp = sparse([1,2;4,5;3,10],[1,2,3])
113 abs(x) - full(abs(sparse(x)))
115 // sparse constructor taking a single dense matrix
116 // removes the zeros.
117 dense = [0., 1., 0., 0., 0.,
120 0., 0., 0., 0., -0.5];
123 // complex matrices are also supported
124 sp = sparse(dense*(1+2*%i))
126 // for boolean matrices, the boolean sparse matrix
127 // only stores true values (and removes false values).
128 dense = [%F, %F, %T, %F, %F
135 <refsection role="see also">
136 <title>See also</title>
137 <simplelist type="inline">
139 <link linkend="full">full</link>
142 <link linkend="spget">spget</link>
145 <link linkend="sprand">sprand</link>
148 <link linkend="speye">speye</link>
151 <link linkend="diag">diag</link>
154 <link linkend="toeplitz">toeplitz</link>