41 throw std::invalid_argument(
"File is not opened");
47 template<
typename ScalarType>
51 throw std::invalid_argument(
"File is not opened");
53 boost::numeric::ublas::matrix<ScalarType> h_A(A.
size1(), A.
size2());
55 for (std::size_t i = 0; i < h_A.size1(); i++)
57 for (std::size_t j = 0; j < h_A.size2(); j++)
69 template<
typename ScalarType>
73 throw std::invalid_argument(
"File is not opened");
75 for (std::size_t i = 0; i < v.size(); i++)
84 template<
typename ScalarType>
87 for (std::size_t i = 0; i < in.size(); i++)
88 in[i] = static_cast<ScalarType>(rand()) /
ScalarType(RAND_MAX);
92 template<
typename ScalarType>
97 std::vector<ScalarType> aA(A.
size1() * A.
size2());
100 for (std::size_t i = 0; i < A.
size1(); i++)
102 for (std::size_t j = 0; j < A.
size2(); j++)
105 if ((fabs(val) > EPS) && (i != j) && ((i + 1) != j))
107 std::cout <<
"Failed at " << i <<
" " << j <<
" " << val << std::endl;
116 template<
typename ScalarType>
129 for (std::size_t i = 0; i < res_std.size(); i++)
131 diff =
std::max(diff, std::abs(res_std[i] - ref_std[i]));
139 template<
typename ScalarType>
141 std::vector<ScalarType>& ref)
143 std::vector<ScalarType> res_std(ref.size());
145 for (std::size_t i = 0; i < ref.size(); i++)
146 res_std[i] = res(i, i);
148 std::sort(ref.begin(), ref.end());
149 std::sort(res_std.begin(), res_std.end());
153 for (std::size_t i = 0; i < ref.size(); i++)
155 diff =
std::max(diff, std::abs(res_std[i] - ref[i]));
163 template<
typename ScalarType>
166 std::size_t sz1, sz2;
175 std::fstream f(fn.c_str(), std::fstream::in);
179 std::size_t to =
std::min(sz1, sz2);
184 std::vector<ScalarType> sigma_ref(to);
200 double time_spend = timer.
get();
209 bool sigma_ok = (fabs(sigma_diff) <
EPS)
210 && (fabs(prods_diff) < std::sqrt(EPS));
212 printf(
"%6s [%dx%d] %40s sigma_diff = %.6f; prod_diff = %.6f; time = %.6f\n", sigma_ok?
"[[OK]]":
"[FAIL]", (
int)Aref.size1(), (int)Aref.size2(), fn.c_str(), sigma_diff, prods_diff, time_spend);
218 template<
typename ScalarType>
223 std::vector<ScalarType> in(Ai.internal_size1() * Ai.internal_size2());
234 double time_spend = timer.get();
236 printf(
"[%dx%d] time = %.6f\n", static_cast<int>(sz1), static_cast<int>(sz2), time_spend);
240 template<
typename ScalarType>
244 test_svd<ScalarType>(std::string(
"../examples/testdata/svd/qr.example"), epsilon);
245 test_svd<ScalarType>(std::string(
"../examples/testdata/svd/wiki.example"), epsilon);
246 test_svd<ScalarType>(std::string(
"../examples/testdata/svd/wiki.qr.example"), epsilon);
247 test_svd<ScalarType>(std::string(
"../examples/testdata/svd/pysvd.example"), epsilon);
248 test_svd<ScalarType>(std::string(
"../examples/testdata/svd/random.example"), epsilon);
250 time_svd<ScalarType>(500, 500);
251 time_svd<ScalarType>(1024, 1024);
252 time_svd<ScalarType>(2048, 512);
264 std::cout << std::endl;
265 std::cout <<
"----------------------------------------------" << std::endl;
266 std::cout <<
"----------------------------------------------" << std::endl;
267 std::cout <<
"## Test :: Singular Value Decomposition" << std::endl;
268 std::cout <<
"----------------------------------------------" << std::endl;
269 std::cout <<
"----------------------------------------------" << std::endl;
270 std::cout << std::endl;
272 int retval = EXIT_SUCCESS;
274 std::cout << std::endl;
275 std::cout <<
"----------------------------------------------" << std::endl;
276 std::cout << std::endl;
279 NumericT epsilon =
NumericT(1.0E-4);
280 std::cout <<
"# Testing setup:" << std::endl;
281 std::cout <<
" eps: " << epsilon << std::endl;
282 std::cout <<
" numeric: float" << std::endl;
283 retval = test<NumericT>(epsilon);
284 if ( retval == EXIT_SUCCESS )
285 std::cout <<
"# Test passed" << std::endl;
289 std::cout << std::endl;
290 std::cout <<
"----------------------------------------------" << std::endl;
291 std::cout << std::endl;
296 NumericT epsilon = 1.0E-6;
297 std::cout <<
"# Testing setup:" << std::endl;
298 std::cout <<
" eps: " << epsilon << std::endl;
299 std::cout <<
" numeric: double" << std::endl;
300 retval = test<NumericT>(epsilon);
301 if ( retval == EXIT_SUCCESS )
302 std::cout <<
"# Test passed" << std::endl;
306 std::cout << std::endl;
307 std::cout <<
"----------------------------------------------" << std::endl;
308 std::cout << std::endl;
311 std::cout << std::endl;
312 std::cout <<
"------- Test completed --------" << std::endl;
313 std::cout << std::endl;
void read_vector_body(std::fstream &f, std::vector< ScalarType > &v)
void time_svd(std::size_t sz1, std::size_t sz2)
size_type internal_size() const
Returns the total amount of allocated memory in multiples of sizeof(NumericT)
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
void read_matrix_body(std::fstream &f, viennacl::matrix< ScalarType > &A)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
void random_fill(std::vector< ScalarType > &in)
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
T max(const T &lhs, const T &rhs)
Maximum.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
void svd(viennacl::matrix< SCALARTYPE, row_major, ALIGNMENT > &A, viennacl::matrix< SCALARTYPE, row_major, ALIGNMENT > &QL, viennacl::matrix< SCALARTYPE, row_major, ALIGNMENT > &QR)
Computes the singular value decomposition of a matrix A. Experimental in 1.3.x.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
ScalarType sigmas_compare(viennacl::matrix< ScalarType > &res, std::vector< ScalarType > &ref)
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
size_type size2() const
Returns the number of columns.
size_type size1() const
Returns the number of rows.
Provides singular value decomposition using a block-based approach. Experimental. ...
A simple, yet (mostly) sufficiently accurate timer for benchmarking and profiling.
void test_svd(const std::string &fn, ScalarType EPS)
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
T min(const T &lhs, const T &rhs)
Minimum.
int test(ScalarType epsilon)
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
void read_matrix_size(std::fstream &f, std::size_t &sz1, std::size_t &sz2)
bool check_bidiag(viennacl::matrix< ScalarType > &A)
ScalarType matrix_compare(viennacl::matrix< ScalarType > &res, viennacl::matrix< ScalarType > &ref)
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)