table.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cudf/column/column.hpp>
20 
21 #include <rmm/cuda_stream_view.hpp>
22 
23 #include <memory>
24 #include <vector>
25 
31 namespace cudf {
32 
38 class table {
39  public:
40  table() = default;
41  ~table() = default;
42  table(table&&) = default;
43  table& operator=(table const&) = delete;
44  table& operator=(table&&) = delete;
45 
49  table(table const& other);
50 
58  table(std::vector<std::unique_ptr<column>>&& columns);
59 
68  rmm::cuda_stream_view stream = rmm::cuda_stream_default,
69  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
70 
74  size_type num_columns() const noexcept { return _columns.size(); }
75 
79  size_type num_rows() const noexcept { return _num_rows; }
80 
85  table_view view() const;
86 
91  operator table_view() const { return this->view(); };
92 
98 
103  operator mutable_table_view() { return this->mutable_view(); };
104 
111  std::vector<std::unique_ptr<column>> release();
112 
125  template <typename InputIterator>
126  table_view select(InputIterator begin, InputIterator end) const
127  {
128  std::vector<column_view> columns(std::distance(begin, end));
130  begin, end, columns.begin(), [this](auto index) { return _columns.at(index)->view(); });
131  return table_view(columns);
132  }
133 
144  table_view select(std::vector<cudf::size_type> const& column_indices) const
145  {
146  return select(column_indices.begin(), column_indices.end());
147  };
148 
158  column& get_column(cudf::size_type column_index) { return *(_columns.at(column_index)); }
159 
169  column const& get_column(cudf::size_type i) const { return *(_columns.at(i)); }
170 
171  private:
172  std::vector<std::unique_ptr<column>> _columns{};
173  size_type _num_rows{};
174 };
175 
176 } // namespace cudf
cudf::mutable_table_view
A set of mutable_column_views of the same size.
Definition: table_view.hpp:222
table_view.hpp
Class definitions for (mutable)_table_view
cudf::column
A container of nullable device data as a column of elements.
Definition: column.hpp:45
cudf::table::table
table(table_view view, rmm::cuda_stream_view stream=rmm::cuda_stream_default, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Copy the contents of a table_view to construct a new table.
column.hpp
Class definition for cudf::column.
cudf::table::table
table(std::vector< std::unique_ptr< column >> &&columns)
Moves the contents from a vector of unique_ptrs to columns to construct a new table.
rmm::cuda_stream_view
cudf::table
A set of cudf::column's of the same size.
Definition: table.hpp:38
cudf::table::select
table_view select(std::vector< cudf::size_type > const &column_indices) const
Returns a table_view with set of specified columns.
Definition: table.hpp:144
cudf::table::num_columns
size_type num_columns() const noexcept
Returns the number of columns in the table.
Definition: table.hpp:74
cudf::table_view
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:154
cudf::table::mutable_view
mutable_table_view mutable_view()
Returns a mutable, non-owning mutable_table_view of the contents of this table.
cudf::table::table
table(table const &other)
Construct a new table by copying the contents of another table.
cudf::transform
std::unique_ptr< column > transform(column_view const &input, std::string const &unary_udf, data_type output_type, bool is_ptx, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Creates a new column by applying a unary function against every element of an input column.
cudf::table::view
table_view view() const
Returns an immutable, non-owning table_view of the contents of this table.
cudf::table::get_column
column & get_column(cudf::size_type column_index)
Returns a reference to the specified column.
Definition: table.hpp:158
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::table::get_column
column const & get_column(cudf::size_type i) const
Returns a const reference to the specified column.
Definition: table.hpp:169
cudf::table::release
std::vector< std::unique_ptr< column > > release()
Releases ownership of the columns by returning a vector of unique_ptrs to the constituent columns.
cudf::table::select
table_view select(InputIterator begin, InputIterator end) const
Returns a table_view built from a range of column indices.
Definition: table.hpp:126
rmm::mr::device_memory_resource
cudf::distance
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:103
cudf::table::num_rows
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table.hpp:79