clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.06k stars 69 forks source link

Execution error (ExceptionInfo) at tech.v2.datatype.base/copy! (base.cljc:208). #120

Closed zendevil closed 3 years ago

zendevil commented 3 years ago

Getting this error:

Execution error (ExceptionInfo) at tech.v2.datatype.base/copy! (base.cljc:208).

With the following code:

(require-python '[numpy :as np :refer [zeros where greater dot
                                       random add multiply random
                                       subtract
                                       negative]])

(defn A-0 [N]
  (->
   (for [r (range (inc N))]
     (for [n (range (inc N))]
       (if (= r n)
         (reduce * (map #(- r %) (range r)))
         0)))
   ->numpy))

(defn A [N tau]
  (->
   (for [r (range (inc N))]
     (for [n (range (inc N))]
       (if (>= n r)
         (* (reduce * (map #(- n %)
                           (range r)))
            (expt tau (- n r)))
         0)))
   ->numpy))

(defn A-row [K N tau row]
  (->
   (fn [c]
     (condp = c
       row (negative (A N tau))
       (inc row) (A-0 N)
       (zeros [N N])))
   (map (-> K inc range))
   ->numpy))

(A-row 10 7 2 1) ;; doesn't work

(A-row 10 7 2 0) ;; works
zendevil commented 3 years ago

the line (zeros [N N]) needs to be

(zeros [(inc N) (inc N)])

A better error message about the asymmetry when converting using ->numpy is warranted.