<h1 id="Using-LazyLinearOp-s">Using LazyLinearOp-s<a class="anchor-link" href="#Using-LazyLinearOp-s">¶</a></h1><p>The <code>LazyLinearOp</code> class defines a kind of linear operator extending the scipy <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html">LinearOperator</a> class.</p>
<p>Starting from a <code>numpy</code> array, a <code>scipy</code> matrix, a <code>Faust</code> object, or potentially many other compatible linear operators with efficient implementatons, this class follows the <em>lazy evaluation paradigm</em>.</p>
<p>In short, one can <em>aggregate low-level <code>LazyLinearOp</code> objects into higher-level ones</em> using classical operations (addition, concatenation, adjoint, real part, slicing, etc.), without actually building arrays. The actual effect of these operations is delayed until the resulting linear operator is actually applied to a vector (or to a collection of vectors, seen as a matrix).</p>
<p>The main interest of this paradigm is to enable the construction of processing pipelines that exploit as building blocks efficient implementations of ``low-level'' linear operators.</p>
<p>The main interest of this paradigm is to enable the construction of processing pipelines that exploit as building blocks efficient implementations of ``low-level'' linear operators.</p>
<h2 id="This-notebook">This notebook<a class="anchor-link" href="#This-notebook">¶</a></h2><p>In this notebook we shall see how to create a <code>LazyLinearOp</code> instance, create more complex instances using various lazy operations, and finally how to apply the resulting instance on vectors or matrices. We assume the reader is familiar with at least <code>numpy</code> arrays and their operations.</p>
<h3 id="1.-Creating-a-LazyLinearOp">1. Creating a LazyLinearOp<a class="anchor-link" href="#1.-Creating-a-LazyLinearOp">¶</a></h3><p>In order to create this kind of object, you simply need to use the <code>asLazyLinearOp</code> function. This function receives an object that represents a linear operator, for instance a <code>Faust</code> (but it can also be a <code>numpy</code> array or a <code>scipy</code> matrix). The function instantiates a <code>LazyLinearOp</code> that encapsulates the <code>Faust</code> you gave.</p>
<h3 id="1.-How-to-create-and-use-a-LazyLinearOp">1. How to create and use a LazyLinearOp<a class="anchor-link" href="#1.-How-to-create-and-use-a-LazyLinearOp">¶</a></h3><p>In order to create this kind of object, you simply need to use the <code>aslazylinearoperator</code> function. This function receives an object that represents a linear operator, for instance a <code>Faust</code> (but it can also be a <code>numpy</code> array or a <code>scipy</code> matrix). Besides, note that there is another way to create a LazyLinearOp using the kind of functions we call matmat or matvec as explained in 4.3 with the FFT use case.</p>
<p>In the example below, the function <code>aslazylinearoperator</code> allows us to instantiate a <code>LazyLinearOp</code> that encapsulates a <code>Faust</code>.</p>
<p>The LazyLinearOp kron function is much faster! Indeed, it is optimized for <code>LazyLinearOp-s</code>.</p>
<h4 id="4.3-The-FFT-and-its-inverse-as-a-LazyLinearOp">4.3 The FFT and its inverse as a LazyLinearOp<a class="anchor-link" href="#4.3-The-FFT-and-its-inverse-as-a-LazyLinearOp">¶</a></h4><p>Now let's explain how it is possible to create a <code>LazyLinearOp</code> not using a pre-defined operator like a Faust or a numpy array but a function that defines how to apply the operator on a vector (the kind of function we name matvec) or on a matrix (in which case the function is named matmat). Actually, this process mimics the scipy <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html">LinearOperator</a> constructor, so it works pretty the same for a <code>LazyLinearOp</code> as we show in the example below for an operator that represents the FFT.</p>
<p>Hence, <code>lfft</code> is a <code>LazyLinearOp</code> defined upon the scipy <code>fft</code> and <code>ifft</code> functions. Here <code>fft</code> is the matvec function, it defines how to apply the <code>lfft</code> operator to a vector. Likewise, the <code>ifft</code>, as a <code>rmatvec</code> function, defines how to apply the inverse of the lfft operator to a vector.
The operator can totally be applied on matrices too. So, since we choose to apply the 1D FFT on columns instead of rows we set the axis argument of scipy fft to 0. The reason of the scaling by n of the <code>ifft</code> is to find on the scipy documentation <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.fft.fft.html#scipy.fft.fft">fft doc.</a> (look at the norm argument). For more details about the <code>LazyLinearOperator</code> constructor, please look at the <a href="https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/namespacepyfaust_1_1lazylinop.html">API documentation</a>.</p>
<p>We can compare this <code>lfft</code> operator to the equivalent operator based this time on the DFT Faust.</p>
<p>This notebook comes to its end. We've seen quickly how to create and evaluate <code>LazyLinearOp</code> objects based on numpy arrays, scipy matrices, or a Faust objects. We've seen a bunch of operations we can call on this kind of objects. For more information about <code>LazyLinearOp</code> objects you can take a look to the API documentation <a href="https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/namespacepyfaust_1_1lazylinop.html">here</a>.</p>
<p>This notebook comes to its end. We've seen quickly how to create and evaluate <code>LazyLinearOp</code> objects based on numpy arrays, scipy matrices, or a Faust objects. We've also seen how to define them upon <code>matmat</code> and <code>matvec</code> functions. We've tried a bunch of operations we can call on this kind of objects. For more information about <code>LazyLinearOp</code> objects you can take a look to the API documentation <a href="https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/namespacepyfaust_1_1lazylinop.html">here</a>.</p>
<p><strong>NOTE</strong>: this notebook was executed using the pyfaust version:</p>