| 564 | |
| 565 | template <typename TYPE> |
| 566 | int64_t ContiguousTensorCountNonZero(const Tensor& tensor) { |
| 567 | using c_type = typename TYPE::c_type; |
| 568 | auto* data = reinterpret_cast<const c_type*>(tensor.raw_data()); |
| 569 | return std::count_if(data, data + tensor.size(), |
| 570 | [](const c_type& x) { return x != 0; }); |
| 571 | } |
| 572 | |
| 573 | template <typename TYPE> |
| 574 | inline int64_t TensorCountNonZero(const Tensor& tensor) { |