-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove deprecated APIs * tensor type name * #include <climits> * move ttl::experimental::zip to upstream * fix namespace * fix namespace * use size_t in basic_allocator<R, cuda_memory> * size_t * show cuda error string (#88)
- Loading branch information
Showing
18 changed files
with
424 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#pragma once | ||
|
||
#if defined(__GNUC__) && !defined(__clang__) | ||
#pragma message("ttl::experimental::zip is error-prone, use with care!") | ||
#endif | ||
|
||
#include <array> | ||
#include <functional> | ||
#include <numeric> | ||
#include <tuple> | ||
|
||
namespace ttl | ||
{ | ||
namespace experimental | ||
{ | ||
namespace internal | ||
{ | ||
template <typename... Ts> | ||
class zipper_t | ||
{ | ||
static constexpr auto arity = sizeof...(Ts); | ||
|
||
const std::tuple<const Ts &...> ranges_; | ||
|
||
template <typename... Iters> | ||
class iterator | ||
{ | ||
std::tuple<Iters...> is_; | ||
|
||
template <size_t... Is> | ||
auto operator*(std::index_sequence<Is...>) | ||
{ | ||
return std::make_tuple(*std::get<Is>(is_)...); | ||
} | ||
|
||
template <typename... P> | ||
static void noop(const P &...) | ||
{ | ||
} | ||
|
||
template <typename Iter> | ||
int incr(Iter &i) | ||
{ | ||
++i; | ||
return 0; | ||
} | ||
|
||
template <size_t... Is> | ||
void _advance(std::index_sequence<Is...>) | ||
{ | ||
noop(incr(std::get<Is>(is_))...); | ||
} | ||
|
||
template <size_t... Is> | ||
bool neq(std::index_sequence<Is...>, const iterator &p) const | ||
{ | ||
// TODO: expand the expression | ||
std::array<bool, arity> neqs( | ||
{(std::get<Is>(is_) != std::get<Is>(p.is_))...}); | ||
return std::accumulate(neqs.begin(), neqs.end(), false, | ||
std::logical_or<bool>()); | ||
} | ||
|
||
public: | ||
iterator(const Iters &... i) : is_(i...) {} | ||
|
||
bool operator!=(const iterator &p) const | ||
{ | ||
// return get<0>(is_) != get<0>(p.is_) || get<1>(is_) != | ||
// get<1>(p.is_); | ||
return neq(std::make_index_sequence<arity>(), p); | ||
} | ||
|
||
void operator++() | ||
{ | ||
_advance(std::make_index_sequence<arity>()); | ||
// ++get<0>(is_), ++get<1>(is_); | ||
} | ||
|
||
auto operator*() | ||
{ | ||
return (operator*)(std::make_index_sequence<arity>()); | ||
} | ||
}; | ||
|
||
template <typename... Iters> | ||
static iterator<Iters...> make_iterator(const Iters &... is) | ||
{ | ||
return iterator<Iters...>(is...); | ||
} | ||
|
||
template <size_t... Is> | ||
auto begin(std::index_sequence<Is...>) const | ||
{ | ||
return make_iterator(std::get<Is>(ranges_).begin()...); | ||
} | ||
|
||
template <size_t... Is> | ||
auto end(std::index_sequence<Is...>) const | ||
{ | ||
return make_iterator(std::get<Is>(ranges_).end()...); | ||
} | ||
|
||
public: | ||
zipper_t(const Ts &... ranges) : ranges_(ranges...) {} | ||
|
||
auto begin() const { return begin(std::make_index_sequence<arity>()); } | ||
|
||
auto end() const { return end(std::make_index_sequence<arity>()); } | ||
}; | ||
|
||
template <typename... Ts> | ||
zipper_t<Ts...> zip(const Ts &... ranges) | ||
{ | ||
return zipper_t<Ts...>(ranges...); | ||
} | ||
} // namespace internal | ||
} // namespace experimental | ||
} // namespace ttl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
#include <cxxabi.h> | ||
|
||
#include <climits> | ||
#include <string> | ||
|
||
namespace ttl | ||
{ | ||
namespace internal | ||
{ | ||
template <typename T> | ||
std::string demangled_type_info_name() | ||
{ | ||
int status = 0; | ||
return abi::__cxa_demangle(typeid(T).name(), 0, 0, &status); | ||
} | ||
|
||
template <typename R> | ||
constexpr char scalar_type_prefix() | ||
{ | ||
if (std::is_floating_point<R>::value) { | ||
return 'f'; | ||
} else if (std::is_integral<R>::value) { | ||
return std::is_signed<R>::value ? 'i' : 'u'; | ||
} else { | ||
return 's'; | ||
} | ||
} | ||
|
||
template <bool, typename R> | ||
class scalar_type_name; | ||
|
||
template <typename R> | ||
class scalar_type_name<false, R> | ||
{ | ||
public: | ||
std::string operator()() const { return demangled_type_info_name<R>(); } | ||
}; | ||
|
||
template <typename R> | ||
class scalar_type_name<true, R> | ||
{ | ||
public: | ||
std::string operator()() const | ||
{ | ||
return scalar_type_prefix<R>() + std::to_string(sizeof(R) * CHAR_BIT); | ||
} | ||
}; | ||
} // namespace internal | ||
} // namespace ttl |
Oops, something went wrong.