Familiarize yourself with the following function. 'mx' is an array framework inspired by…
- User
Familiarize yourself with the following function. 'mx' is an array framework inspired by PyTorch but not as extensive.
def upsample_nearest(x, scale: int = 2): B, H, W, C = x.shape x = mx.broadcast_to(x[:, :, None, :, None, :], (B, H, scale, W, scale, C)) x = x.reshape(B, H * scale, W * scale, C)
return xNow, implement downsample_nearest(x, target_width, target_height)
- Assistant
Here's an implementation of the
downsample_nearestfunction you requested:def downsample_nearest(x, target_width, target_height): B, H, W, C = x.shape if target_width > W or target_height > H: raise ValueError("Target width and height must be smaller or equal to the input dimensions") scale_height = H // target_height scale_width = W // target_width x = x[:, ::scale_height, ::scale_width, :] return x
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.