<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rank(tensor: BKTensor) -> int: """Return the number of dimensions of a tensor"""

    if isinstance(tensor, np.ndarray):
        return len(tensor.shape)

    return len(tensor[0].size())