Utility function. Subset an object x with a
dim attribute (matrix/array/data.frame/etc.)
and return another with dimensions pmin(dim, dim(x))
subset_dim(x, dim, random)object to subset
new dimensions
logical, whether to take a random subset or just the head.