Repository: activeloopai/Hub
File: deeplake/core/tensor_link.py (Python)

Code before:
        ):
            ret = np.concatenate([ret, (1,)])

        if tensor_meta.is_link and ret.size and np.prod(ret):
            tensor_meta.update_shape_interval(ret.tolist())

    return ret


@link
def extend_shape(samples, link_creds=None, tensor_meta=None):
    if isinstance(samples, np.ndarray):
        if samples.dtype != object:
            samples_shape = samples.shape
            if samples.ndim == 1:
                samples_shape = samples_shape + (1,)
            return np.tile(np.array([samples_shape[1:]]), (samples_shape[0], 1))
    if samples is None:
        return np.array([], dtype=np.int64)
    shapes = [
        update_shape.f(sample, link_creds=link_creds, tensor_meta=tensor_meta)
        for sample in samples
    ]

    max_ndim = max(map(len, shapes)) if shapes else 0
    min_ndim = min(map(len, shapes)) if shapes else 0
    mixed_ndim = max_ndim != min_ndim

    if mixed_ndim:
        for i, s in enumerate(shapes):
            if len(s) < max_ndim:
                shapes[i] = np.concatenate(
                    [s, (int(bool(np.any(s) and np.prod(s))),) * (max_ndim - len(s))]
                )
    arr = np.array(shapes)
    return arr


@link
def extend_len(samples, link_creds=None):
    return [0 if sample is None else len(sample) for sample in samples]


@link
def update_len(new_sample, link_creds=None):
    return 0 if new_sample is None else len(new_sample)


def convert_sample_for_downsampling(sample, link_creds=None):
    try:
        if isinstance(sample, deeplake.core.linked_sample.LinkedSample):

Review comment (suggestion):
```
    max_ndim = max(map(len, shapes), default=0)
    min_ndim = min(map(len, shapes), default=0)
```

Code after:
        ):
            ret = np.concatenate([ret, (1,)])

        if tensor_meta.is_link and ret.size and np.prod(ret):
            tensor_meta.update_shape_interval(ret.tolist())

    return ret


@link
def extend_shape(samples, link_creds=None, tensor_meta=None):
    if isinstance(samples, np.ndarray):
        if samples.dtype != object:
            samples_shape = samples.shape
            if samples.ndim == 1:
                samples_shape = samples_shape + (1,)
            return np.tile(np.array([samples_shape[1:]]), (samples_shape[0], 1))
    if samples is None:
        return np.array([], dtype=np.int64)
    shapes = [
        update_shape.f(sample, link_creds=link_creds, tensor_meta=tensor_meta)
        for sample in samples
    ]

    max_ndim = max(map(len, shapes), default=0)
    min_ndim = min(map(len, shapes), default=0)
    mixed_ndim = max_ndim != min_ndim

    if mixed_ndim:
        for i, s in enumerate(shapes):
            if len(s) < max_ndim:
                shapes[i] = np.concatenate(
                    [s, (int(bool(np.any(s) and np.prod(s))),) * (max_ndim - len(s))]
                )
    arr = np.array(shapes)
    return arr


@link
def extend_len(samples, link_creds=None):
    return [0 if sample is None else len(sample) for sample in samples]


@link
def update_len(new_sample, link_creds=None):
    return 0 if new_sample is None else len(new_sample)


def convert_sample_for_downsampling(sample, link_creds=None):
    try:
        if isinstance(sample, deeplake.core.linked_sample.LinkedSample):