def corners_nd(dims, origin=0.5):
    'generate relative box corners based on length per dim and\n    origin point.\n\n    Args:\n        dims (float array, shape=[N, ndim]): array of length per dim\n        origin (list or array or float): origin point relate to smallest point.\n\n    Returns:\n        float array, shape=[N, 2 ** ndim, ndim]: returned corners.\n        point layout example: (2d) x0y0, x0y1, x1y0, x1y1;\n            (3d) x0y0z0, x0y0z1, x0y1z0, x0y1z1, x1y0z0, x1y0z1, x1y1z0, x1y1z1\n            where x0 < x1, y0 < y1, z0 < z1\n    '
    ndim = int(dims.shape[1])
    corners_norm = np.stack(np.unravel_index(np.arange((2 ** ndim)), ([2] * ndim)), axis=1).astype(dims.dtype)
    if (ndim == 2):
        corners_norm = corners_norm[[0, 1, 3, 2]]
    elif (ndim == 3):
        corners_norm = corners_norm[[0, 1, 3, 2, 4, 5, 7, 6]]
    corners_norm = (corners_norm - np.array(origin, dtype=dims.dtype))
    corners = (dims.reshape([(- 1), 1, ndim]) * corners_norm.reshape([1, (2 ** ndim), ndim]))
    return corners
generate relative box corners based on length per dim and
origin point.

Args:
    dims (float array, shape=[N, ndim]): array of length per dim
    origin (list or array or float): origin point relate to smallest point.

Returns:
    float array, shape=[N, 2 ** ndim, ndim]: returned corners.
    point layout example: (2d) x0y0, x0y1, x1y0, x1y1;
        (3d) x0y0z0, x0y0z1, x0y1z0, x0y1z1, x1y0z0, x1y0z1, x1y1z0, x1y1z1
        where x0 < x1, y0 < y1, z0 < z1
def corners_nd(dims, origin=0.5):
    'generate relative box corners based on length per dim and\n    origin point.\n\n    Args:\n        dims (float array, shape=[N, ndim]): array of length per dim\n        origin (list or array or float): origin point relate to smallest point.\n\n    Returns:\n        float array, shape=[N, 2 ** ndim, ndim]: returned corners.\n        point layout example: (2d) x0y0, x0y1, x1y0, x1y1;\n            (3d) x0y0z0, x0y0z1, x0y1z0, x0y1z1, x1y0z0, x1y0z1, x1y1z0, x1y1z1\n            where x0 < x1, y0 < y1, z0 < z1\n    '
    ndim = int(dims.shape[1])
    corners_norm = np.stack(np.unravel_index(np.arange((2 ** ndim)), ([2] * ndim)), axis=1).astype(dims.dtype)
    if (ndim == 2):
        corners_norm = corners_norm[[0, 1, 3, 2]]
    elif (ndim == 3):
        corners_norm = corners_norm[[0, 1, 3, 2, 4, 5, 7, 6]]
    corners_norm = (corners_norm - np.array(origin, dtype=dims.dtype))
    corners = (dims.reshape([(- 1), 1, ndim]) * corners_norm.reshape([1, (2 ** ndim), ndim]))
    return corners