/[escript]/branches/diaplayground/cusplibrary/testing/spectral_radius.cu
ViewVC logotype

Contents of /branches/diaplayground/cusplibrary/testing/spectral_radius.cu

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4955 - (show annotations)
Tue May 20 04:33:15 2014 UTC (5 years, 4 months ago) by caltinay
File size: 2264 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 #include <unittest/unittest.h>
2
3 #include <cusp/detail/spectral_radius.h>
4 #include <cusp/krylov/arnoldi.h>
5
6 #include <cusp/gallery/poisson.h>
7 #include <cusp/csr_matrix.h>
8 #include <cusp/array2d.h>
9
10 template <class MemorySpace>
11 void TestEstimateSpectralRadius(void)
12 {
13 // 2x2 diagonal matrix
14 {
15 cusp::csr_matrix<int, float, MemorySpace> A(2,2,2);
16 A.row_offsets[0] = 0;
17 A.row_offsets[1] = 1;
18 A.row_offsets[2] = 2;
19 A.column_indices[0] = 0;
20 A.column_indices[1] = 1;
21 A.values[0] = -5;
22 A.values[1] = 2;
23 float rho = 5.0;
24 ASSERT_EQUAL((std::abs(cusp::detail::estimate_spectral_radius(A) - rho) / rho) < 0.1f, true);
25 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius(A) - rho) / rho) < 0.1f, true);
26 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius_symmetric(A) - rho) / rho) < 0.1f, true);
27 ASSERT_EQUAL((std::abs(cusp::detail::disks_spectral_radius(A) - rho) / rho) < 0.1f, true);
28 }
29
30 // 2x2 Poisson problem
31 {
32 cusp::csr_matrix<int, float, MemorySpace> A; cusp::gallery::poisson5pt(A, 2, 2);
33 float rho = 6.0;
34 ASSERT_EQUAL((std::abs(cusp::detail::estimate_spectral_radius(A) - rho) / rho) < 0.1f, true);
35 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius(A) - rho) / rho) < 0.1f, true);
36 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius_symmetric(A) - rho) / rho) < 0.1f, true);
37 ASSERT_EQUAL((std::abs(cusp::detail::disks_spectral_radius(A) - rho) / rho) < 0.1f, true);
38 }
39
40 // 4x4 Poisson problem
41 {
42 cusp::csr_matrix<int, float, MemorySpace> A; cusp::gallery::poisson5pt(A, 4, 4);
43 float rho = 7.2360679774997871;
44 ASSERT_EQUAL((std::abs(cusp::detail::estimate_spectral_radius(A) - rho) / rho) < 0.1f, true);
45 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius(A) - rho) / rho) < 0.1f, true);
46 ASSERT_EQUAL((std::abs(cusp::detail::ritz_spectral_radius_symmetric(A) - rho) / rho) < 0.1f, true);
47 ASSERT_EQUAL((std::abs(cusp::detail::disks_spectral_radius(A) - rho) / rho) < 0.11f, true);
48 }
49
50 // TODO test larger sizes and non-symmetric matrices
51 }
52 DECLARE_HOST_DEVICE_UNITTEST(TestEstimateSpectralRadius);
53

  ViewVC Help
Powered by ViewVC 1.1.26