             [uncomplicate.fluokitten.core :refer [op]]
             [uncomplicate.neanderthal
              [vect-math :refer [sqrt!]]
-             [core :refer [transfer dim vspace?]]]
+             [core :refer [transfer transfer! dim vspace? subvector vctr]]]
             [uncomplicate.neanderthal.internal.api :as na]
             [uncomplicate.bayadera.util :refer [srand-int]]
             [uncomplicate.bayadera.internal.protocols :refer :all])

    (with-params-check (model dist-eng) params
      (->DistributionImpl factory dist-eng sampler-factory (transfer factory params))))
  (invoke [this data hyperparams]
    (with-release [params (op data hyperparams)]
      (with-params-check (model dist-eng) hyperparams
        (->DistributionImpl factory dist-eng sampler-factory (transfer factory params)))))
  ModelProvider
  (model [_]
    (model dist-eng)))


(defmacro ^:private with-params-check [model params & body]
  `(if (= (params-size ~model) (if (vspace? ~params) (dim ~params) (count ~params)))
     (do ~@body)
     (dragan-says-ex "Dimension of params must match the distribution."
                     {:required (params-size ~model) :supplied (dim ~params)})))

