Advertisement
Guest User

gemm test

a guest
Mar 23rd, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <opencv2/opencv.hpp>
  2. #include <opencv2/cudaarithm.hpp>
  3.  
  4. int main()
  5. {
  6.     try {
  7.         float a_in[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  8.         cv::Mat a(1, 9, CV_32FC1, a_in);
  9.         cv::Mat a_t(a.t());
  10.  
  11.         float b_in[9] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  12.         cv::Mat b(9, 1, CV_32FC1, b_in);
  13.         cv::Mat b_t(b.t());
  14.  
  15.         cv::Mat result, result_t;
  16.  
  17.         // Regular gemm
  18.         cv::gemm(a, b, 1.0, cv::Mat(), 0.0, result);
  19.         cv::gemm(a_t, b_t, 1.0, cv::Mat(), 0.0, result_t);
  20.  
  21.         std::cout << "result = " << result << std::endl;
  22.         std::cout << "result_t = " << result_t << std::endl;
  23.     } catch (cv::Exception& e) {
  24.         std::cerr << e.what();
  25.         return -1;
  26.     }
  27. }
  28.  
  29. /* Prints out:
  30.  
  31. result = [45]
  32. result_t = [1, 1, 1, 1, 1, 1, 1, 1, 1;
  33. 2, 2, 2, 2, 2, 2, 2, 2, 2;
  34. 3, 3, 3, 3, 3, 3, 3, 3, 3;
  35. 4, 4, 4, 4, 4, 4, 4, 4, 4;
  36. 5, 5, 5, 5, 5, 5, 5, 5, 5;
  37. 6, 6, 6, 6, 6, 6, 6, 6, 6;
  38. 7, 7, 7, 7, 7, 7, 7, 7, 7;
  39. 8, 8, 8, 8, 8, 8, 8, 8, 8;
  40. 9, 9, 9, 9, 9, 9, 9, 9, 9]
  41.  
  42. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement