Skip to content

Commit

Permalink
Made it possible to copy from const vectors into non-const ones. (#110)
Browse files Browse the repository at this point in the history
In the previous version of the code one would always have to start copies
from non-const host containers. Which was very far from ideal...

Added explicit tests for making sure that these types of copies would be
possible from now on.
  • Loading branch information
krasznaa authored Sep 29, 2021
1 parent 04d7c65 commit f119d40
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 84 deletions.
47 changes: 24 additions & 23 deletions core/include/vecmem/utils/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// System include(s).
#include <cstddef>
#include <type_traits>
#include <vector>

namespace vecmem {
Expand Down Expand Up @@ -66,14 +67,14 @@ class copy {

/// Copy a 1-dimensional vector to the specified memory resource
template <typename TYPE>
data::vector_buffer<TYPE> to(const data::vector_view<TYPE>& data,
memory_resource& resource,
type::copy_type cptype = type::unknown);
data::vector_buffer<std::remove_cv_t<TYPE>> to(
const data::vector_view<TYPE>& data, memory_resource& resource,
type::copy_type cptype = type::unknown);

/// Copy a 1-dimensional vector's data between two existing memory blocks
template <typename TYPE>
void operator()(const data::vector_view<TYPE>& from,
data::vector_view<TYPE>& to,
template <typename TYPE1, typename TYPE2>
void operator()(const data::vector_view<TYPE1>& from,
data::vector_view<TYPE2>& to,
type::copy_type cptype = type::unknown);

/// Copy a 1-dimensional vector's data into a vector object
Expand All @@ -98,40 +99,40 @@ class copy {

/// Copy a jagged vector to the specified memory resource
template <typename TYPE>
data::jagged_vector_buffer<TYPE> to(
data::jagged_vector_buffer<std::remove_cv_t<TYPE>> to(
const data::jagged_vector_view<TYPE>& data, memory_resource& resource,
memory_resource* host_access_resource = nullptr,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector to the specified memory resource
template <typename TYPE>
data::jagged_vector_buffer<TYPE> to(
data::jagged_vector_buffer<std::remove_cv_t<TYPE>> to(
const data::jagged_vector_buffer<TYPE>& data, memory_resource& resource,
memory_resource* host_access_resource = nullptr,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector's data between two existing allocations
template <typename TYPE>
void operator()(const data::jagged_vector_view<TYPE>& from,
data::jagged_vector_view<TYPE>& to,
template <typename TYPE1, typename TYPE2>
void operator()(const data::jagged_vector_view<TYPE1>& from,
data::jagged_vector_view<TYPE2>& to,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector's data between two existing allocations
template <typename TYPE>
void operator()(const data::jagged_vector_view<TYPE>& from,
data::jagged_vector_buffer<TYPE>& to,
template <typename TYPE1, typename TYPE2>
void operator()(const data::jagged_vector_view<TYPE1>& from,
data::jagged_vector_buffer<TYPE2>& to,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector's data between two existing allocations
template <typename TYPE>
void operator()(const data::jagged_vector_buffer<TYPE>& from,
data::jagged_vector_view<TYPE>& to,
template <typename TYPE1, typename TYPE2>
void operator()(const data::jagged_vector_buffer<TYPE1>& from,
data::jagged_vector_view<TYPE2>& to,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector's data between two existing allocations
template <typename TYPE>
void operator()(const data::jagged_vector_buffer<TYPE>& from,
data::jagged_vector_buffer<TYPE>& to,
template <typename TYPE1, typename TYPE2>
void operator()(const data::jagged_vector_buffer<TYPE1>& from,
data::jagged_vector_buffer<TYPE2>& to,
type::copy_type cptype = type::unknown);

/// Copy a jagged vector's data into a vector object
Expand Down Expand Up @@ -167,9 +168,9 @@ class copy {

private:
/// Helper function performing the copy of a jagged array/vector
template <typename TYPE>
void copy_views(std::size_t size, const data::vector_view<TYPE>* from,
data::vector_view<TYPE>* to, type::copy_type cptype);
template <typename TYPE1, typename TYPE2>
void copy_views(std::size_t size, const data::vector_view<TYPE1>* from,
data::vector_view<TYPE2>* to, type::copy_type cptype);
/// Helper function for getting the sizes of a jagged vector/buffer
template <typename TYPE>
std::vector<typename data::vector_view<TYPE>::size_type> get_sizes(
Expand Down
Loading

0 comments on commit f119d40

Please sign in to comment.