开发者

Clojure's :gen-class and double arrays

开发者 https://www.devze.com 2023-01-08 08:19 出处:网络
I am attempting to :gen-class a fn which takes a 2D array of Doubles as input. I have already seen the post and solution here concerning a similar topic, but I am still unable to produce a working sol

I am attempting to :gen-class a fn which takes a 2D array of Doubles as input. I have already seen the post and solution here concerning a similar topic, but I am still unable to produce a working solution.

(ns gui.heatmap
  (:gen-class
    :name gui.Heatmap
    :methods [[heat-map2 ["[[D"] org.jfree.chart.JFreeChart]]))

(defn foo [dbl-array]
  ...)

I use the "[[D" based on using type on my input. This compiles fine int开发者_开发问答o a .class file.

Now, when I move to another .clj file, I have the following.

(ns ...
  (import (gui.Heatmap)))

(defn bar [args]
  ...
  (.foo
    (into-array
      (vector
        (double-array <list of numbers>)
        (double-array <list of numbers>)
        (double-array <list of numbers>)))))

When I call bar from the repl, I get the following error:

java.lang.IllegalArgumentException: No matching field found: heat_map2 for class [[D

Any thoughts?


You are missing the object. (.foo (into-array ...)) vs (.foo (Heatmap.) (into-array...))

Note, you should also require your gui.Heatmap namespace. Otherwise you can get into trouble if the ... namespace is compiled before gui.Heatmap. Then the import fails, because the class is not generated, yet. Adding the require will resolve this problem.

Edit:

To clarify things.

  • fix missing object
  • add require
  • fix prefix (good catch by dbyrne!)
  • fix :import clause (was also wrong)
(ns gui.heatmap
  (:gen-class
    :name gui.Heatmap
    :methods [[heat-map2 ["[[D"] org.jfree.chart.JFreeChart]]))

(defn -foo [dbl-array]
  ...)

(ns ...
  (import gui.Heatmap))

(defn bar [args]
  ...
  (.foo
    (Heatmap.)
    (into-array
      (vector
        (double-array )
        (double-array )
        (double-array )))))


Kotarak's answer is good. However another problem is that you need to name your function -foo instead of foo. Either that or change the :prefix inside :gen-class.

0

精彩评论

暂无评论...
验证码 换一张
取 消