Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cc73164f authored by hhakim's avatar hhakim
Browse files

Review/doctest matfaust.poly and add it to doctest ci job.

parent 435c733c
Branches
Tags
No related merge requests found
......@@ -186,7 +186,7 @@ doctest_nightly_matfaust:
- rm -Rf build
# all is set to doctest matfaust
# no -nojvm because it's needed for Faust.imagesc doctest
- 'for S in Faust proj.sp proj.splin proj.spcol proj.splincol proj.const proj.supp proj.normlin proj.normcol proj.blockdiag proj.anticirc proj.circ proj.hankel proj.skperm proj.sptriu proj.sptril proj.spsymm proj.toeplitz proj.proj_id; do if matlab -nodisplay -r "addpath /usr/share/octave/packages/doctest-0.7.0/; setup_FAUST; doctest matfaust.$S; exit;" | tee /tmp/matlab_doctest_$ | grep FAIL; then exit 1; else exit 0; fi; done'
- 'for S in Faust proj.sp proj.splin proj.spcol proj.splincol proj.const proj.supp proj.normlin proj.normcol proj.blockdiag proj.anticirc proj.circ proj.hankel proj.skperm proj.sptriu proj.sptril proj.spsymm proj.toeplitz proj.proj_id poly.poly poly.expm_multiply poly.next poly.basis poly.expm_inv_multiply; do if matlab -nodisplay -r "addpath /usr/share/octave/packages/doctest-0.7.0/; setup_FAUST; doctest matfaust.$S; exit;" | tee /tmp/matlab_doctest_$ | grep FAIL; then exit 1; else exit 0; fi; done'
after_script:
- if [ $(rpm -qa faust | wc -l) -gt 0 ]; then sudo rpm -e faust;fi
only:
......
......@@ -18,29 +18,32 @@
%> >> L = L*L';
%> >> K = 3;
%> >> F = basis(L, K, 'chebyshev')
%> @endcode
%>
%> F =
%>
%> Faust size 200x50, density 0.6612, nnz_sum 6612, 4 factor(s):
%> - FACTOR 0 (real) SPARSE, size 200x150, density 0.0751333, nnz 2254
%> - FACTOR 1 (real) SPARSE, size 150x100, density 0.146933, nnz 2204
%> - FACTOR 2 (real) SPARSE, size 100x50, density 0.4208, nnz 2104
%> - FACTOR 3 (real) SPARSE, size 50x50, density 0.02, nnz 50
%> - FACTOR 0 (double) SPARSE, size 200x150, density 0.0751333, nnz 2254
%> - FACTOR 1 (double) SPARSE, size 150x100, density 0.146933, nnz 2204
%> - FACTOR 2 (double) SPARSE, size 100x50, density 0.4208, nnz 2104
%> - FACTOR 3 (double) SPARSE, size 50x50, density 0.02, nnz 50
%> identity matrix flag
%> @endcode
%>
%> By default, the 0-degree polynomial is the identity.
%> However it is possible to replace the corresponding matrix by any sparse matrix T0 of your choice (with the only constraint that size(T0,1) == size(L, 1)). In that purpose, do as follows:
%>
%> @code
%> >> T0 = sprand(50, 2, .3)
%> >> rng(42)
%> >> T0 = sprand(50, 2, .3);
%> >> F = basis(L, 3, 'chebyshev', 'T0', T0)
%> @endcode
%> F =
%>
%> Faust size 200x50, density 0.6612, nnz_sum 6612, 4 factor(s):
%> - FACTOR 0 (real) SPARSE, size 200x150, density 0.0751333, nnz 2254
%> - FACTOR 1 (real) SPARSE, size 150x100, density 0.146933, nnz 2204
%> - FACTOR 2 (real) SPARSE, size 100x50, density 0.4208, nnz 2104
%> - FACTOR 3 (real) SPARSE, size 50x2, density 0.23, nnz 23
%> Faust size 200x2, density 16.53, nnz_sum 6612, 4 factor(s):
%> - FACTOR 0 (double) SPARSE, size 200x150, density 0.0751333, nnz 2254
%> - FACTOR 1 (double) SPARSE, size 150x100, density 0.146933, nnz 2204
%> - FACTOR 2 (double) SPARSE, size 100x50, density 0.4208, nnz 2104
%> - FACTOR 3 (double) SPARSE, size 50x2, density 0.5, nnz 50
%> @endcode
%>
%>
%=======================================================================
......
%==============================================
%> @brief Computes an approximate of the action of the matrix exponential of A on B using series of Chebyshev polynomials.
%>
......@@ -16,19 +15,60 @@
%> @b Example
%> @code
%> % in a matlab terminal
%> >> rng(42)
%> >> import matfaust.poly.expm_multiply
%> >> L = sprand(5, 5, .2);
%> >> L = L*L';
%> >> x = rand(size(L,2), 1);
%> >> t = linspace(-.5, -.1, 3);
%> >> C = expm_multiply(L, x, t);
%> @endcode
%> >> C = expm_multiply(L, x, t)
%>
%> C(:,:,1) =
%>
%> 0.1796
%> 0.1706
%> 0.3698
%> 0.4223
%> 0.2662
%>
%> C(:,:,2) =
%>
%> 0.1809
%> 0.2164
%> 0.4254
%> 0.4261
%> 0.2748
%>
%> C(:,:,3) =
%>
%> 0.1825
%> 0.2721
%> 0.4893
%> 0.4300
%> 0.2852
%>
%> >> norm(C(:,:,1) - expm(t(1) * L) * x)
%>
%> C =
%> ans =
%>
%> 1.0194e-15
%>
%> >> norm(C(:,:,2) - expm(t(2) * L) * x)
%>
%> ans =
%>
%> 4.9763e-15
%>
%> >> norm(C(:,:,3) - expm(t(3) * L) * x)
%>
%> ans =
%>
%> 6.4160e-15
%>
%> >>
%> @endcode
%>
%> 0.1401 0.4218 0.9157 0.3332 0.2658
%> 0.1408 0.4218 0.9157 0.4620 0.4532
%> 0.1415 0.4218 0.9157 0.6580 0.7508
%> @b see @b also matlab builtin expm
%==============================================
function C = expm_multiply(A, B, t, varargin)
dev = 'cpu';
......
......@@ -15,18 +15,20 @@
%> @b Example
%> @code
%> >> import matfaust.poly.*
%> >> rng(42)
%> >> A = sprand(64, 64, .1);
%> >> A = A*A';
%> >> B = rand(size(A, 2), 2);
%> >> AinvB = invm_multiply(A, B, 'rel_err', 1e-6);
%> >> AinvB_ref = inv(full(A))*B;
%> >> err = norm(AinvB-AinvB_ref)/norm(AinvB)
%> @endcode
%>
%>err =
%> err =
%>
%> 8.5162e-11
%> 1.5364e-10
%>
%> >>
%> @endcode
%==============================================
function AinvB = invm_multiply(A, B, varargin)
dev = 'cpu';
......
......@@ -10,33 +10,35 @@
%> @code
%> % in a matlab terminal
%> >> import matfaust.poly.*
%> >> rng(42)
%> >> L = sprand(50, 50, .2);
%> >> L = L*L';
%> >> K = 3;
%> >> F = basis(L, K, 'chebyshev');
%> >> G = next(F);
%> >> F
%> @endcode
%>
%> F =
%>
%>Faust size 200x50, density 0.6672, nnz_sum 6672, 4 factor(s):
%>- FACTOR 0 (real) SPARSE, size 200x150, density 0.0758, nnz 2274
%>- FACTOR 1 (real) SPARSE, size 150x100, density 0.148267, nnz 2224
%>- FACTOR 2 (real) SPARSE, size 100x50, density 0.4248, nnz 2124
%>- FACTOR 3 (real) SPARSE, size 50x50, density 0.02, nnz 50
%> Faust size 200x50, density 0.6624, nnz_sum 6624, 4 factor(s):
%> - FACTOR 0 (double) SPARSE, size 200x150, density 0.0752667, nnz 2258
%> - FACTOR 1 (double) SPARSE, size 150x100, density 0.1472, nnz 2208
%> - FACTOR 2 (double) SPARSE, size 100x50, density 0.4216, nnz 2108
%> - FACTOR 3 (double) SPARSE, size 50x50, density 0.02, nnz 50
%> identity matrix flag
%>
%> @code
%> >> G
%> @endcode
%>
%> G =
%>
%> Faust size 250x50, density 0.71968, nnz_sum 8996, 5 factor(s):
%> - FACTOR 0 (real) SPARSE, size 250x200, density 0.04648, nnz 2324
%> - FACTOR 1 (real) SPARSE, size 200x150, density 0.0758, nnz 2274
%> - FACTOR 2 (real) SPARSE, size 150x100, density 0.148267, nnz 2224
%> - FACTOR 3 (real) SPARSE, size 100x50, density 0.4248, nnz 2124
%> - FACTOR 4 (real) SPARSE, size 50x50, density 0.02, nnz 50
%> Faust size 250x50, density 0.71456, nnz_sum 8932, 5 factor(s):
%> - FACTOR 0 (double) SPARSE, size 250x200, density 0.04616, nnz 2308
%> - FACTOR 1 (double) SPARSE, size 200x150, density 0.0752667, nnz 2258
%> - FACTOR 2 (double) SPARSE, size 150x100, density 0.1472, nnz 2208
%> - FACTOR 3 (double) SPARSE, size 100x50, density 0.4216, nnz 2108
%> - FACTOR 4 (double) SPARSE, size 50x50, density 0.02, nnz 50
%> identity matrix flag
%>
%> @endcode
%>
%======================================================================
......
%> @package matfaust.poly @brief The matfaust module for polynomial basis as Faust objects.
%> @note This module is still in BETA status.
%======================================================================
%> @brief Computes the linear combination of the polynomials defined by basis.
%>
......@@ -19,16 +16,19 @@
%> >> L = L*L';
%> >> coeffs = [.5 1 2 3];
%> >> G = poly(coeffs, 'chebyshev', 'L', L)
%> @endcode
%>
%> G =
%>
%> Faust size 50x50, density 0.3524, nnz_sum 881, 5 factor(s):
%> - FACTOR 0 (real) SPARSE, size 50x200, density 0.02, nnz 200
%> - FACTOR 1 (real) SPARSE, size 200x150, density 0.00923333, nnz 277
%> - FACTOR 2 (real) SPARSE, size 150x100, density 0.0151333, nnz 227
%> - FACTOR 3 (real) SPARSE, size 100x50, density 0.0254, nnz 127
%> - FACTOR 4 (real) SPARSE, size 50x50, density 0.02, nnz 50
%> Faust size 50x50, density 0.35, nnz_sum 875, 5 factor(s):
%> - FACTOR 0 (double) SPARSE, size 50x200, density 0.02, nnz 200
%> - FACTOR 1 (double) SPARSE, size 200x150, density 0.00916667, nnz 275
%> - FACTOR 2 (double) SPARSE, size 150x100, density 0.015, nnz 225
%> - FACTOR 3 (double) SPARSE, size 100x50, density 0.025, nnz 125
%> - FACTOR 4 (double) SPARSE, size 50x50, density 0.02, nnz 50
%> identity matrix flag
%>
%> >>
%> @endcode
%>
%> Which is equivalent to do as below (in two times):
%>
......@@ -36,39 +36,48 @@
%> >> K = 3;
%> >> F = basis(L, K, 'chebyshev');
%> >> G = poly(coeffs, F)
%> @endcode
%>
%> G =
%>
%> Faust size 50x50, density 0.3524, nnz_sum 881, 5 factor(s):
%> - FACTOR 0 (real) SPARSE, size 50x200, density 0.02, nnz 200
%> - FACTOR 1 (real) SPARSE, size 200x150, density 0.00923333, nnz 277
%> - FACTOR 2 (real) SPARSE, size 150x100, density 0.0151333, nnz 227
%> - FACTOR 3 (real) SPARSE, size 100x50, density 0.0254, nnz 127
%> - FACTOR 4 (real) SPARSE, size 50x50, density 0.02, nnz 50
%> Faust size 50x50, density 0.35, nnz_sum 875, 5 factor(s):
%> - FACTOR 0 (double) SPARSE, size 50x200, density 0.02, nnz 200
%> - FACTOR 1 (double) SPARSE, size 200x150, density 0.00916667, nnz 275
%> - FACTOR 2 (double) SPARSE, size 150x100, density 0.015, nnz 225
%> - FACTOR 3 (double) SPARSE, size 100x50, density 0.025, nnz 125
%> - FACTOR 4 (double) SPARSE, size 50x50, density 0.02, nnz 50
%> identity matrix flag
%>
%> >>
%> @endcode
%>
%> Above G is a Faust because F is too. Below the full array of the Faust F is passed, so an array is returned into GA.
%>
%> @code
%> GA = poly(coeffs, full(F));
%> ismatrix(GA)
%> @endcode
%> >> GA = poly(coeffs, full(F));
%> >> ismatrix(GA)
%>
%>ans =
%> ans =
%>
%> logical
%> logical
%>
%> 1
%> 1
%>
%> >>
%> @endcode
%>
%> But of course they are equal:
%>
%> @code
%> >> norm(GA-full(G))/(norm(GA))
%> @endcode
%> >> norm(GA-full(G))/(norm(GA)) < 1e-16
%>
%> ans =
%>
%> logical
%>
%>ans =
%> 1
%>
%> 8.8455e-17
%> >>
%> @endcode
%>
%======================================================================
function LC = poly(coeffs, basis, varargin)
......@@ -153,7 +162,7 @@ function LC = poly(coeffs, basis, varargin)
error('coeffs and basis dimensions must agree.')
end
d = floor(size(basis,1) / (K+1));
if(size(coeffs, 2) == 1)
if(size(coeffs, 1) == 1)
if(is_real)
if(is_float)
LC = mexPolyRealFloat('polyMatrix', d, K, size(basis,2), coeffs, basis, on_gpu);
......@@ -178,3 +187,7 @@ function LC = poly(coeffs, basis, varargin)
% LC is a matrix
end
end
%> @package matfaust.poly @brief The matfaust module for polynomial basis as Faust objects.
%> @note This module is still in BETA status.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment