Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure's :gen-class and double arrays

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 into 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?

like image 918
cryptic_star Avatar asked Dec 06 '25 10:12

cryptic_star


2 Answers

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 )))))
like image 82
kotarak Avatar answered Dec 08 '25 07:12

kotarak


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.

like image 42
dbyrne Avatar answered Dec 08 '25 08:12

dbyrne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!