Skip to content

Comparing actual tensor against empty reference tensor passes #107

@hjjvandam

Description

@hjjvandam

By accident I discovered that this test:

#include <catch2/catch.hpp>
#include <simde/simde.hpp>

TEST_CASE("allclose") {
    using tensor_t = simde::type::tensor;
    tensor_t t1{{1.0, 1.0}, {1.0, 1.0}};
    auto l = [&](const auto& lo, const auto& hi, auto* tile) {
    };
    using field_t   = typename simde::type::tensor::field_type;
    using shape_t   = typename simde::type::tensor::shape_type;
    using extents_t = typename shape_t::extents_type;
    extents_t extents{2,2};
    tensor_t t2(l,
                std::make_unique<shape_t>(extents),
                tensorwrapper::tensor::default_allocator<field_t>());
    SECTION("reference tensor empty, actual non-empty") {
        REQUIRE_FALSE(tensorwrapper::tensor::allclose(t1,t2));
    }
    SECTION("actual tensor empty, reference non-empty") {
        REQUIRE_FALSE(tensorwrapper::tensor::allclose(t2,t1));
    }
} 

fails in the instance where the reference tensor is empty. I.e. adding this test to SCF/tests I got

$ ./test_scf "allclose"
Filters: allclose

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_scf is a Catch v2.13.9 host application.
Run with -? for options

-------------------------------------------------------------------------------
allclose
  reference tensor empty, actual non-empty
-------------------------------------------------------------------------------
/workspaces/NWChemEx-Project.nosync/SCF/tests/allclose.cpp:16
...............................................................................

/workspaces/NWChemEx-Project.nosync/SCF/tests/allclose.cpp:17: FAILED:
  REQUIRE_FALSE( tensorwrapper::tensor::allclose(t1,t2) )
with expansion:
  !true

===============================================================================
test cases: 1 | 1 failed
assertions: 2 | 1 passed | 1 failed

I would have thought that both tests should have detected that the tensors are different. Am I just mistaken?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions