Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Sep 25, 2023
1 parent 3762076 commit 9ee12c0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cpp/src/binaryop/compiled/binary_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ namespace {
struct scalar_as_column_view {
using return_type = typename std::pair<column_view, std::unique_ptr<column>>;
template <typename T, CUDF_ENABLE_IF(is_fixed_width<T>())>
return_type operator()(scalar const& s, rmm::cuda_stream_view, rmm::mr::device_memory_resource*)
return_type operator()(scalar const& s,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource*)
{
auto& h_scalar_type_view = static_cast<cudf::scalar_type_t<T>&>(const_cast<scalar&>(s));
auto col_v = column_view(s.type(),
1,
h_scalar_type_view.data(),
reinterpret_cast<bitmask_type const*>(s.validity_data()),
!s.is_valid());
!s.is_valid(stream));
return std::pair{col_v, std::unique_ptr<column>(nullptr)};
}
template <typename T, CUDF_ENABLE_IF(!is_fixed_width<T>())>
Expand Down
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ ConfigureTest(
STREAM_IDENTIFICATION_TEST identify_stream_usage/test_default_stream_identification.cu
)

ConfigureTest(STREAM_BINARYOP_TEST streams/binaryop_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_CONCATENATE_TEST streams/concatenate_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_FILLING_TEST streams/filling_test.cpp STREAM_MODE testing)
Expand Down
61 changes: 61 additions & 0 deletions cpp/tests/streams/binaryop_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cudf/binaryop.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/scalar/scalar.hpp>

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>

class BinaryopTest : public cudf::test::BaseFixture {};

TEST_F(BinaryopTest, ColumnColumn)
{
cudf::test::fixed_width_column_wrapper<int32_t> lhs{10, 20, 30, 40, 50};
cudf::test::fixed_width_column_wrapper<int32_t> rhs{15, 25, 35, 45, 55};

cudf::binary_operation(lhs,
rhs,
cudf::binary_operator::ADD,
cudf::data_type(cudf::type_to_id<int32_t>()),
cudf::test::get_default_stream());
}

TEST_F(BinaryopTest, ColumnScalar)
{
cudf::test::fixed_width_column_wrapper<int32_t> lhs{10, 20, 30, 40, 50};
cudf::numeric_scalar<int32_t> rhs{23, true, cudf::test::get_default_stream()};

cudf::binary_operation(lhs,
rhs,
cudf::binary_operator::ADD,
cudf::data_type(cudf::type_to_id<int32_t>()),
cudf::test::get_default_stream());
}

TEST_F(BinaryopTest, ScalarColumn)
{
cudf::numeric_scalar<int32_t> lhs{42, true, cudf::test::get_default_stream()};
cudf::test::fixed_width_column_wrapper<int32_t> rhs{15, 25, 35, 45, 55};

cudf::binary_operation(lhs,
rhs,
cudf::binary_operator::ADD,
cudf::data_type(cudf::type_to_id<int32_t>()),
cudf::test::get_default_stream());
}

0 comments on commit 9ee12c0

Please sign in to comment.