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

Fix bug in comparing default tensor #184

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tensorwrapper/tensor/tensor_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void Tensor::swap(Tensor& other) noexcept { m_pimpl_.swap(other.m_pimpl_); }

bool Tensor::operator==(const Tensor& rhs) const noexcept {
if(has_pimpl_() != rhs.has_pimpl_()) return false;
if(!has_pimpl_()) return true; // Both don't have a PIMPL
return (*m_pimpl_) == (*rhs.m_pimpl_);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/cxx/unit_tests/tensorwrapper/tensor/tensor_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ TEST_CASE("Tensor") {
}

SECTION("operator==") {
REQUIRE(defaulted == Tensor{});

Tensor other_scalar(testing::smooth_scalar());
Tensor other_vector(testing::smooth_vector());
REQUIRE(scalar == other_scalar);
Expand Down
Loading