Count non-zero elements along dim (or whole tensor when None).
Parameters
Input. Non-zero is determined by element-wise comparison to
zero (NaN counts as non-zero).
dimint, sequence of int, or None= NoneAxis or axes to reduce.
None (default) reduces the entire
tensor to a 0-D scalar.Returns
Tensorint64 count(s). Shape mirrors lucid.sum over the
same dim argument.
Notes
Composite implementation: the CPU backend lacks
where(bool, i64, i64) and astype(bool → i64), so the op
builds a float32 1.0/0.0 mask, reduces, and astype-casts
the float scalar back to int64 (a path the backend does support).
Slightly more allocations than a native int reduction but
semantically identical.