Skip to content

Commit

Permalink
Merge pull request #3229 from ChuckHastings/fea_move_search_part2
Browse files Browse the repository at this point in the history
[REVIEW] Define and implement new search APIs
  • Loading branch information
harrism authored Nov 19, 2019
2 parents 122e6b0 + d06b092 commit d640dd8
Show file tree
Hide file tree
Showing 9 changed files with 1,957 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- PR #3278 Add `to_host` utility to copy `column_view` to host
- PR #3087 Add new cudf::experimental bool8 wrapper
- PR #3219 Construct column from column_view
- PR #3229 Define and implement new search APIs
- PR #3308 java add API for memory usage callbacks
- PR #2691 Row-wise reduction and scan operations via CuPy
- PR #3291 Add normalize_nans_and_zeros
Expand Down
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ add_library(cudf
src/filling/legacy/repeat.cu
src/filling/legacy/tile.cu
src/search/legacy/search.cu
src/search/search.cu
src/column/column.cu
src/column/column_view.cpp
src/column/column_device_view.cu
Expand Down
7 changes: 6 additions & 1 deletion cpp/include/cudf/scalar/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,18 @@ class fixed_width_scalar : public scalar {
*
* @param stream The CUDA stream to do the operation in
*/
T value(cudaStream_t stream = 0) { return _data.value(stream); }
T value(cudaStream_t stream = 0) const { return _data.value(stream); }

/**
* @brief Returns a raw pointer to the value in device memory
*/
T* data() { return _data.data(); }

/**
* @brief Returns a raw pointer to the value in device memory
*/
T const* data() const { return _data.data(); }

protected:
rmm::device_scalar<T> _data{}; ///< device memory containing the value

Expand Down
135 changes: 135 additions & 0 deletions cpp/include/cudf/search.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2019, 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.
*/

#pragma once

#include <cudf/types.hpp>
#include <cudf/column/column.hpp>
#include <cudf/scalar/scalar.hpp>
#include <cudf/table/table.hpp>

#include <vector>

namespace cudf {
namespace experimental {

/**---------------------------------------------------------------------------*
* @brief Find smallest indices in a sorted table where values should be
* inserted to maintain order
*
* For each row v in @p values, find the first index in @p t where
* inserting the row will maintain the sort order of @p t
*
* Example:
*
* Single column:
* idx 0 1 2 3 4
* column = { 10, 20, 20, 30, 50 }
* values = { 20 }
* result = { 1 }
*
* Multi Column:
* idx 0 1 2 3 4
* t = {{ 10, 20, 20, 20, 20 },
* { 5.0, .5, .5, .7, .7 },
* { 90, 77, 78, 61, 61 }}
* values = {{ 20 },
* { .7 },
* { 61 }}
* result = { 3 }
*
* @param t Table to search
* @param values Find insert locations for these values
* @param column_order Vector of column sort order
* @param null_precedence Vector of null_precedence enums
* values
* @param mr Device memory resource to use for device memory allocation
* @return std::unique_ptr<column> A non-nullable column of cudf::size_type elements
* containing the insertion points.
*---------------------------------------------------------------------------**/
std::unique_ptr<column> lower_bound(table_view const& t,
table_view const& values,
std::vector<order> const& column_order,
std::vector<null_order> const& null_precedence,
rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

/**---------------------------------------------------------------------------*
* @brief Find largest indices in a sorted table where values should be
* inserted to maintain order
*
* For each row v in @p values, find the last index in @p t where
* inserting the row will maintain the sort order of @p t
*
* Example:
*
* Single Column:
* idx 0 1 2 3 4
* column = { 10, 20, 20, 30, 50 }
* values = { 20 }
* result = { 3 }
*
* Multi Column:
* idx 0 1 2 3 4
* t = {{ 10, 20, 20, 20, 20 },
* { 5.0, .5, .5, .7, .7 },
* { 90, 77, 78, 61, 61 }}
* values = {{ 20 },
* { .7 },
* { 61 }}
* result = { 5 * *
* @param column Table to search
* @param values Find insert locations for these values
* @param column_order Vector of column sort order
* @param null_precedence Vector of null_precedence enums
* values
* @param mr Device memory resource to use for device memory allocation
* @return std::unique_ptr<column> A non-nullable column of cudf::size_type elements
* containing the insertion points.
*---------------------------------------------------------------------------**/
std::unique_ptr<column> upper_bound(table_view const& t,
table_view const& values,
std::vector<order> const& column_order,
std::vector<null_order> const& null_precedence,
rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

/**---------------------------------------------------------------------------*
* @brief Find if the `value` is present in the `col`
*
* @throws cudf::logic_error
* If `col.type() != values.type()`
*
* @example:
*
* Single Column:
* idx 0 1 2 3 4
* col = { 10, 20, 20, 30, 50 }
* Scalar:
* value = { 20 }
* result = true
*
* @param col A column object
* @param value A scalar value to search for in `col`
* @param mr Device memory resource to use for device memory allocation
*
* @return bool If `value` is found in `column` true, else false.
*---------------------------------------------------------------------------**/
bool contains(column_view const& col, scalar const& value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

} // namespace experimental
} // namespace cudf


6 changes: 3 additions & 3 deletions cpp/include/cudf/table/table_device_view.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class table_device_view_base {

__device__ ColumnDeviceView const& column(size_type column_index) const
noexcept {
assert(column_index > 0);
assert(column_index >= 0);
assert(column_index < _num_columns);
return _columns[column_index];
}

__device__ ColumnDeviceView& column(size_type column_index) noexcept {
assert(column_index > 0);
assert(column_index >= 0);
assert(column_index < _num_columns);
return _columns[column_index];
}
Expand Down Expand Up @@ -104,4 +104,4 @@ class mutable_table_device_view
mutable_table_view>(source_view,
stream) {}
};
} // namespace cudf
} // namespace cudf
Loading

0 comments on commit d640dd8

Please sign in to comment.