Calculates the rank of a tensor.