views:

63

answers:

2

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?

+2  A: 

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
If I made `foo` static (so `(defn ^{:static true} -foo ...)`), would I then call `foo` by `(Heatmap/-foo (into-array...))`?
allie
Well, even without it being static, I am being told that I am unable to resolve the classname Heatmap, despite being able to see that it was generated.
allie
I updated the example. There was another problem with import clause. I also added dbyrne's fix for the function prefix.
kotarak
+1  A: 

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.

dbyrne