inline subsample function