Revert "Moved dim measurement into dim and cache the result"

This reverts commit de769ccee0f8939ff00e286b621e3a2903c5ead6.

* dim(x) cannot change x@.dim value

* Some functions, for example "sample", uses x@.dim before calling dim()