Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linalg::Sum(const Tensor&) gives wrong answer for complex types #467

Open
IvanaGyro opened this issue Sep 13, 2024 · 0 comments
Open

linalg::Sum(const Tensor&) gives wrong answer for complex types #467

IvanaGyro opened this issue Sep 13, 2024 · 0 comments

Comments

@IvanaGyro
Copy link
Collaborator

The test below should pass.

#include "cuda_runtime_api.h"
#include "gtest/gtest.h"

#include "cytnx_error.hpp"
#include "linalg.hpp"
#include "Tensor.hpp"
#include "Type.hpp"

using namespace cytnx;

TEST(Linalg, Sum) {
  Tensor block(/* shape */ {5}, Type.ComplexDouble, Device.cuda, /* init_zero */ true);
  checkCudaErrors(cudaSetDevice(block.device()));
  block.fill(cytnx_complex128{2., 3.});
  Tensor sum_result = cytnx::linalg::Sum(block);
  checkCudaErrors(cudaDeviceSynchronize());

  EXPECT_EQ(sum_result.shape().size(), 1);
  EXPECT_EQ(sum_result.shape()[0], 1);
  EXPECT_DOUBLE_EQ(sum_result.at<cytnx_complex128>({0}).real(), 10.);
  EXPECT_DOUBLE_EQ(sum_result.at<cytnx_complex128>({0}).imag(), 15.);
}

However, the test fails.

[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Linalg
[ RUN      ] Linalg.Sum
test.cpp:20: Failure
Expected equality of these values:
  sum_result.at<cytnx_complex128>({0}).real()
    Which is: 0
  10.
    Which is: 10

test.cpp:21: Failure
Expected equality of these values:
  sum_result.at<cytnx_complex128>({0}).imag()
    Which is: 0
  15.
    Which is: 15

[  FAILED  ] Linalg.Sum (496 ms)
[----------] 1 test from Linalg (496 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (496 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Linalg.Sum

 1 FAILED TEST


0% tests passed, 1 tests failed out of 1

Total Test time (real) =   4.98 sec

This issue may be the culprit for failing the tests BlockUniTensorTest.gpu_Trace and DenseUniTensorTest.gpu_Trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant