Skip to content

Commit

Permalink
Fix xilinx::partition_array constructors to have example to work
Browse files Browse the repository at this point in the history
Simplify and generalize the constructors from containers.
Deal better with initializer_list.
  • Loading branch information
keryell committed Feb 14, 2018
1 parent 46e7ac2 commit e4f62cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
41 changes: 21 additions & 20 deletions include/CL/sycl/vendor/Xilinx/partition_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <array>
#include <cstddef>
#include <type_traits>

/** \addtogroup Xilinx Xilinx vendor extensions
@{
Expand Down Expand Up @@ -190,30 +191,30 @@ struct partition_array {
}


/// A constructor from another array of the same size
template <typename SourceBasicType>
partition_array(const partition_array<PartitionType, Size,
SourceBasicType> &src)
: partition_array{ } {
std::copy_n(&src[0], Size, &(*this)[0]);
}


/// Construct an array from a std::array
template <typename SourceBasicType>
partition_array(const std::array<SourceBasicType, Size> &src)
: partition_array{ } {
std::copy_n(&src[0], Size, &(*this)[0]);
/// A constructor from some container
template <typename SomeContainer>
partition_array(const SomeContainer &src)
: partition_array { } {
/// \todo Find a way to specialize this with a safer
/// implementation when the size of src is at least constexpr
std::copy_n(std::begin(src), Size, begin());
}


/// Construct an array from initializer_list
template <typename SourceBasicType>
partition_array(std::initializer_list<SourceBasicType> l)
: partition_array{ } {
std::size_t i = 0;
for (auto itr = l.begin(); itr != l.end(); itr++)
(*this)[i++] = *itr;
template <typename SourceBasicType,
// Only use this constructor for a real element-oriented
// initializer_list we can assign, not for the case
// partition_array<> a = { some_other_array }
typename = std::enable_if_t<std::is_convertible<SourceBasicType,
ValueType>::value>>
constexpr partition_array(std::initializer_list<SourceBasicType> l)
: partition_array { } {
/// \todo Find a way to specialize this with a safer
/// implementation when the size of src is at least constexpr
/// This does not work...
/// static_assert(l.size() == Size);
std::copy_n(std::begin(l), Size, begin());
}


Expand Down
13 changes: 9 additions & 4 deletions tests/array_partition/array_partition.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;#include <array>
#include <array>
#include <CL/sycl.hpp>
#include <iostream>
#include <string>
Expand All @@ -23,7 +23,8 @@ void validateFunc (std::string name, ArrayType arr) {
std::cout << "Size: " << arr.size() << std::endl;

// Show partition type
std::cout << "Partition type: " << asInt(arr.get_partition_type()) << std::endl;
std::cout << "Partition type: " << asInt(arr.get_partition_type())
<< std::endl;

// Test iterator
std::cout << "Content from iterator: ";
Expand All @@ -33,8 +34,8 @@ void validateFunc (std::string name, ArrayType arr) {

// Test subscript operator
std::cout << "Content from operator: ";
for (int i = 0; i < arr.size(); i++)
std::cout << arr[i] << " ";
for (auto e : arr)
std::cout << e << " ";
std::cout << "\n";
}

Expand Down Expand Up @@ -66,6 +67,10 @@ int main() {
xilinx::partition::cyclic<SIZE, 1>> F { E };
validateFunc("F", F);

F = C;

validateFunc("FC", F);

// Block Partition for G
xilinx::partition_array<Type, SIZE,
xilinx::partition::block<SIZE, 1>> G;
Expand Down

0 comments on commit e4f62cb

Please sign in to comment.