3136 lines
150 KiB
HTML
3136 lines
150 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs</title>
|
||
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
|
||
<link rel="home" href="index.html" title="igraph Reference Manual">
|
||
<link rel="up" href="index.html" title="igraph Reference Manual">
|
||
<link rel="prev" href="igraph-Foreign.html" title="Chapter 31. Reading and writing graphs from and to files">
|
||
<link rel="next" href="igraph-Nongraph.html" title="Chapter 33. Non-graph related functions">
|
||
<script type="text/javascript" src="toggle.js"></script><link rel="stylesheet" href="style.css" type="text/css">
|
||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
|
||
<link rel="chapter" href="igraph-Introduction.html" title="Chapter 1. Introduction">
|
||
<link rel="chapter" href="igraph-Installation.html" title="Chapter 2. Installation">
|
||
<link rel="chapter" href="igraph-Tutorial.html" title="Chapter 3. Tutorial">
|
||
<link rel="chapter" href="igraph-Basic.html" title="Chapter 4. Basic data types and interface">
|
||
<link rel="chapter" href="igraph-Error.html" title="Chapter 5. Error handling">
|
||
<link rel="chapter" href="igraph-Memory.html" title="Chapter 6. Memory (de)allocation">
|
||
<link rel="chapter" href="igraph-Data-structures.html" title="Chapter 7. Data structure library: vector, matrix, other data types">
|
||
<link rel="chapter" href="igraph-Random.html" title="Chapter 8. Random numbers">
|
||
<link rel="chapter" href="igraph-Iterators.html" title="Chapter 9. Vertex and edge selectors and sequences, iterators">
|
||
<link rel="chapter" href="igraph-Attributes.html" title="Chapter 10. Graph, vertex and edge attributes">
|
||
<link rel="chapter" href="igraph-Generators.html" title="Chapter 11. Deterministic graph generators">
|
||
<link rel="chapter" href="igraph-Games.html" title='Chapter 12. Stochastic graph generators ("games")'>
|
||
<link rel="chapter" href="igraph-Bipartite.html" title="Chapter 13. Bipartite, i.e. two-mode graphs">
|
||
<link rel="chapter" href="igraph-Spatial.html" title="Chapter 14. Spatial graphs">
|
||
<link rel="chapter" href="igraph-Operators.html" title="Chapter 15. Graph operators">
|
||
<link rel="chapter" href="igraph-Visitors.html" title="Chapter 16. Graph visitors">
|
||
<link rel="chapter" href="igraph-Structural.html" title="Chapter 17. Structural properties of graphs">
|
||
<link rel="chapter" href="igraph-Cycles.html" title="Chapter 18. Graph cycles">
|
||
<link rel="chapter" href="igraph-Cliques.html" title="Chapter 19. Cliques and independent vertex sets">
|
||
<link rel="chapter" href="igraph-Motifs.html" title="Chapter 20. Graph motifs, dyad census and triad census">
|
||
<link rel="chapter" href="igraph-Isomorphism.html" title="Chapter 21. Graph isomorphism">
|
||
<link rel="chapter" href="igraph-Coloring.html" title="Chapter 22. Graph coloring">
|
||
<link rel="chapter" href="igraph-Flows.html" title="Chapter 23. Maximum flows, minimum cuts and related measures">
|
||
<link rel="chapter" href="igraph-Separators.html" title="Chapter 24. Vertex separators">
|
||
<link rel="chapter" href="igraph-Community.html" title="Chapter 25. Detecting community structure">
|
||
<link rel="chapter" href="igraph-Graphlets.html" title="Chapter 26. Graphlets">
|
||
<link rel="chapter" href="igraph-HRG.html" title="Chapter 27. Hierarchical random graphs">
|
||
<link rel="chapter" href="igraph-Embedding.html" title="Chapter 28. Embedding of graphs">
|
||
<link rel="chapter" href="igraph-Layout.html" title="Chapter 29. Generating layouts for graph drawing">
|
||
<link rel="chapter" href="igraph-Processes.html" title="Chapter 30. Processes on graphs">
|
||
<link rel="chapter" href="igraph-Foreign.html" title="Chapter 31. Reading and writing graphs from and to files">
|
||
<link rel="chapter" href="igraph-Linalg.html" title="Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs">
|
||
<link rel="chapter" href="igraph-Nongraph.html" title="Chapter 33. Non-graph related functions">
|
||
<link rel="chapter" href="igraph-Advanced.html" title="Chapter 34. Advanced igraph programming">
|
||
<link rel="chapter" href="igraph-Glossary.html" title="Chapter 35. Glossary">
|
||
<link rel="chapter" href="igraph-Licenses.html" title="Chapter 36. Licenses for igraph and this manual">
|
||
<link rel="index" href="ix01.html" title="Index">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<div class="navigation-header mb-4" width="100%" summary="Navigation header"><div class="btn-group">
|
||
<a accesskey="p" class="btn btn-light" href="igraph-Foreign.html"><i class="fa fa-chevron-left"></i>
|
||
Previous
|
||
</a><a accesskey="h" class="btn btn-light" href="index.html"><i class="fa fa-home"></i>
|
||
Home
|
||
</a><a accesskey="n" class="btn btn-light" href="igraph-Nongraph.html"><i class="fa fa-chevron-right"></i>
|
||
Next
|
||
</a>
|
||
</div></div>
|
||
<div class="chapter">
|
||
<div class="titlepage"><div><div><h1 class="title">
|
||
<a name="igraph-Linalg"></a>Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs</h1></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#about-blas">1. BLAS interface in igraph</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#about-lapack">2. LAPACK interface in igraph</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#about-arpack">3. ARPACK interface in igraph</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="about-blas"></a>1. BLAS interface in igraph</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_blas_ddot">1.1. <code class="function">igraph_blas_ddot</code> — Dot product of two vectors.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_blas_dnrm2">1.2. <code class="function">igraph_blas_dnrm2</code> — Euclidean norm of a vector.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_blas_dgemv">1.3. <code class="function">igraph_blas_dgemv</code> — Matrix-vector multiplication using BLAS, vector version.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_blas_dgemm">1.4. <code class="function">igraph_blas_dgemm</code> — Matrix-matrix multiplication using BLAS.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_blas_dgemv_array">1.5. <code class="function">igraph_blas_dgemv_array</code> — Matrix-vector multiplication using BLAS, array version.</a></span></dt>
|
||
</dl></div>
|
||
<p>
|
||
BLAS is a highly optimized library for basic linear algebra operations
|
||
such as vector-vector, matrix-vector and matrix-matrix product.
|
||
Please see <a class="ulink" href="http://www.netlib.org/blas/" target="_top">http://www.netlib.org/blas/</a> for details and a reference
|
||
implementation in Fortran. igraph contains some wrapper functions
|
||
that can be used to call BLAS routines in a somewhat more
|
||
user-friendly way. Not all BLAS routines are included in igraph,
|
||
and even those which are included might not have wrappers;
|
||
the extension of the set of wrapped functions will probably be driven
|
||
by igraph's internal requirements. The wrapper functions usually
|
||
substitute double-precision floating point arrays used by BLAS with
|
||
<span class="type">igraph_vector_t</span> and <span class="type">igraph_matrix_t</span> instances and also
|
||
remove those parameters (such as the number of rows/columns) that
|
||
can be inferred from the passed arguments directly.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_blas_ddot"></a>1.1. <code class="function">igraph_blas_ddot</code> — Dot product of two vectors.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.33.2.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_blas_ddot(const igraph_vector_t *v1, const igraph_vector_t *v2,
|
||
igraph_real_t *res);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>v1</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first vector.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>v2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second vector.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to a real, the result will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(n) where n is the length of the vectors.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.2.3.8.1"></a><p class="title"><b>Example 32.1. File <code class="code">examples/simple/blas.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t m;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> x, y, z;
|
||
igraph_real_t xz, xx;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&x, 3, 1.0, 2.0, 3.0);
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&y, 4, 4.0, 5.0, 6.0, 7.0);
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&z, 3, -1.0, 0.0, 0.5);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&m, 4, 3);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 0) = 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 1) = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 2) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 0) = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 1) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 2) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 0) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 1) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 2) = 5;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 0) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 1) = 5;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 2) = 6;
|
||
|
||
<span class="emphasis"><em>/* Compute 2 m.x + 3 y and store it in y. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_dgemv" title="1.3. igraph_blas_dgemv — Matrix-vector multiplication using BLAS, vector version.">igraph_blas_dgemv</a></strong></span>(<span class="emphasis"><em>/* transpose= */</em></span> 0, <span class="emphasis"><em>/* alpha= */</em></span> 2, &m, &x, <span class="emphasis"><em>/* beta= */</em></span> 3, &y);
|
||
<span class="strong"><strong>igraph_vector_print</strong></span>(&y);
|
||
|
||
<span class="emphasis"><em>/* Compute the squared norm of x, as well as the dor product of x and z. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_ddot" title="1.1. igraph_blas_ddot — Dot product of two vectors.">igraph_blas_ddot</a></strong></span>(&x, &x, &xx);
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_ddot" title="1.1. igraph_blas_ddot — Dot product of two vectors.">igraph_blas_ddot</a></strong></span>(&x, &z, &xz);
|
||
<span class="strong"><strong>printf</strong></span>("x.x = %g, x.z = %g\n", xx, xz);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&m);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&z);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&y);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&x);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_blas_dnrm2"></a>1.2. <code class="function">igraph_blas_dnrm2</code> — Euclidean norm of a vector.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.33.2.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_real_t igraph_blas_dnrm2(const igraph_vector_t *v);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>v</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vector.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Real value, the norm of <em class="parameter"><code>v</code></em>.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(n) where n is the length of the vector.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_blas_dgemv"></a>1.3. <code class="function">igraph_blas_dgemv</code> — Matrix-vector multiplication using BLAS, vector version.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.33.2.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_blas_dgemv(igraph_bool_t transpose, igraph_real_t alpha,
|
||
const igraph_matrix_t *a, const igraph_vector_t *x,
|
||
igraph_real_t beta, igraph_vector_t *y);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function is a somewhat more user-friendly interface to
|
||
the <code class="constant">dgemv</code> function in BLAS. <code class="constant">dgemv</code> performs the operation
|
||
<code class="literal">y = alpha*A*x + beta*y</code>, where <em class="parameter"><code>x</code></em> and <em class="parameter"><code>y</code></em> are vectors
|
||
and <em class="parameter"><code>A</code></em> is an appropriately sized matrix (symmetric or non-symmetric).
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>transpose</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to transpose the matrix <em class="parameter"><code>A</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>alpha</code></em>:</span></p></td>
|
||
<td><p>
|
||
The constant <em class="parameter"><code>alpha</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
The matrix <em class="parameter"><code>A</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>x</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vector <em class="parameter"><code>x</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>beta</code></em>:</span></p></td>
|
||
<td><p>
|
||
The constant <em class="parameter"><code>beta</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>y</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vector <em class="parameter"><code>y</code></em> (which will be modified in-place).
|
||
It must always have the correct length, but its
|
||
elements need not be set when <code class="literal">beta=0</code>.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: O(nk) if the matrix is of size n x k
|
||
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<code class="constant">IGRAPH_EOVERFLOW</code> if the matrix is too large for BLAS,
|
||
<code class="constant">IGRAPH_SUCCESS</code> otherwise.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Linalg.html#igraph_blas_dgemv_array" title="1.5. igraph_blas_dgemv_array — Matrix-vector multiplication using BLAS, array version."><code class="function">igraph_blas_dgemv_array</code></a> if you have arrays instead of
|
||
vectors.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.2.5.10.1"></a><p class="title"><b>Example 32.2. File <code class="code">examples/simple/blas.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t m;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> x, y, z;
|
||
igraph_real_t xz, xx;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&x, 3, 1.0, 2.0, 3.0);
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&y, 4, 4.0, 5.0, 6.0, 7.0);
|
||
<span class="strong"><strong>igraph_vector_init_real</strong></span>(&z, 3, -1.0, 0.0, 0.5);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&m, 4, 3);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 0) = 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 1) = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 0, 2) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 0) = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 1) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 1, 2) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 0) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 1) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 2, 2) = 5;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 0) = 4;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 1) = 5;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(m, 3, 2) = 6;
|
||
|
||
<span class="emphasis"><em>/* Compute 2 m.x + 3 y and store it in y. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_dgemv" title="1.3. igraph_blas_dgemv — Matrix-vector multiplication using BLAS, vector version.">igraph_blas_dgemv</a></strong></span>(<span class="emphasis"><em>/* transpose= */</em></span> 0, <span class="emphasis"><em>/* alpha= */</em></span> 2, &m, &x, <span class="emphasis"><em>/* beta= */</em></span> 3, &y);
|
||
<span class="strong"><strong>igraph_vector_print</strong></span>(&y);
|
||
|
||
<span class="emphasis"><em>/* Compute the squared norm of x, as well as the dor product of x and z. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_ddot" title="1.1. igraph_blas_ddot — Dot product of two vectors.">igraph_blas_ddot</a></strong></span>(&x, &x, &xx);
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_ddot" title="1.1. igraph_blas_ddot — Dot product of two vectors.">igraph_blas_ddot</a></strong></span>(&x, &z, &xz);
|
||
<span class="strong"><strong>printf</strong></span>("x.x = %g, x.z = %g\n", xx, xz);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&m);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&z);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&y);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&x);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_blas_dgemm"></a>1.4. <code class="function">igraph_blas_dgemm</code> — Matrix-matrix multiplication using BLAS.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.33.2.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_blas_dgemm(igraph_bool_t transpose_a, igraph_bool_t transpose_b,
|
||
igraph_real_t alpha, const igraph_matrix_t *a, const igraph_matrix_t *b,
|
||
igraph_real_t beta, igraph_matrix_t *c);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function is a somewhat more user-friendly interface to
|
||
the <code class="constant">dgemm</code> function in BLAS. <code class="constant">dgemm</code> calculates
|
||
alpha*a*b + beta*c, where a, b and c are matrices, of which a and b
|
||
can be transposed.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>transpose_a</code></em>:</span></p></td>
|
||
<td><p>
|
||
whether to transpose the matrix <em class="parameter"><code>a</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>transpose_b</code></em>:</span></p></td>
|
||
<td><p>
|
||
whether to transpose the matrix <em class="parameter"><code>b</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>alpha</code></em>:</span></p></td>
|
||
<td><p>
|
||
the constant <code class="constant">alpha</code>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
the matrix <code class="constant">a</code>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
the matrix <code class="constant">b</code>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>beta</code></em>:</span></p></td>
|
||
<td><p>
|
||
the constant <code class="constant">beta</code>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>c</code></em>:</span></p></td>
|
||
<td><p>
|
||
the matrix <code class="constant">c</code>. The result will also be stored here.
|
||
If beta is zero, c will be resized to fit the result.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: O(n m k) where matrix a is of size n × k, and matrix b is of
|
||
size k × m.
|
||
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<code class="constant">IGRAPH_EOVERFLOW</code> if the matrix is too large for BLAS,
|
||
<code class="constant">IGRAPH_EINVAL</code> if the matrices have incompatible sizes,
|
||
<code class="constant">IGRAPH_SUCCESS</code> otherwise.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.2.6.8.1"></a><p class="title"><b>Example 32.3. File <code class="code">examples/simple/blas_dgemm.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t a, b, c;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&a, 2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(a, 0, 0) = 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(a, 0, 1) = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(a, 1, 0) = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(a, 1, 1) = 4;
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&b, 2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(b, 0, 0) = 5;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(b, 0, 1) = 6;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(b, 1, 0) = 7;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(b, 1, 1) = 8;
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&c, 2, 2);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_dgemm" title="1.4. igraph_blas_dgemm — Matrix-matrix multiplication using BLAS.">igraph_blas_dgemm</a></strong></span>(1, 1, 0.5, &a, &b, 0, &c);
|
||
<span class="strong"><strong>igraph_matrix_printf</strong></span>(&c, "%g");
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&a);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&b);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&c);
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_blas_dgemv_array"></a>1.5. <code class="function">igraph_blas_dgemv_array</code> — Matrix-vector multiplication using BLAS, array version.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.33.2.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_blas_dgemv_array(igraph_bool_t transpose, igraph_real_t alpha,
|
||
const igraph_matrix_t* a, const igraph_real_t* x,
|
||
igraph_real_t beta, igraph_real_t* y);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function is a somewhat more user-friendly interface to
|
||
the <code class="constant">dgemv</code> function in BLAS. <code class="constant">dgemv</code> performs the operation
|
||
y = alpha*A*x + beta*y, where x and y are vectors and A is an
|
||
appropriately sized matrix (symmetric or non-symmetric).
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>transpose</code></em>:</span></p></td>
|
||
<td><p>
|
||
whether to transpose the matrix <em class="parameter"><code>A</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>alpha</code></em>:</span></p></td>
|
||
<td><p>
|
||
the constant <em class="parameter"><code>alpha</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
the matrix <em class="parameter"><code>A</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>x</code></em>:</span></p></td>
|
||
<td><p>
|
||
the vector <em class="parameter"><code>x</code></em> as a regular C array
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>beta</code></em>:</span></p></td>
|
||
<td><p>
|
||
the constant <em class="parameter"><code>beta</code></em>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>y</code></em>:</span></p></td>
|
||
<td><p>
|
||
the vector <em class="parameter"><code>y</code></em> as a regular C array
|
||
(which will be modified in-place)</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: O(nk) if the matrix is of size n x k
|
||
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<code class="constant">IGRAPH_EOVERFLOW</code> if the matrix is too large for BLAS,
|
||
<code class="constant">IGRAPH_SUCCESS</code> otherwise.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Linalg.html#igraph_blas_dgemv" title="1.3. igraph_blas_dgemv — Matrix-vector multiplication using BLAS, vector version."><code class="function">igraph_blas_dgemv</code></a> if you have vectors instead of
|
||
arrays.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="about-lapack"></a>2. LAPACK interface in igraph</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#matrix-factorization">2.1. Matrix factorization, solving linear systems</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#eigenvalues">2.2. Eigenvalues and eigenvectors of matrices</a></span></dt>
|
||
</dl></div>
|
||
<p>
|
||
LAPACK is written in Fortran90 and provides routines for solving
|
||
systems of simultaneous linear equations, least-squares solutions
|
||
of linear systems of equations, eigenvalue problems, and singular
|
||
value problems. The associated matrix factorizations (LU, Cholesky,
|
||
QR, SVD, Schur, generalized Schur) are also provided, as are
|
||
related computations such as reordering of the Schur factorizations
|
||
and estimating condition numbers. Dense and banded matrices are
|
||
handled, but not general sparse matrices. In all areas, similar
|
||
functionality is provided for real and complex matrices, in both
|
||
single and double precision.
|
||
</p>
|
||
<p>
|
||
igraph provides an interface to a very limited set of LAPACK
|
||
functions, using the regular igraph data structures.
|
||
</p>
|
||
<p>
|
||
See more about LAPACK at <a class="ulink" href="http://www.netlib.org/lapack/" target="_top">http://www.netlib.org/lapack/</a>
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="matrix-factorization"></a>2.1. Matrix factorization, solving linear systems</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dgetrf">2.1.1. <code class="function">igraph_lapack_dgetrf</code> — LU factorization of a general M-by-N matrix.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dgetrs">2.1.2. <code class="function">igraph_lapack_dgetrs</code> — Solve general system of linear equations using LU factorization.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dgesv">2.1.3. <code class="function">igraph_lapack_dgesv</code> — Solve system of linear equations with LU factorization.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dgetrf"></a>2.1.1. <code class="function">igraph_lapack_dgetrf</code> — LU factorization of a general M-by-N matrix.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.5.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dgetrf(igraph_matrix_t *a, igraph_vector_int_t *ipiv,
|
||
int *info);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The factorization has the form
|
||
A = P * L * U
|
||
where P is a permutation matrix, L is lower triangular with unit
|
||
diagonal elements (lower trapezoidal if m > n), and U is upper
|
||
triangular (upper trapezoidal if m < n).
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
The input/output matrix. On entry, the M-by-N matrix to be
|
||
factored. On exit, the factors L and U from the factorization
|
||
A = P * L * U; the unit diagonal elements of L are not
|
||
stored.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>ipiv</code></em>:</span></p></td>
|
||
<td><p>
|
||
An integer vector, the pivot indices are stored here,
|
||
unless it is a null pointer. Row <code class="constant">i</code> of the matrix was
|
||
interchanged with row <code class="literal">ipiv[i]</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>info</code></em>:</span></p></td>
|
||
<td><p>
|
||
LAPACK error code. Zero on successful exit. If its value is
|
||
a positive number i, it indicates that U(i,i) is exactly zero.
|
||
The factorization has been
|
||
completed, but the factor U is exactly singular, and division
|
||
by zero will occur if it is used to solve a system of
|
||
equations. If LAPACK returns an error, i.e. a negative info
|
||
value, then an igraph error is generated as well.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dgetrs"></a>2.1.2. <code class="function">igraph_lapack_dgetrs</code> — Solve general system of linear equations using LU factorization.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.5.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dgetrs(igraph_bool_t transpose, const igraph_matrix_t *a,
|
||
const igraph_vector_int_t *ipiv, igraph_matrix_t *b);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function calls LAPACK to solve a system of linear equations
|
||
A * X = B or A' * X = B
|
||
with a general N-by-N matrix A using the LU factorization
|
||
computed by <a class="link" href="igraph-Linalg.html#igraph_lapack_dgetrf" title="2.1.1. igraph_lapack_dgetrf — LU factorization of a general M-by-N matrix."><code class="function">igraph_lapack_dgetrf</code></a>.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>transpose</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether to transpose the input
|
||
matrix.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
A matrix containing the L and U factors from the
|
||
factorization A = P*L*U. L is expected to be unitriangular,
|
||
diagonal entries are those of U. If A is singular, no warning or
|
||
error wil be given and random output will be returned.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>ipiv</code></em>:</span></p></td>
|
||
<td><p>
|
||
An integer vector, the pivot indices from
|
||
<a class="link" href="igraph-Linalg.html#igraph_lapack_dgetrf" title="2.1.1. igraph_lapack_dgetrf — LU factorization of a general M-by-N matrix."><code class="function">igraph_lapack_dgetrf()</code></a> must be given here. Row <code class="constant">i</code> of A was
|
||
interchanged with row <code class="literal">ipiv[i]</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
The right hand side matrix must be given here. The solution
|
||
will also be placed here.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dgesv"></a>2.1.3. <code class="function">igraph_lapack_dgesv</code> — Solve system of linear equations with LU factorization.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.5.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dgesv(igraph_matrix_t *a, igraph_vector_int_t *ipiv,
|
||
igraph_matrix_t *b, int *info);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function computes the solution to a real system of linear
|
||
equations A * X = B, where A is an N-by-N matrix and X and B are
|
||
N-by-NRHS matrices.
|
||
|
||
</p>
|
||
<p>The LU decomposition with partial pivoting and row
|
||
interchanges is used to factor A as
|
||
A = P * L * U,
|
||
where P is a permutation matrix, L is unit lower triangular, and U is
|
||
upper triangular. The factored form of A is then used to solve the
|
||
system of equations A * X = B.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
Matrix. On entry the N-by-N coefficient matrix, on exit,
|
||
the factors L and U from the factorization A=P*L*U; the unit
|
||
diagonal elements of L are not stored.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>ipiv</code></em>:</span></p></td>
|
||
<td><p>
|
||
An integer vector or a null pointer. If not a null
|
||
pointer, then the pivot indices that define the permutation
|
||
matrix P, are stored here. Row i of the matrix was
|
||
interchanged with row IPIV(i).
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
Matrix, on entry the right hand side matrix should be
|
||
stored here. On exit, if there was no error, and the info
|
||
argument is zero, then it contains the solution matrix X.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>info</code></em>:</span></p></td>
|
||
<td><p>
|
||
The LAPACK info code. If it is positive, then
|
||
U(info,info) is exactly zero. In this case the factorization
|
||
has been completed, but the factor U is exactly
|
||
singular, so the solution could not be computed.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.3.5.4.9.1"></a><p class="title"><b>Example 32.4. File <code class="code">examples/simple/igraph_lapack_dgesv.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <stdio.h>
|
||
|
||
<span class="strong"><strong>#define</strong></span> DIM 10
|
||
|
||
void <span class="strong"><strong>igraph_print_warning</strong></span>(<span class="strong"><strong>const</strong></span> char *reason, <span class="strong"><strong>const</strong></span> char *file,
|
||
int line) {
|
||
<span class="strong"><strong>IGRAPH_UNUSED</strong></span>(file);
|
||
<span class="strong"><strong>IGRAPH_UNUSED</strong></span>(line);
|
||
<span class="strong"><strong>printf</strong></span>("Warning: %s\n", reason);
|
||
}
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
|
||
igraph_matrix_t A, B, RHS;
|
||
int info;
|
||
int i, j;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Identity matrix, you have to start somewhere */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, DIM, DIM);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&B, DIM, 1);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, i, i) = 1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, i, 0) = i + 1;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init_copy" title="3.2.3. igraph_matrix_init_copy — Copies a matrix.">igraph_matrix_init_copy</a></strong></span>(&RHS, &B);
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgesv" title="2.1.3. igraph_lapack_dgesv — Solve system of linear equations with LU factorization.">igraph_lapack_dgesv</a></strong></span>(&A, <span class="emphasis"><em>/*ipiv=*/</em></span> 0, &RHS, &info);
|
||
|
||
<span class="strong"><strong>if</strong></span> (info != 0) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (!<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_all_e" title="3.9.1. igraph_matrix_all_e — Are all elements equal?">igraph_matrix_all_e</a></strong></span>(&B, &RHS)) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&B);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&RHS);
|
||
|
||
<span class="emphasis"><em>/* Diagonal matrix */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, DIM, DIM);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&RHS, DIM, 1);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, i, i) = i + 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(RHS, i, 0) = i + 1;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgesv" title="2.1.3. igraph_lapack_dgesv — Solve system of linear equations with LU factorization.">igraph_lapack_dgesv</a></strong></span>(&A, <span class="emphasis"><em>/*ipiv=*/</em></span> 0, &RHS, &info);
|
||
|
||
<span class="strong"><strong>if</strong></span> (info != 0) {
|
||
<span class="strong"><strong>return</strong></span> 3;
|
||
}
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(RHS, i, 0) != 1.0) {
|
||
<span class="strong"><strong>return</strong></span> 4;
|
||
}
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&RHS);
|
||
|
||
<span class="emphasis"><em>/* A general matrix */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator.">igraph_rng_seed</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 42);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, DIM, DIM);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&B, DIM, 1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&RHS, DIM, 1);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
int j;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, i, 0) = <span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_get_integer" title="4.2. igraph_rng_get_integer — Generate an integer random number from an interval.">igraph_rng_get_integer</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 1, 10);
|
||
<span class="strong"><strong>for</strong></span> (j = 0; j < DIM; j++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, i, j) = <span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_get_integer" title="4.2. igraph_rng_get_integer — Generate an integer random number from an interval.">igraph_rng_get_integer</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 1, 10);
|
||
}
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_dgemv_array" title="1.5. igraph_blas_dgemv_array — Matrix-vector multiplication using BLAS, array version.">igraph_blas_dgemv_array</a></strong></span>(<span class="emphasis"><em>/*transpose=*/</em></span> 0, <span class="emphasis"><em>/*alpha=*/</em></span> 1.0, <span class="emphasis"><em>/*a=*/</em></span> &A,
|
||
<span class="emphasis"><em>/*x-*/</em></span> &<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, 0, 0), <span class="emphasis"><em>/*beta=*/</em></span> 0,
|
||
<span class="emphasis"><em>/*y=*/</em></span> &<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(RHS, 0, 0));
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgesv" title="2.1.3. igraph_lapack_dgesv — Solve system of linear equations with LU factorization.">igraph_lapack_dgesv</a></strong></span>(&A, <span class="emphasis"><em>/*ipiv=*/</em></span> 0, &RHS, &info);
|
||
<span class="strong"><strong>if</strong></span> (info != 0) {
|
||
<span class="strong"><strong>return</strong></span> 5;
|
||
}
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>fabs</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, i, 0) - <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(RHS, i, 0)) > 1e-11) {
|
||
<span class="strong"><strong>return</strong></span> 6;
|
||
}
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&B);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&RHS);
|
||
|
||
<span class="emphasis"><em>/* A singular matrix */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, DIM, DIM);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&B, DIM, 1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&RHS, DIM, 1);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, i, 0) = <span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_get_integer" title="4.2. igraph_rng_get_integer — Generate an integer random number from an interval.">igraph_rng_get_integer</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 1, 10);
|
||
<span class="strong"><strong>for</strong></span> (j = 0; j < DIM; j++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, i, j) = i == j ? 1 : 0;
|
||
}
|
||
}
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < DIM; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, DIM - 1, i) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, i);
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_blas_dgemv_array" title="1.5. igraph_blas_dgemv_array — Matrix-vector multiplication using BLAS, array version.">igraph_blas_dgemv_array</a></strong></span>(<span class="emphasis"><em>/*transpose=*/</em></span> 0, <span class="emphasis"><em>/*alpha=*/</em></span> 1.0, <span class="emphasis"><em>/*a=*/</em></span> &A,
|
||
<span class="emphasis"><em>/*x-*/</em></span> &<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(B, 0, 0), <span class="emphasis"><em>/*beta=*/</em></span> 0,
|
||
<span class="emphasis"><em>/*y=*/</em></span> &<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(RHS, 0, 0));
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#igraph_set_warning_handler" title="4.2. igraph_set_warning_handler — Installs a warning handler.">igraph_set_warning_handler</a></strong></span>(igraph_print_warning);
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgesv" title="2.1.3. igraph_lapack_dgesv — Solve system of linear equations with LU factorization.">igraph_lapack_dgesv</a></strong></span>(&A, <span class="emphasis"><em>/*ipiv=*/</em></span> 0, &RHS, &info);
|
||
<span class="strong"><strong>if</strong></span> (info != 10) {
|
||
<span class="strong"><strong>printf</strong></span>("LAPACK returned info = %d, should have been 10", info);
|
||
<span class="strong"><strong>return</strong></span> 7;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&B);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&RHS);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="eigenvalues"></a>2.2. Eigenvalues and eigenvectors of matrices</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dsyevr">2.2.1. <code class="function">igraph_lapack_dsyevr</code> — Selected eigenvalues and optionally eigenvectors of a symmetric matrix.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dgeev">2.2.2. <code class="function">igraph_lapack_dgeev</code> — Eigenvalues and optionally eigenvectors of a non-symmetric matrix.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_lapack_dgeevx">2.2.3. <code class="function">igraph_lapack_dgeevx</code> — Eigenvalues/vectors of nonsymmetric matrices, expert mode.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dsyevr"></a>2.2.1. <code class="function">igraph_lapack_dsyevr</code> — Selected eigenvalues and optionally eigenvectors of a symmetric matrix.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.6.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dsyevr(const igraph_matrix_t *A,
|
||
igraph_lapack_dsyev_which_t which,
|
||
igraph_real_t vl, igraph_real_t vu, int vestimate,
|
||
int il, int iu, igraph_real_t abstol,
|
||
igraph_vector_t *values, igraph_matrix_t *vectors,
|
||
igraph_vector_int_t *support);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Calls the DSYEVR LAPACK function to compute selected eigenvalues
|
||
and, optionally, eigenvectors of a real symmetric matrix <code class="constant">A</code>.
|
||
Eigenvalues and eigenvectors can be selected by specifying either
|
||
a range of values or a range of indices for the desired eigenvalues.
|
||
|
||
</p>
|
||
<p>
|
||
See more in the LAPACK documentation.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>A</code></em>:</span></p></td>
|
||
<td><p>
|
||
Matrix, on entry it contains the symmetric input
|
||
matrix. Only the leading N-by-N upper triangular part is
|
||
used for the computation.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>which</code></em>:</span></p></td>
|
||
<td><p>
|
||
Constant that gives which eigenvalues (and possibly
|
||
the corresponding eigenvectors) to calculate. Possible
|
||
values are <code class="constant">IGRAPH_LAPACK_DSYEV_ALL</code>, all eigenvalues;
|
||
<code class="constant">IGRAPH_LAPACK_DSYEV_INTERVAL</code>, all eigenvalues in the
|
||
half-open interval <code class="literal">(vl, vu]</code>;
|
||
<code class="constant">IGRAPH_LAPACK_DSYEV_SELECT</code>, the il-th through iu-th
|
||
eigenvalues.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vl</code></em>:</span></p></td>
|
||
<td><p>
|
||
If <em class="parameter"><code>which</code></em> is <code class="constant">IGRAPH_LAPACK_DSYEV_INTERVAL</code>, then
|
||
this is the lower bound of the interval to be searched for
|
||
eigenvalues. See also the <em class="parameter"><code>vestimate</code></em> argument.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vu</code></em>:</span></p></td>
|
||
<td><p>
|
||
If <em class="parameter"><code>which</code></em> is <code class="constant">IGRAPH_LAPACK_DSYEV_INTERVAL</code>, then
|
||
this is the upper bound of the interval to be searched for
|
||
eigenvalues. See also the <em class="parameter"><code>vestimate</code></em> argument.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vestimate</code></em>:</span></p></td>
|
||
<td><p>
|
||
An upper bound for the number of eigenvalues in
|
||
the <code class="literal">(vl, vu]</code> interval, if <em class="parameter"><code>which</code></em> is <code class="constant">IGRAPH_LAPACK_DSYEV_INTERVAL</code>. Memory is allocated only for
|
||
the given number of eigenvalues (and eigenvectors), so this
|
||
upper bound must be correct.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>il</code></em>:</span></p></td>
|
||
<td><p>
|
||
The index of the smallest eigenvalue to return, if <em class="parameter"><code>which</code></em> is <code class="constant">IGRAPH_LAPACK_DSYEV_SELECT</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>iu</code></em>:</span></p></td>
|
||
<td><p>
|
||
The index of the largets eigenvalue to return, if <em class="parameter"><code>which</code></em> is <code class="constant">IGRAPH_LAPACK_DSYEV_SELECT</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>abstol</code></em>:</span></p></td>
|
||
<td><p>
|
||
The absolute error tolerance for the eigevalues. An
|
||
approximate eigenvalue is accepted as converged when it is
|
||
determined to lie in an interval <code class="literal">[a,b]</code> of width
|
||
less than or equal to <code class="literal">abstol + EPS * max(|a|,|b|)</code>,
|
||
where <code class="constant">EPS</code> is the machine precision.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>values</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector, the eigenvalues are stored
|
||
here, unless it is a null pointer. It will be resized as
|
||
needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectors</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized matrix. A set of orthonormal eigenvectors
|
||
are stored in its columns, unless it is a null pointer. It will be
|
||
resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>support</code></em>:</span></p></td>
|
||
<td><p>
|
||
An integer vector. If not a null pointer, then it
|
||
will be resized to (2*max(1,M)) (M is a the total number of
|
||
eigenvalues found). Then the support of the eigenvectors in
|
||
<em class="parameter"><code>vectors</code></em> is stored here, i.e., the indices
|
||
indicating the nonzero elements in <em class="parameter"><code>vectors</code></em>.
|
||
The i-th eigenvector is nonzero only in elements
|
||
support(2*i-1) through support(2*i).
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.3.6.2.9.1"></a><p class="title"><b>Example 32.5. File <code class="code">examples/simple/igraph_lapack_dsyevr.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t A;
|
||
igraph_matrix_t vectors;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> values;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, 2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&vectors, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&values, 0);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 0) = 2.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 1) = -1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 0) = -1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 1) = 3.0;
|
||
|
||
<span class="strong"><strong>printf</strong></span>("Take a subset:\n");
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dsyevr" title="2.2.1. igraph_lapack_dsyevr — Selected eigenvalues and optionally eigenvectors of a symmetric matrix.">igraph_lapack_dsyevr</a></strong></span>(&A, IGRAPH_LAPACK_DSYEV_SELECT, <span class="emphasis"><em>/*vl=*/</em></span> 0, <span class="emphasis"><em>/*vu=*/</em></span> 0,
|
||
<span class="emphasis"><em>/*vestimate=*/</em></span> 0, <span class="emphasis"><em>/*il=*/</em></span> 1, <span class="emphasis"><em>/*iu=*/</em></span> 1,
|
||
<span class="emphasis"><em>/*abstol=*/</em></span> 1e-10, &values, &vectors,
|
||
<span class="emphasis"><em>/*support=*/</em></span> 0);
|
||
<span class="strong"><strong>printf</strong></span>("eigenvalues:\n");
|
||
<span class="strong"><strong>igraph_vector_print</strong></span>(&values);
|
||
<span class="strong"><strong>printf</strong></span>("eigenvectors:\n");
|
||
<span class="strong"><strong>igraph_matrix_print</strong></span>(&vectors);
|
||
|
||
<span class="strong"><strong>printf</strong></span>("\nTake a subset based on an interval:\n");
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dsyevr" title="2.2.1. igraph_lapack_dsyevr — Selected eigenvalues and optionally eigenvectors of a symmetric matrix.">igraph_lapack_dsyevr</a></strong></span>(&A, IGRAPH_LAPACK_DSYEV_INTERVAL, <span class="emphasis"><em>/*vl*/</em></span> 3, <span class="emphasis"><em>/*vu*/</em></span> 4,
|
||
<span class="emphasis"><em>/*vestimate=*/</em></span> 1, <span class="emphasis"><em>/*il=*/</em></span> 0, <span class="emphasis"><em>/*iu=*/</em></span> 0,
|
||
<span class="emphasis"><em>/*abstol=*/</em></span> 1e-10, &values, &vectors,
|
||
<span class="emphasis"><em>/*support=*/</em></span> 0);
|
||
|
||
<span class="strong"><strong>printf</strong></span>("eigenvalues:\n");
|
||
<span class="strong"><strong>igraph_vector_print</strong></span>(&values);
|
||
<span class="strong"><strong>printf</strong></span>("eigenvectors:\n");
|
||
<span class="strong"><strong>igraph_matrix_print</strong></span>(&vectors);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&values);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&vectors);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dgeev"></a>2.2.2. <code class="function">igraph_lapack_dgeev</code> — Eigenvalues and optionally eigenvectors of a non-symmetric matrix.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.6.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dgeev(const igraph_matrix_t *A,
|
||
igraph_vector_t *valuesreal,
|
||
igraph_vector_t *valuesimag,
|
||
igraph_matrix_t *vectorsleft,
|
||
igraph_matrix_t *vectorsright,
|
||
int *info);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function calls LAPACK to compute, for an N-by-N real
|
||
nonsymmetric matrix A, the eigenvalues and, optionally, the left
|
||
and/or right eigenvectors.
|
||
|
||
</p>
|
||
<p>
|
||
The right eigenvector v(j) of A satisfies
|
||
A * v(j) = lambda(j) * v(j)
|
||
where lambda(j) is its eigenvalue.
|
||
The left eigenvector u(j) of A satisfies
|
||
u(j)^H * A = lambda(j) * u(j)^H
|
||
where u(j)^H denotes the conjugate transpose of u(j).
|
||
|
||
</p>
|
||
<p>
|
||
The computed eigenvectors are normalized to have Euclidean norm
|
||
equal to 1 and largest component real.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>A</code></em>:</span></p></td>
|
||
<td><p>
|
||
matrix. On entry it contains the N-by-N input matrix.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>valuesreal</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector, or a null
|
||
pointer. If not a null pointer, then the real parts of the
|
||
eigenvalues are stored here. The vector will be resized as
|
||
needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>valuesimag</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector, or a null
|
||
pointer. If not a null pointer, then the imaginary parts of
|
||
the eigenvalues are stored here. The vector will be resized
|
||
as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectorsleft</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized matrix, or a null
|
||
pointer. If not a null pointer, then the left eigenvectors
|
||
are stored in the columns of the matrix. The matrix will be
|
||
resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectorsright</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized matrix, or a null
|
||
pointer. If not a null pointer, then the right eigenvectors
|
||
are stored in the columns of the matrix. The matrix will be
|
||
resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>info</code></em>:</span></p></td>
|
||
<td><p>
|
||
This argument is used for two purposes. As an input
|
||
argument it gives whether an igraph error should be
|
||
generated if the QR algorithm fails to compute all
|
||
eigenvalues. If <em class="parameter"><code>info</code></em> is non-zero, then an error is
|
||
generated, otherwise only a warning is given.
|
||
On exit it contains the LAPACK error code.
|
||
Zero means successful exit.
|
||
A negative values means that some of the arguments had an
|
||
illegal value, this always triggers an igraph error. An i
|
||
positive value means that the QR algorithm failed to
|
||
compute all the eigenvalues, and no eigenvectors have been
|
||
computed; element i+1:N of <em class="parameter"><code>valuesreal</code></em> and <em class="parameter"><code>valuesimag</code></em>
|
||
contain eigenvalues which have converged. This case only
|
||
generates an igraph error, if <em class="parameter"><code>info</code></em> was non-zero on entry.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.3.6.3.10.1"></a><p class="title"><b>Example 32.6. File <code class="code">examples/simple/igraph_lapack_dgeev.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <stdio.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t A;
|
||
igraph_matrix_t vectors_left, vectors_right;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> values_real, values_imag;
|
||
igraph_vector_complex_t values;
|
||
int info = 1;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, 2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&vectors_left, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&vectors_right, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&values_real, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&values_imag, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 0) = 1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 1) = 1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 0) = -1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 1) = 1.0;
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgeev" title="2.2.2. igraph_lapack_dgeev — Eigenvalues and optionally eigenvectors of a non-symmetric matrix.">igraph_lapack_dgeev</a></strong></span>(&A, &values_real, &values_imag,
|
||
&vectors_left, &vectors_right, &info);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_complex_create" title="2.14.4. igraph_vector_complex_create — Creates a complex vector from a real and imaginary part.">igraph_vector_complex_create</a></strong></span>(&values, &values_real, &values_imag);
|
||
<span class="strong"><strong>printf</strong></span>("eigenvalues:\n");
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&values);
|
||
<span class="strong"><strong>printf</strong></span>("left eigenvectors:\n");
|
||
<span class="strong"><strong>igraph_matrix_print</strong></span>(&vectors_left);
|
||
<span class="strong"><strong>printf</strong></span>("right eigenvectors:\n");
|
||
<span class="strong"><strong>igraph_matrix_print</strong></span>(&vectors_right);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&values_imag);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&values_real);
|
||
<span class="strong"><strong>igraph_vector_complex_destroy</strong></span>(&values);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&vectors_right);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&vectors_left);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_lapack_dgeevx"></a>2.2.3. <code class="function">igraph_lapack_dgeevx</code> — Eigenvalues/vectors of nonsymmetric matrices, expert mode.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.3.6.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_lapack_dgeevx(igraph_lapack_dgeevx_balance_t balance,
|
||
const igraph_matrix_t *A,
|
||
igraph_vector_t *valuesreal,
|
||
igraph_vector_t *valuesimag,
|
||
igraph_matrix_t *vectorsleft,
|
||
igraph_matrix_t *vectorsright,
|
||
int *ilo, int *ihi, igraph_vector_t *scale,
|
||
igraph_real_t *abnrm,
|
||
igraph_vector_t *rconde,
|
||
igraph_vector_t *rcondv,
|
||
int *info);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function calculates the eigenvalues and optionally the left
|
||
and/or right eigenvectors of a nonsymmetric N-by-N real matrix.
|
||
|
||
</p>
|
||
<p>
|
||
Optionally also, it computes a balancing transformation to improve
|
||
the conditioning of the eigenvalues and eigenvectors (<em class="parameter"><code>ilo</code></em>, <em class="parameter"><code>ihi</code></em>,
|
||
<em class="parameter"><code>scale</code></em>, and <em class="parameter"><code>abnrm</code></em>), reciprocal condition numbers for the
|
||
eigenvalues (<em class="parameter"><code>rconde</code></em>), and reciprocal condition numbers for the
|
||
right eigenvectors (<em class="parameter"><code>rcondv</code></em>).
|
||
|
||
</p>
|
||
<p>
|
||
The right eigenvector v(j) of A satisfies
|
||
A * v(j) = lambda(j) * v(j)
|
||
where lambda(j) is its eigenvalue.
|
||
The left eigenvector u(j) of A satisfies
|
||
u(j)^H * A = lambda(j) * u(j)^H
|
||
where u(j)^H denotes the conjugate transpose of u(j).
|
||
|
||
</p>
|
||
<p>
|
||
The computed eigenvectors are normalized to have Euclidean norm
|
||
equal to 1 and largest component real.
|
||
|
||
</p>
|
||
<p>
|
||
Balancing a matrix means permuting the rows and columns to make it
|
||
more nearly upper triangular, and applying a diagonal similarity
|
||
transformation D * A * D^(-1), where D is a diagonal matrix, to
|
||
make its rows and columns closer in norm and the condition numbers
|
||
of its eigenvalues and eigenvectors smaller. The computed
|
||
reciprocal condition numbers correspond to the balanced matrix.
|
||
Permuting rows and columns will not change the condition numbers
|
||
(in exact arithmetic) but diagonal scaling will. For further
|
||
explanation of balancing, see section 4.10.2 of the LAPACK
|
||
Users' Guide. Note that the eigenvectors obtained for the balanced
|
||
matrix are backtransformed to those of <em class="parameter"><code>A</code></em>.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>balance</code></em>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Indicates whether the input matrix should be balanced.
|
||
Possible values:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_LAPACK_DGEEVX_BALANCE_NONE</code></span></p></td>
|
||
<td><p>
|
||
|
||
no not diagonally scale or permute.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_LAPACK_DGEEVX_BALANCE_PERM</code></span></p></td>
|
||
<td><p>
|
||
|
||
perform permutations to make the matrix more nearly upper
|
||
triangular. Do not diagonally scale.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_LAPACK_DGEEVX_BALANCE_SCALE</code></span></p></td>
|
||
<td><p>
|
||
|
||
diagonally scale the matrix, i.e. replace A by
|
||
D*A*D^(-1), where D is a diagonal matrix, chosen to make
|
||
the rows and columns of A more equal in norm. Do not
|
||
permute.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_LAPACK_DGEEVX_BALANCE_BOTH</code></span></p></td>
|
||
<td><p>
|
||
|
||
both diagonally scale and permute A.
|
||
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>A</code></em>:</span></p></td>
|
||
<td><p>
|
||
The input matrix, must be square.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>valuesreal</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector, or a <code class="constant">NULL</code> pointer. If not
|
||
a <code class="constant">NULL</code> pointer, then the real parts of the eigenvalues are stored
|
||
here. The vector will be resized, as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>valuesimag</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector, or a <code class="constant">NULL</code> pointer. If not
|
||
a <code class="constant">NULL</code> pointer, then the imaginary parts of the eigenvalues are stored
|
||
here. The vector will be resized, as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectorsleft</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized matrix or a <code class="constant">NULL</code> pointer. If not
|
||
a null pointer, then the left eigenvectors are stored here. The
|
||
order corresponds to the eigenvalues and the eigenvectors are
|
||
stored in a compressed form. If the j-th eigenvalue is real then
|
||
column j contains the corresponding eigenvector. If the j-th and
|
||
(j+1)-th eigenvalues form a complex conjugate pair, then the j-th
|
||
and (j+1)-th columns contain the real and imaginary parts of the
|
||
corresponding eigenvectors.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectorsright</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized matrix or a <code class="constant">NULL</code> pointer. If not
|
||
a null pointer, then the right eigenvectors are stored here. The
|
||
format is the same, as for the <em class="parameter"><code>vectorsleft</code></em> argument.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>ilo</code></em>:</span></p></td>
|
||
<td><p>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>ihi</code></em>:</span></p></td>
|
||
<td><p>
|
||
if not NULL, <em class="parameter"><code>ilo</code></em> and <em class="parameter"><code>ihi</code></em> point to integer values
|
||
determined when A was
|
||
balanced. The balanced A(i,j) = 0 if I>J and
|
||
J=1,...,ilo-1 or I=ihi+1,...,N.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>scale</code></em>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Pointer to an initialized vector or a NULL pointer. If
|
||
not a NULL pointer, then details of the permutations and scaling
|
||
factors applied when balancing <em class="parameter"><code>A</code></em>, are stored here.
|
||
If P(j) is the index of the row and column
|
||
interchanged with row and column j, and D(j) is the scaling
|
||
factor applied to row and column j, then
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">scale(J) = P(J), for J = 1,...,ilo-1</code></span></p></td>
|
||
<td><p>
|
||
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">scale(J) = D(J), for J = ilo,...,ihi</code></span></p></td>
|
||
<td><p>
|
||
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">scale(J) = P(J) for J = ihi+1,...,N.</code></span></p></td>
|
||
<td><p>
|
||
|
||
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
The order in which the interchanges are made is N to <em class="parameter"><code>ihi</code></em>+1,
|
||
then 1 to <em class="parameter"><code>ilo</code></em>-1.
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>abnrm</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to a real variable, the one-norm of the
|
||
balanced matrix is stored here. (The one-norm is the maximum of
|
||
the sum of absolute values of elements in any column.)
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>rconde</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector or a NULL pointer. If not a
|
||
null pointer, then the reciprocal condition numbers of the
|
||
eigenvalues are stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>rcondv</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector or a NULL pointer. If not a
|
||
null pointer, then the reciprocal condition numbers of the right
|
||
eigenvectors are stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>info</code></em>:</span></p></td>
|
||
<td><p>
|
||
This argument is used for two purposes. As an input
|
||
argument it gives whether an igraph error should be
|
||
generated if the QR algorithm fails to compute all
|
||
eigenvalues. If <em class="parameter"><code>info</code></em> is non-zero, then an error is
|
||
generated, otherwise only a warning is given.
|
||
On exit it contains the LAPACK error code.
|
||
Zero means successful exit.
|
||
A negative values means that some of the arguments had an
|
||
illegal value, this always triggers an igraph error. An i
|
||
positive value means that the QR algorithm failed to
|
||
compute all the eigenvalues, and no eigenvectors have been
|
||
computed; element i+1:N of <em class="parameter"><code>valuesreal</code></em> and <em class="parameter"><code>valuesimag</code></em>
|
||
contain eigenvalues which have converged. This case only
|
||
generated an igraph error, if <em class="parameter"><code>info</code></em> was non-zero on entry.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.33.3.6.4.12.1"></a><p class="title"><b>Example 32.7. File <code class="code">examples/simple/igraph_lapack_dgeevx.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <stdio.h>
|
||
|
||
void <span class="strong"><strong>matrix_to_complex_vectors</strong></span>(igraph_vector_complex_t *c1, igraph_vector_complex_t *c2, igraph_matrix_t *m) {
|
||
<span class="strong"><strong>IGRAPH_REAL</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c1)[0]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 0, 0);
|
||
<span class="strong"><strong>IGRAPH_REAL</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c1)[1]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 1, 0);
|
||
<span class="strong"><strong>IGRAPH_IMAG</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c1)[0]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 0, 1);
|
||
<span class="strong"><strong>IGRAPH_IMAG</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c1)[1]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 1, 1);
|
||
|
||
<span class="strong"><strong>IGRAPH_REAL</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c2)[0]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 0, 0);
|
||
<span class="strong"><strong>IGRAPH_REAL</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c2)[1]) = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 1, 0);
|
||
<span class="strong"><strong>IGRAPH_IMAG</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c2)[0]) = -<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 0, 1);
|
||
<span class="strong"><strong>IGRAPH_IMAG</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(*c2)[1]) = -<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(*m, 1, 1);
|
||
}
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_matrix_t A;
|
||
igraph_matrix_t vectors_left, vectors_right;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> values_real, values_imag;
|
||
igraph_vector_complex_t values;
|
||
igraph_vector_complex_t eigenvector1;
|
||
igraph_vector_complex_t eigenvector2;
|
||
int info = 1;
|
||
igraph_real_t abnrm;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&A, 2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&vectors_left, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_init" title="3.2.1. igraph_matrix_init — Initializes a matrix.">igraph_matrix_init</a></strong></span>(&vectors_right, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&values_real, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&values_imag, 0);
|
||
<span class="strong"><strong>igraph_vector_complex_init</strong></span>(&eigenvector1, 2);
|
||
<span class="strong"><strong>igraph_vector_complex_init</strong></span>(&eigenvector2, 2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 0) = 1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 0, 1) = 1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 0) = -1.0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#MATRIX" title="3.4.1. MATRIX — Accessing an element of a matrix.">MATRIX</a></strong></span>(A, 1, 1) = 1.0;
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Linalg.html#igraph_lapack_dgeevx" title="2.2.3. igraph_lapack_dgeevx — Eigenvalues/vectors of nonsymmetric matrices, expert mode.">igraph_lapack_dgeevx</a></strong></span>(IGRAPH_LAPACK_DGEEVX_BALANCE_BOTH,
|
||
&A, &values_real, &values_imag,
|
||
&vectors_left, &vectors_right, NULL, NULL,
|
||
<span class="emphasis"><em>/*scale=*/</em></span> NULL, &abnrm, <span class="emphasis"><em>/*rconde=*/</em></span> NULL,
|
||
<span class="emphasis"><em>/*rcondv=*/</em></span> NULL, &info);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_complex_create" title="2.14.4. igraph_vector_complex_create — Creates a complex vector from a real and imaginary part.">igraph_vector_complex_create</a></strong></span>(&values, &values_real, &values_imag);
|
||
<span class="strong"><strong>printf</strong></span>("eigenvalues:\n");
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&values);
|
||
|
||
<span class="strong"><strong>printf</strong></span>("\nleft eigenvectors:\n");
|
||
<span class="emphasis"><em>/*matrix_to_complex_vectors only works because we have two complex</em></span>
|
||
<span class="emphasis"><em> conjugate eigenvalues */</em></span>
|
||
<span class="strong"><strong>matrix_to_complex_vectors</strong></span>(&eigenvector1, &eigenvector2, &vectors_left);
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&eigenvector1);
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&eigenvector2);
|
||
|
||
<span class="strong"><strong>printf</strong></span>("\nright eigenvectors:\n");
|
||
<span class="strong"><strong>matrix_to_complex_vectors</strong></span>(&eigenvector1, &eigenvector2, &vectors_right);
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&eigenvector1);
|
||
<span class="strong"><strong>igraph_vector_complex_print</strong></span>(&eigenvector2);
|
||
<span class="strong"><strong>printf</strong></span>("\nOne-norm of the balanced matrix:\n%g\n", abnrm);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&values_imag);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&values_real);
|
||
<span class="strong"><strong>igraph_vector_complex_destroy</strong></span>(&values);
|
||
<span class="strong"><strong>igraph_vector_complex_destroy</strong></span>(&eigenvector1);
|
||
<span class="strong"><strong>igraph_vector_complex_destroy</strong></span>(&eigenvector2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&vectors_right);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&vectors_left);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_matrix_destroy" title="3.2.4. igraph_matrix_destroy — Destroys a matrix object.">igraph_matrix_destroy</a></strong></span>(&A);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="about-arpack"></a>3. ARPACK interface in igraph</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#arpack-data-structures">3.1. Data structures</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#arpack-solvers">3.2. ARPACK solvers</a></span></dt>
|
||
</dl></div>
|
||
<p>
|
||
ARPACK is a library for solving large scale eigenvalue problems.
|
||
The package is designed to compute a few eigenvalues and corresponding
|
||
eigenvectors of a general <code class="constant">n</code> by <code class="constant">n</code> matrix <code class="constant">A</code>. It is
|
||
most appropriate for large sparse or structured matrices <code class="constant">A</code> where
|
||
structured means that a matrix-vector product <code class="literal">w <- Av</code> requires
|
||
order <code class="constant">n</code> rather than the usual order <code class="literal">n^2</code> floating point
|
||
operations. Please see <a class="ulink" href="https://github.com/opencollab/arpack-ng" target="_top">https://github.com/opencollab/arpack-ng</a> for details.
|
||
</p>
|
||
<p>
|
||
The eigenvalue calculation in ARPACK (in the simplest
|
||
case) involves the calculation of the <code class="constant">Av</code> product where <code class="constant">A</code>
|
||
is the matrix we work with and <code class="constant">v</code> is an arbitrary vector. A
|
||
user-defined function of type <a class="link" href="igraph-Linalg.html#igraph_arpack_function_t" title="3.1.3. igraph_arpack_function_t — Type of the ARPACK callback function."><code class="function">igraph_arpack_function_t</code></a>
|
||
is expected to perform this product. If the product can be done
|
||
efficiently, e.g. if the matrix is sparse, then ARPACK is usually
|
||
able to calculate the eigenvalues very quickly.
|
||
</p>
|
||
<p>In igraph, eigenvalue/eigenvector calculations usually
|
||
involve the following steps:
|
||
</p>
|
||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||
<li class="listitem"><p>
|
||
Initialization of an <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> data
|
||
structure using <a class="link" href="igraph-Linalg.html#igraph_arpack_options_init" title="3.1.4. igraph_arpack_options_init — Initialize ARPACK options."><code class="function">igraph_arpack_options_init</code></a>.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
Setting some options in the initialized <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> object.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
Defining a function of type <a class="link" href="igraph-Linalg.html#igraph_arpack_function_t" title="3.1.3. igraph_arpack_function_t — Type of the ARPACK callback function."><code class="function">igraph_arpack_function_t</code></a>.
|
||
The input of this function is a vector, and the output
|
||
should be the output matrix multiplied by the input vector.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
Calling <a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve()</code></a> (is the matrix is
|
||
symmetric), or <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a>.
|
||
|
||
</p></li>
|
||
</ol></div>
|
||
<p>
|
||
The <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> object can be used multiple
|
||
times.
|
||
</p>
|
||
<p>
|
||
If we have many eigenvalue problems to solve, then it might worth
|
||
to create an <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object, and initialize it
|
||
via <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_init" title="3.1.5. igraph_arpack_storage_init — Initialize ARPACK storage."><code class="function">igraph_arpack_storage_init()</code></a>. This structure contains all
|
||
memory needed for ARPACK (with the given upper limit regerding to
|
||
the size of the eigenvalue problem). Then many problems can be
|
||
solved using the same <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object, without
|
||
always reallocating the required memory.
|
||
The <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object needs to be destroyed by
|
||
calling <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_destroy" title="3.1.6. igraph_arpack_storage_destroy — Deallocate ARPACK storage."><code class="function">igraph_arpack_storage_destroy()</code></a> on it, when it is not
|
||
needed any more.
|
||
</p>
|
||
<p>
|
||
igraph does not contain all
|
||
ARPACK routines, only the ones dealing with symmetric and
|
||
non-symmetric eigenvalue problems using double precision real
|
||
numbers.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="arpack-data-structures"></a>3.1. Data structures</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_options_t">3.1.1. <code class="function">igraph_arpack_options_t</code> — Options for ARPACK.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_storage_t">3.1.2. <code class="function">igraph_arpack_storage_t</code> — Storage for ARPACK.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_function_t">3.1.3. <code class="function">igraph_arpack_function_t</code> — Type of the ARPACK callback function.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_options_init">3.1.4. <code class="function">igraph_arpack_options_init</code> — Initialize ARPACK options.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_storage_init">3.1.5. <code class="function">igraph_arpack_storage_init</code> — Initialize ARPACK storage.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_storage_destroy">3.1.6. <code class="function">igraph_arpack_storage_destroy</code> — Deallocate ARPACK storage.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_options_t"></a>3.1.1. <code class="function">igraph_arpack_options_t</code> — Options for ARPACK.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.2.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
typedef struct igraph_arpack_options_t {
|
||
/* INPUT */
|
||
char bmat[1]; /* I-standard problem, G-generalized */
|
||
int n; /* Dimension of the eigenproblem */
|
||
char which[2]; /* LA, SA, LM, SM, BE */
|
||
int nev; /* Number of eigenvalues to be computed */
|
||
igraph_real_t tol; /* Stopping criterion */
|
||
int ncv; /* Number of columns in V */
|
||
int ldv; /* Leading dimension of V */
|
||
int ishift; /* 0-reverse comm., 1-exact with tridiagonal */
|
||
int mxiter; /* Maximum number of update iterations to take */
|
||
int nb; /* Block size on the recurrence, only 1 works */
|
||
int mode; /* The kind of problem to be solved (1-5)
|
||
1: A*x=l*x, A symmetric
|
||
2: A*x=l*M*x, A symm. M pos. def.
|
||
3: K*x = l*M*x, K symm., M pos. semidef.
|
||
4: K*x = l*KG*x, K s. pos. semidef. KG s. indef.
|
||
5: A*x = l*M*x, A symm., M symm. pos. semidef. */
|
||
int start; /* 0: random, 1: use the supplied vector */
|
||
int lworkl; /* Size of temporary storage, default is fine */
|
||
igraph_real_t sigma; /* The shift for modes 3,4,5 */
|
||
igraph_real_t sigmai; /* The imaginary part of shift for rnsolve */
|
||
/* OUTPUT */
|
||
int info; /* What happened, see docs */
|
||
int ierr; /* What happened in the dseupd call */
|
||
int noiter; /* The number of iterations taken */
|
||
int nconv;
|
||
int numop; /* Number of OP*x operations */
|
||
int numopb; /* Number of B*x operations if BMAT='G' */
|
||
int numreo; /* Number of steps of re-orthogonalizations */
|
||
/* INTERNAL */
|
||
int iparam[11];
|
||
int ipntr[14];
|
||
} igraph_arpack_options_t;
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
</p>
|
||
<p>This data structure contains the options of the ARPACK eigenvalue
|
||
solver routines. It must be initialized by calling <a class="link" href="igraph-Linalg.html#igraph_arpack_options_init" title="3.1.4. igraph_arpack_options_init — Initialize ARPACK options."><code class="function">igraph_arpack_options_init()</code></a> on it. Then it can be used for
|
||
multiple ARPACK calls, as the ARPACK solvers do not modify it.
|
||
|
||
Input options:
|
||
|
||
</p>
|
||
<p><b>Values: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">bmat</code>:</span></p></td>
|
||
<td><p>
|
||
Character. Whether to solve a standard ('I') ot a
|
||
generalized problem ('B').
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">n</code>:</span></p></td>
|
||
<td><p>
|
||
Dimension of the eigenproblem.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">which</code>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Specifies which eigenvalues/vectors to
|
||
compute. Possible values for symmetric matrices:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">LA</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> largest (algebraic) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">SA</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> smallest (algebraic) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">LM</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> largest (in magnitude) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">SM</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> smallest (in magnitude) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">BE</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> eigenvalues, half from each end of
|
||
the spectrum. When <code class="constant">nev</code> is odd, compute one
|
||
more from the high en than from the low
|
||
end.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
Possible values for non-symmetric matrices:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">LM</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> largest (in magnitude) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">SM</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> smallest (in magnitude) eigenvalues.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">LR</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> eigenvalues of largest real part.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">SR</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> eigenvalues of smallest real part.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">LI</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> eigenvalues of largest imaginary part.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">SI</code></span></p></td>
|
||
<td><p>
|
||
|
||
Compute <code class="constant">nev</code> eigenvalues of smallest imaginary
|
||
part.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">nev</code>:</span></p></td>
|
||
<td><p>
|
||
The number of eigenvalues to be computed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">tol</code>:</span></p></td>
|
||
<td><p>
|
||
Stopping criterion: the relative accuracy
|
||
of the Ritz value is considered acceptable if its error is less
|
||
than <code class="constant">tol</code> times its estimated value. If this is set to zero
|
||
then machine precision is used.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ncv</code>:</span></p></td>
|
||
<td><p>
|
||
Number of Lanczos vectors to be generated. Setting this
|
||
to zero means that <a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve</code></a> and <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve</code></a>
|
||
will determine a suitable value for <code class="constant">ncv</code> automatically.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ldv</code>:</span></p></td>
|
||
<td><p>
|
||
Numberic scalar. It should be set to
|
||
zero in the current igraph implementation.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ishift</code>:</span></p></td>
|
||
<td><p>
|
||
Either zero or one. If zero then the shifts are
|
||
provided by the user via reverse communication. If one then exact
|
||
shifts with respect to the reduced tridiagonal matrix <code class="constant">T</code>.
|
||
Please always set this to one.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">mxiter</code>:</span></p></td>
|
||
<td><p>
|
||
Maximum number of Arnoldi update iterations allowed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">nb</code>:</span></p></td>
|
||
<td><p>
|
||
Blocksize to be used in the recurrence. Please always
|
||
leave this on the default value, one.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">mode</code>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
The type of the eigenproblem to be solved.
|
||
Possible values if the input matrix is symmetric:
|
||
</p>
|
||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||
<li class="listitem"><p>
|
||
A*x=lambda*x, A is symmetric.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
A*x=lambda*M*x, A is
|
||
symmetric, M is symmetric positive definite.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
K*x=lambda*M*x, K is
|
||
symmetric, M is symmetric positive semi-definite.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
K*x=lambda*KG*x, K is
|
||
symmetric positive semi-definite, KG is symmetric
|
||
indefinite.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
A*x=lambda*M*x, A is
|
||
symmetric, M is symmetric positive
|
||
semi-definite. (Cayley transformed mode.)
|
||
</p></li>
|
||
</ol></div>
|
||
<p>
|
||
Please note that only <code class="constant">mode</code> ==1 was tested and other values
|
||
might not work properly.
|
||
Possible values if the input matrix is not symmetric:
|
||
</p>
|
||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||
<li class="listitem"><p>
|
||
A*x=lambda*x.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
A*x=lambda*M*x, M is
|
||
symmetric positive definite.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
A*x=lambda*M*x, M is
|
||
symmetric semi-definite.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
A*x=lambda*M*x, M is
|
||
symmetric semi-definite.
|
||
</p></li>
|
||
</ol></div>
|
||
<p>
|
||
Please note that only <code class="constant">mode</code> == 1 was tested and other values
|
||
might not work properly.
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">start</code>:</span></p></td>
|
||
<td><p>
|
||
Whether to use the supplied starting vector (1), or
|
||
use a random starting vector (0). The starting vector must be
|
||
supplied in the first column of the <code class="constant">vectors</code> argument of the
|
||
<a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve()</code></a> of <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a> call.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p>Output options:
|
||
|
||
</p>
|
||
<p><b>Values: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">info</code>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Error flag of ARPACK. Possible values:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">0</code></span></p></td>
|
||
<td><p>
|
||
|
||
Normal exit.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">1</code></span></p></td>
|
||
<td><p>
|
||
|
||
Maximum number of iterations taken.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">3</code></span></p></td>
|
||
<td><p>
|
||
|
||
No shifts could be applied during a cycle of the
|
||
Implicitly restarted Arnoldi iteration. One possibility
|
||
is to increase the size of <code class="constant">ncv</code> relative to <code class="constant">nev</code>.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
ARPACK can return other error flags as well, but these are
|
||
converted to igraph errors, see <a class="link" href="igraph-Error.html#igraph_error_type_t" title="3.2. igraph_error_type_t — Error code type."><code class="function">igraph_error_type_t</code></a>.
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ierr</code>:</span></p></td>
|
||
<td><p>
|
||
Error flag of the second ARPACK call (one eigenvalue
|
||
computation usually involves two calls to ARPACK). This is
|
||
always zero, as other error codes are converted to igraph errors.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">noiter</code>:</span></p></td>
|
||
<td><p>
|
||
Number of Arnoldi iterations taken.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">nconv</code>:</span></p></td>
|
||
<td><p>
|
||
Number of converged Ritz values. This
|
||
represents the number of Ritz values that satisfy the
|
||
convergence critetion.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">numop</code>:</span></p></td>
|
||
<td><p>
|
||
Total number of matrix-vector multiplications.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">numopb</code>:</span></p></td>
|
||
<td><p>
|
||
Not used currently.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">numreo</code>:</span></p></td>
|
||
<td><p>
|
||
Total number of steps of re-orthogonalization.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p>Internal options:
|
||
</p>
|
||
<p><b>Values: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">lworkl</code>:</span></p></td>
|
||
<td><p>
|
||
Do not modify this option.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">sigma</code>:</span></p></td>
|
||
<td><p>
|
||
The shift for the shift-invert mode.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">sigmai</code>:</span></p></td>
|
||
<td><p>
|
||
The imaginary part of the shift, for the
|
||
non-symmetric or complex shift-invert mode.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">iparam</code>:</span></p></td>
|
||
<td><p>
|
||
Do not modify this option.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ipntr</code>:</span></p></td>
|
||
<td><p>
|
||
Do not modify this option.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_storage_t"></a>3.1.2. <code class="function">igraph_arpack_storage_t</code> — Storage for ARPACK.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.3.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
typedef struct igraph_arpack_storage_t {
|
||
int maxn, maxncv, maxldv;
|
||
igraph_real_t *v;
|
||
igraph_real_t *workl;
|
||
igraph_real_t *workd;
|
||
igraph_real_t *d;
|
||
igraph_real_t *resid;
|
||
igraph_real_t *ax;
|
||
int *select;
|
||
/* The following two are only used for non-symmetric problems: */
|
||
igraph_real_t *di;
|
||
igraph_real_t *workev;
|
||
} igraph_arpack_storage_t;
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
</p>
|
||
<p>Public members, do not modify them directly, these are considered
|
||
to be read-only.
|
||
</p>
|
||
<p><b>Values: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">maxn</code>:</span></p></td>
|
||
<td><p>
|
||
Maximum rank of matrix.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">maxncv</code>:</span></p></td>
|
||
<td><p>
|
||
Maximum NCV.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">maxldv</code>:</span></p></td>
|
||
<td><p>
|
||
Maximum LDV.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p>These members are considered to be private:
|
||
</p>
|
||
<p><b>Values: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">workl</code>:</span></p></td>
|
||
<td><p>
|
||
Working memory.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">workd</code>:</span></p></td>
|
||
<td><p>
|
||
Working memory.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">d</code>:</span></p></td>
|
||
<td><p>
|
||
Memory for eigenvalues.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">resid</code>:</span></p></td>
|
||
<td><p>
|
||
Memory for residuals.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">ax</code>:</span></p></td>
|
||
<td><p>
|
||
Working memory.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">select</code>:</span></p></td>
|
||
<td><p>
|
||
Working memory.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">di</code>:</span></p></td>
|
||
<td><p>
|
||
Memory for eigenvalues, non-symmetric case only.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">workev</code>:</span></p></td>
|
||
<td><p>
|
||
Working memory, non-symmetric case only.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_function_t"></a>3.1.3. <code class="function">igraph_arpack_function_t</code> — Type of the ARPACK callback function.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.4.2"></a><pre class="programlisting">
|
||
typedef igraph_error_t igraph_arpack_function_t(igraph_real_t *to, const igraph_real_t *from,
|
||
int n, void *extra);
|
||
</pre>
|
||
<p>
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>to</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <code class="constant">igraph_real_t</code>, the result of the
|
||
matrix-vector product is expected to be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>from</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <code class="constant">igraph_real_t</code>, the input matrix should
|
||
be multiplied by the vector stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The length of the vector (which is the same as the order
|
||
of the input matrix).
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>extra</code></em>:</span></p></td>
|
||
<td><p>
|
||
Extra argument to the matrix-vector calculation
|
||
function. This is coming from the <a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve()</code></a>
|
||
or <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a> function.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code. If not <code class="constant">IGRAPH_SUCCESS</code>, then the ARPACK solver considers
|
||
this as an error, stops and calls the igraph error handler.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_options_init"></a>3.1.4. <code class="function">igraph_arpack_options_init</code> — Initialize ARPACK options.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
void igraph_arpack_options_init(igraph_arpack_options_t *o);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Initializes ARPACK options, set them to default values.
|
||
You can always pass the initialized <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a>
|
||
object to built-in igraph functions without any modification. The
|
||
built-in igraph functions modify the options to perform their
|
||
calculation, e.g. <a class="link" href="igraph-Structural.html#igraph_pagerank" title="11.6. igraph_pagerank — Calculates the Google PageRank for the specified vertices."><code class="function">igraph_pagerank()</code></a> always searches for the
|
||
eigenvalue with the largest magnitude, regardless of the supplied
|
||
value.
|
||
|
||
</p>
|
||
<p>
|
||
If you want to implement your own function involving eigenvalue
|
||
calculation using ARPACK, however, you will likely need to set up
|
||
the fields for yourself.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>o</code></em>:</span></p></td>
|
||
<td><p>
|
||
The <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> object to initialize.</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: O(1).
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_storage_init"></a>3.1.5. <code class="function">igraph_arpack_storage_init</code> — Initialize ARPACK storage.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_arpack_storage_init(igraph_arpack_storage_t *s, igraph_int_t maxn,
|
||
igraph_int_t maxncv, igraph_int_t maxldv,
|
||
igraph_bool_t symm);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
You only need this function if you want to run multiple eigenvalue
|
||
calculations using ARPACK, and want to spare the memory
|
||
allocation/deallocation between each two runs. Otherwise it is safe
|
||
to supply a null pointer as the <code class="constant">storage</code> argument of both <a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve()</code></a> and <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a> to make
|
||
memory allocated and deallocated automatically.
|
||
|
||
</p>
|
||
<p>
|
||
Don't forget to call the <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_destroy" title="3.1.6. igraph_arpack_storage_destroy — Deallocate ARPACK storage."><code class="function">igraph_arpack_storage_destroy()</code></a>
|
||
function on the storage object if you don't need it any more.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>s</code></em>:</span></p></td>
|
||
<td><p>
|
||
The <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object to initialize.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>maxn</code></em>:</span></p></td>
|
||
<td><p>
|
||
The maximum order of the matrices.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>maxncv</code></em>:</span></p></td>
|
||
<td><p>
|
||
The maximum NCV parameter intended to use.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>maxldv</code></em>:</span></p></td>
|
||
<td><p>
|
||
The maximum LDV parameter intended to use.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>symm</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether symmetric or non-symmetric problems will be
|
||
solved using this <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a>. (You cannot use
|
||
the same storage both with symmetric and non-symmetric solvers.)
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(maxncv*(maxldv+maxn)).
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_storage_destroy"></a>3.1.6. <code class="function">igraph_arpack_storage_destroy</code> — Deallocate ARPACK storage.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.7.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
void igraph_arpack_storage_destroy(igraph_arpack_storage_t *s);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>s</code></em>:</span></p></td>
|
||
<td><p>
|
||
The <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object for which the
|
||
memory will be deallocated.</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: operating system dependent.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="arpack-solvers"></a>3.2. ARPACK solvers</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_rssolve">3.2.1. <code class="function">igraph_arpack_rssolve</code> — ARPACK solver for symmetric matrices.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_rnsolve">3.2.2. <code class="function">igraph_arpack_rnsolve</code> — ARPACK solver for non-symmetric matrices.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Linalg.html#igraph_arpack_unpack_complex">3.2.3. <code class="function">igraph_arpack_unpack_complex</code> — Makes the result of the non-symmetric ARPACK solver more readable.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_rssolve"></a>3.2.1. <code class="function">igraph_arpack_rssolve</code> — ARPACK solver for symmetric matrices.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.8.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_arpack_rssolve(igraph_arpack_function_t *fun, void *extra,
|
||
igraph_arpack_options_t *options,
|
||
igraph_arpack_storage_t *storage,
|
||
igraph_vector_t *values, igraph_matrix_t *vectors);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This is the ARPACK solver for symmetric matrices. Please use
|
||
<a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a> for non-symmetric matrices.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>fun</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <a class="link" href="igraph-Linalg.html#igraph_arpack_function_t" title="3.1.3. igraph_arpack_function_t — Type of the ARPACK callback function."><code class="function">igraph_arpack_function_t</code></a> object,
|
||
the function that performs the matrix-vector multiplication.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>extra</code></em>:</span></p></td>
|
||
<td><p>
|
||
An extra argument to be passed to <code class="constant">fun</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>options</code></em>:</span></p></td>
|
||
<td><p>
|
||
An <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>storage</code></em>:</span></p></td>
|
||
<td><p>
|
||
An <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object, or a null
|
||
pointer. In the latter case memory allocation and deallocation
|
||
is performed automatically. Either this or the <em class="parameter"><code>vectors</code></em> argument
|
||
must be non-null if the ARPACK iteration is started from a
|
||
given starting vector. If both are given <em class="parameter"><code>vectors</code></em> take
|
||
precedence.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>values</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it should be a pointer to an
|
||
initialized vector. The eigenvalues will be stored here. The
|
||
vector will be resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectors</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be a pointer to
|
||
an initialized matrix. The eigenvectors will be stored in the
|
||
columns of the matrix. The matrix will be resized as needed.
|
||
Either this or the <em class="parameter"><code>storage</code></em> argument must be non-null if the
|
||
ARPACK iteration is started from a given starting vector. If
|
||
both are given <em class="parameter"><code>vectors</code></em> take precedence.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: depends on the matrix-vector
|
||
multiplication. Usually a small number of iterations is enough, so
|
||
if the matrix is sparse and the matrix-vector multiplication can be
|
||
done in O(n) time (the number of vertices), then the eigenvalues
|
||
are found in O(n) time as well.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_rnsolve"></a>3.2.2. <code class="function">igraph_arpack_rnsolve</code> — ARPACK solver for non-symmetric matrices.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.8.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_arpack_rnsolve(igraph_arpack_function_t *fun, void *extra,
|
||
igraph_arpack_options_t *options,
|
||
igraph_arpack_storage_t *storage,
|
||
igraph_matrix_t *values, igraph_matrix_t *vectors);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Please always consider calling <a class="link" href="igraph-Linalg.html#igraph_arpack_rssolve" title="3.2.1. igraph_arpack_rssolve — ARPACK solver for symmetric matrices."><code class="function">igraph_arpack_rssolve()</code></a> if your
|
||
matrix is symmetric, it is much faster.
|
||
<a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve()</code></a> for non-symmetric matrices.
|
||
</p>
|
||
<p>
|
||
Note that ARPACK is not called for 2x2 matrices as an exact algebraic
|
||
solution exists in these cases.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>fun</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <a class="link" href="igraph-Linalg.html#igraph_arpack_function_t" title="3.1.3. igraph_arpack_function_t — Type of the ARPACK callback function."><code class="function">igraph_arpack_function_t</code></a> object,
|
||
the function that performs the matrix-vector multiplication.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>extra</code></em>:</span></p></td>
|
||
<td><p>
|
||
An extra argument to be passed to <code class="constant">fun</code>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>options</code></em>:</span></p></td>
|
||
<td><p>
|
||
An <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a> object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>storage</code></em>:</span></p></td>
|
||
<td><p>
|
||
An <a class="link" href="igraph-Linalg.html#igraph_arpack_storage_t" title="3.1.2. igraph_arpack_storage_t — Storage for ARPACK."><code class="function">igraph_arpack_storage_t</code></a> object, or a null
|
||
pointer. In the latter case memory allocation and deallocation
|
||
is performed automatically.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>values</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it should be a pointer to an
|
||
initialized matrix. The (possibly complex) eigenvalues will be
|
||
stored here. The matrix will have two columns, the first column
|
||
contains the real, the second the imaginary parts of the
|
||
eigenvalues.
|
||
The matrix will be resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectors</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be a pointer to
|
||
an initialized matrix. The eigenvectors will be stored in the
|
||
columns of the matrix. The matrix will be resized as needed.
|
||
Note that real eigenvalues will have real eigenvectors in a single
|
||
column in this matrix; however, complex eigenvalues come in conjugate
|
||
pairs and the result matrix will store the eigenvector corresponding to
|
||
the eigenvalue with <span class="emphasis"><em>positive</em></span> imaginary part only. Since in this case
|
||
the eigenvector is also complex, it will occupy <span class="emphasis"><em>two</em></span> columns in the
|
||
eigenvector matrix (the real and the imaginary parts, in this order).
|
||
Caveat: if the eigenvalue vector returns only the eigenvalue with the
|
||
<span class="emphasis"><em>negative</em></span> imaginary part for a complex conjugate eigenvalue pair, the
|
||
result vector will <span class="emphasis"><em>still</em></span> store the eigenvector corresponding to the
|
||
eigenvalue with the positive imaginary part (since this is how ARPACK
|
||
works).
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: depends on the matrix-vector
|
||
multiplication. Usually a small number of iterations is enough, so
|
||
if the matrix is sparse and the matrix-vector multiplication can be
|
||
done in O(n) time (the number of vertices), then the eigenvalues
|
||
are found in O(n) time as well.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_arpack_unpack_complex"></a>3.2.3. <code class="function">igraph_arpack_unpack_complex</code> — Makes the result of the non-symmetric ARPACK solver more readable.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.33.4.8.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_arpack_unpack_complex(igraph_matrix_t *vectors, igraph_matrix_t *values,
|
||
igraph_int_t nev);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function works on the output of <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve</code></a> and
|
||
brushes it up a bit: it only keeps <em class="parameter"><code>nev</code></em> eigenvalues/vectors and
|
||
every eigenvector is stored in two columns of the <em class="parameter"><code>vectors</code></em>
|
||
matrix.
|
||
|
||
</p>
|
||
<p>
|
||
The output of the non-symmetric ARPACK solver is somewhat hard to
|
||
parse, as real eigenvectors occupy only one column in the matrix,
|
||
and the complex conjugate eigenvectors are not stored at all
|
||
(usually). The other problem is that the solver might return more
|
||
eigenvalues than requested. The common use of this function is to
|
||
call it directly after <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve</code></a> with its <em class="parameter"><code>vectors</code></em> and <em class="parameter"><code>values</code></em> argument and <code class="constant">options</code>->nev as <em class="parameter"><code>nev</code></em>.
|
||
This will add the vectors for eigenvalues with a negative imaginary
|
||
part and return all vectors as 2 columns, a real and imaginary part.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vectors</code></em>:</span></p></td>
|
||
<td><p>
|
||
The eigenvector matrix, as returned by <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve</code></a>. It will be resized, typically it will be
|
||
larger.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>values</code></em>:</span></p></td>
|
||
<td><p>
|
||
The eigenvalue matrix, as returned by <a class="link" href="igraph-Linalg.html#igraph_arpack_rnsolve" title="3.2.2. igraph_arpack_rnsolve — ARPACK solver for non-symmetric matrices."><code class="function">igraph_arpack_rnsolve</code></a>. It will be resized, typically extra,
|
||
unneeded rows (=eigenvalues) will be removed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>nev</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of eigenvalues/vectors to keep. Can be less
|
||
or equal than the number originally requested from ARPACK.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: linear in the number of elements in the <em class="parameter"><code>vectors</code></em>
|
||
matrix.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<table class="navigation-footer" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle">
|
||
<td align="left"><a accesskey="p" href="igraph-Foreign.html"><b>← Chapter 31. Reading and writing graphs from and to files</b></a></td>
|
||
<td align="right"><a accesskey="n" href="igraph-Nongraph.html"><b>Chapter 33. Non-graph related functions →</b></a></td>
|
||
</tr></table>
|
||
</body>
|
||
</html>
|