| 433 | |
| 434 | template <typename T, typename U> |
| 435 | TensorND TensorValue( |
| 436 | const TensorShape& shape, T dtype, std::initializer_list<U> values) { |
| 437 | TensorLayout layout{shape, dtype}; |
| 438 | auto buf = static_cast<dt_byte*>(malloc(layout.span().dist_byte())); |
| 439 | TensorND tensor{buf, layout}; |
| 440 | megdnn_assert( |
| 441 | values.size() == tensor.layout.total_nr_elems(), "%zu == %zu", |
| 442 | values.size(), tensor.layout.total_nr_elems()); |
| 443 | auto ptr = tensor.ptr<typename DTypeTrait<T>::ctype>(); |
| 444 | for (const auto& v : values) { |
| 445 | *ptr++ = typename DTypeTrait<T>::ctype(v); |
| 446 | } |
| 447 | return tensor; |
| 448 | } |
| 449 | |
| 450 | template <typename T, typename U> |
| 451 | TensorND TensorValueLowbit4(const TensorShape& shape, T dtype, std::vector<U> values) { |