text: //=======================================================================
  // Copyright (c) 2017 Baptiste Wicht
  // Distributed under the terms of the MIT License.
  // (See accompanying file LICENSE or copy at
  //  http://opensource.org/licenses/MIT)
  //=======================================================================
  
  #include "test.hpp"
  
  TEST_CASE("conj/c/0", "[float][conj]") {
      const size_t N = 137;
  
      std::complex<float>* x_cpu = new std::complex<float>[N];
      std::complex<float>* y_cpu = new std::complex<float>[N];
  
      for (size_t i = 0; i < N; ++i) {
          x_cpu[i] = std::complex<float>(1.0f + i / 1000.0f, 1.0f * i);
      }
  
      std::complex<float>* x_gpu;
      std::complex<float>* y_gpu;
      cuda_check(cudaMalloc((void**)&x_gpu, N * sizeof(std::complex<float>)));
      cuda_check(cudaMalloc((void**)&y_gpu, N * sizeof(std::complex<float>)));
  
      cuda_check(cudaMemcpy(x_gpu, x_cpu, N * sizeof(std::complex<float>), cudaMemcpyHostToDevice));
      cuda_check(cudaMemcpy(y_gpu, y_cpu, N * sizeof(std::complex<float>), cudaMemcpyHostToDevice));
  
      egblas_cconj(N, make_cuComplex(1.0f, 0.0f), reinterpret_cast<cuComplex*>(x_gpu), 1, reinterpret_cast<cuComplex*>(y_gpu), 1);
  
      cuda_check(cudaMemcpy(y_cpu, y_gpu, N * sizeof(std::complex<float>), cudaMemcpyDeviceToHost));
  
      for (size_t i = 0; i < N; ++i) {
          REQUIRE(y_cpu[i] == TestComplex<float>(std::conj(std::complex<float>(1.0f + i / 1000.0f, 1.0f * i))));
      }
  
      cuda_check(cudaFree(x_gpu));
      cuda_check(cudaFree(y_gpu));
  
      delete[] x_cpu;
      delete[] y_cpu;
  }
  
  TEST_CASE("conj/c/1", "[float][conj]") {
      const size_t N = 338;
  
      std::complex<float>* x_cpu = new std::complex<float>[N];
      std::complex<float>* y_cpu = new std::complex<float>[N];
  
      for (size_t i = 0; i < N; ++i) {
          x_cpu[i] = std::complex<float>(i / 998.0f, -2.0f * i);
      }
  
      std::complex<float>* x_gpu;
      std::complex<float>* y_gpu;
      cuda_check(cudaMalloc((void**)&x_gpu, N * sizeof(std::complex<float>)));
      cuda_check(cudaMalloc((void**)&y_gpu, N * sizeof(std::complex<float>)));
  
      cuda_check(cudaMemcpy(x_gpu, x_cpu, N * sizeof(std::complex<float>), cudaMemcpyHostToDevice));
      cuda_check(cudaMemcpy(y_gpu, y_cpu, N * sizeof(std::complex<float>), cudaMemcpyHostToDevice));
  
      egblas_cconj(N, make_cuComplex(1.0f, 1.0f), reinterpret_cast<cuComplex*>(x_gpu), 1, reinterpret_cast<cuComplex*>(y_gpu), 1);
  
      cuda_check(cudaMemcpy(y_cpu, y_gpu, N * sizeof(std::complex<float>), cudaMemcpyDeviceToHost));
  
      for (size_t i = 0; i < N; ++i) {
          REQUIRE(y_cpu[i] == TestComplex<float>(std::complex<float>(1.0f, 1.0f) * std::conj(std::complex<float>(i / 998.0f, -2.0f * i))));
      }
  
      cuda_check(cudaFree(x_gpu));
      cuda_check(cudaFree(y_gpu));
  
      delete[] x_cpu;
      delete[] y_cpu;
  }
  
  TEST_CASE("conj/z/0", "[double][conj]") {
      const size_t N = 137;
  
      std::complex<double>* x_cpu = new std::complex<double>[N];
      std::complex<double>* y_cpu = new std::complex<double>[N];
  
      for (size_t i = 0; i < N; ++i) {
          x_cpu[i] = std::complex<double>(i / 999.0, -1.1 * i);
      }
  
      std::complex<double>* x_gpu;
      std::complex<double>* y_gpu;
      cuda_check(cudaMalloc((void**)&x_gpu, N * sizeof(std::complex<double>)));
      cuda_check(cudaMalloc((void**)&y_gpu, N * sizeof(std::complex<double>)));
  
      cuda_check(cudaMemcpy(x_gpu, x_cpu, N * sizeof(std::complex<double>), cudaMemcpyHostToDevice));
      cuda_check(cudaMemcpy(y_gpu, y_cpu, N * sizeof(std::complex<double>), cudaMemcpyHostToDevice));
  
      egblas_zconj(N, make_cuDoubleComplex(1.0, 0.0), reinterpret_cast<cuDoubleComplex*>(x_gpu), 1, reinterpret_cast<cuDoubleComplex*>(y_gpu), 1);
  
      cuda_check(cudaMemcpy(y_cpu, y_gpu, N * sizeof(std::complex<double>), cudaMemcpyDeviceToHost));
  
      for (size_t i = 0; i < N; ++i) {
          REQUIRE(y_cpu[i] == TestComplex<double>(std::conj(std::complex<double>(i / 999.0, -1.1 * i))));
      }
  
      cuda_check(cudaFree(x_gpu));
      cuda_check(cudaFree(y_gpu));
  
      delete[] x_cpu;
      delete[] y_cpu;
  }
  
  TEST_CASE("conj/z/1", "[double][conj]") {
      const size_t N = 338;
  
      std::complex<double>* x_cpu = new std::complex<double>[N];
      std::complex<double>* y_cpu = new std::complex<double>[N];
  
      for (size_t i = 0; i < N; ++i) {
          x_cpu[i] = std::complex<double>(i / 996.0, -2.4 * i);
      }
  
      std::complex<double>* x_gpu;
      std::complex<double>* y_gpu;
      cuda_check(cudaMalloc((void**)&x_gpu, N * sizeof(std::complex<double>)));
      cuda_check(cudaMalloc((void**)&y_gpu, N * sizeof(std::complex<double>)));
  
      cuda_check(cudaMemcpy(x_gpu, x_cpu, N * sizeof(std::complex<double>), cudaMemcpyHostToDevice));
      cuda_check(cudaMemcpy(y_gpu, y_cpu, N * sizeof(std::complex<double>), cudaMemcpyHostToDevice));
  
      egblas_zconj(N, make_cuDoubleComplex(0.1, 2.0), reinterpret_cast<cuDoubleComplex*>(x_gpu), 1, reinterpret_cast<cuDoubleComplex*>(y_gpu), 1);
  
      cuda_check(cudaMemcpy(y_cpu, y_gpu, N * sizeof(std::complex<double>), cudaMemcpyDeviceToHost));
  
      for (size_t i = 0; i < N; ++i) {
          REQUIRE(y_cpu[i] == TestComplex<double>(std::complex<double>(0.1, 2.0) * std::conj(std::complex<double>(i / 996.0, -2.4 * i))));
      }
  
      cuda_check(cudaFree(x_gpu));
      cuda_check(cudaFree(y_gpu));
  
      delete[] x_cpu;
      delete[] y_cpu;
  }
  