10 #include <initializer_list>
17 namespace tensor_init {
24 template <
typename T,
size_t D>
26 using type = std::initializer_list<
35 template <
typename T,
size_t D>
40 static constexpr
size_t value = 0;
51 static constexpr
size_t value(
const L& list) {
52 if (list.size() == 0) {
56 for (
const auto&
value : list) {
59 "Input contains ragged nested sequences"
60 "(nested lists with unequal sizes or shapes).");
70 static constexpr
size_t value(
const L& list) {
75 template <
typename L,
size_t... D>
87 while (shape.
size() > (last_dim + 1) && shape[last_dim] != 0) {
90 shape.
resize(last_dim + 1);
94 template <
typename T,
typename L>
99 template <
typename T,
typename L>
100 void NestedCopy(T&& iter,
const std::initializer_list<L>& list) {
101 for (
const auto& value : list) {
106 template <
typename T,
size_t D>
int64_t NumElements() const
typename NestedInitializerImpl< T, D >::type NestedInitializerList
std::vector< T > ToFlatVector(const SizeVector &shape, const tensor_init::NestedInitializerList< T, D > &nested_list)
SizeVector InitializerShape(const L &list, std::index_sequence< D... >)
void NestedCopy(T &&iter, const L &list)
SizeVector InferShape(const L &list)
Generic file read and write utility for python interface.
static constexpr size_t value
static constexpr size_t value(const L &list)
static constexpr size_t value(const L &list)
std::initializer_list< typename NestedInitializerImpl< T, D - 1 >::type > type