Commit c9511733 authored by Chao Liu's avatar Chao Liu
Browse files

refactoring Array

parent a289f7b2
......@@ -9,12 +9,20 @@ namespace ck {
template <index_t N>
using MultiIndex = Array<index_t, N>;
#if 1 // works
template <typename... Xs>
__host__ __device__ constexpr auto make_multi_index(const Xs&... xs)
{
return make_array<index_t>(xs...);
return make_array<const index_t>(std::forward<const Xs>(xs)...);
}
#else
template <typename... Xs>
__host__ __device__ constexpr auto make_multi_index(Xs&&... xs)
{
return make_array<const index_t>(std::forward<const Xs>(xs)...);
}
#endif
#else
template <index_t N>
using MultiIndex = StaticallyIndexedArray<index_t, N>;
......
......@@ -41,13 +41,13 @@ struct NativeTensorCoordinate
template <typename... Xs>
__host__ __device__ constexpr NativeTensorCoordinate(Xs... xs)
: NativeTensorCoordinate(Index{xs...})
: NativeTensorCoordinate(make_multi_index(xs...))
{
}
template <index_t... Xs>
__host__ __device__ constexpr NativeTensorCoordinate(Sequence<Xs...>)
: NativeTensorCoordinate(Index{Xs...})
: NativeTensorCoordinate(make_mutli_index(Xs...))
{
}
......
......@@ -45,19 +45,12 @@ struct Array<TData, 0>
__host__ __device__ static constexpr index_t Size() { return 0; }
};
#if 1
template <typename X, typename... Xs>
__host__ __device__ constexpr auto make_array(const X& x, const Xs&... xs)
{
return Array<X, sizeof...(Xs) + 1>{{x, static_cast<X>(xs)...}};
}
#else
template <typename X, typename... Xs>
__host__ __device__ constexpr auto make_array(X&& x, Xs&&... xs)
{
return Array<remove_cv_t<remove_reference_t<X>>, sizeof...(Xs) + 1>{{x, xs...}};
using data_type = remove_cv_t<remove_reference_t<X>>;
return Array<data_type, sizeof...(Xs) + 1>{{std::forward<X>(x), std::forward<Xs>(xs)...}};
}
#endif
// make empty array
template <typename X>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment