| 596 | |
| 597 | template <typename TYPE> |
| 598 | int64_t ContiguousTensorCountNonZero(const Tensor& tensor) { |
| 599 | using c_type = typename TYPE::c_type; |
| 600 | auto* data = reinterpret_cast<const c_type*>(tensor.raw_data()); |
| 601 | return std::count_if(data, data + tensor.size(), |
| 602 | [](const c_type& x) { return x != 0; }); |
| 603 | } |
| 604 | |
| 605 | template <typename TYPE> |
| 606 | inline int64_t TensorCountNonZero(const Tensor& tensor) { |