Gets the total element count. For tuples, this is not the count of tuple elements, but the sum of elements of each tuple element.
| 201 | // Gets the total element count. For tuples, this is not the count of tuple |
| 202 | // elements, but the sum of elements of each tuple element. |
| 203 | int64 RecursiveElementCount(const Shape& shape) { |
| 204 | if (shape.IsTuple()) { |
| 205 | const int64 tuple_elements = ShapeUtil::TupleElementCount(shape); |
| 206 | int64 total = 0; |
| 207 | for (int64 i = 0; i < tuple_elements; ++i) { |
| 208 | total += RecursiveElementCount(ShapeUtil::GetTupleElementShape(shape, i)); |
| 209 | } |
| 210 | return total; |
| 211 | } else if (shape.IsArray()) { |
| 212 | return ShapeUtil::ElementsIn(shape); |
| 213 | } else { |
| 214 | return 0; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // Returns whether the given value is infinity. |
| 219 | template <typename NativeT> |
no test coverage detected