| 504 | |
| 505 | template <typename TYPE> |
| 506 | int64_t ContiguousTensorCountNonZero(const Tensor& tensor) { |
| 507 | using c_type = typename TYPE::c_type; |
| 508 | auto* data = reinterpret_cast<const c_type*>(tensor.raw_data()); |
| 509 | return std::count_if(data, data + tensor.size(), |
| 510 | [](const c_type& x) { return x != 0; }); |
| 511 | } |
| 512 | |
| 513 | template <typename TYPE> |
| 514 | inline int64_t TensorCountNonZero(const Tensor& tensor) { |