Clojure: unable to import specific methods from java class

111 views Asked by At

Possible linked to Cannot call particular java method from Clojure

Using the smile package, I've upgraded to 3.0.0 and failing to call some methods. My Leiningen project.clj has the following import [com.github.haifengl/smile-core "3.0.0"]

Now in the REPL:


(import smile.math.MathEx)

(MathEx/log2 5.)
=> 2.321928094887362
(MathEx/pow2 5.)
Syntax error (IllegalArgumentException) compiling . at (C:\Users\AAlmosni\AppData\Local\Temp\1\form-init13649993705313983821.clj:1:1).
No matching method pow2 found taking 1 args for class smile.math.MathEx
(MathEx/sigmoid 5.)
Syntax error (IllegalArgumentException) compiling . at (C:\Users\AAlmosni\AppData\Local\Temp\1\form-init13649993705313983821.clj:1:1).
No matching method sigmoid found taking 1 args for class smile.math.MathEx
(MathEx/isPower2 32)
=> true

This is very confusing to me - some methods work fine, some don't. Here's an extract from MathEx.class:

    public static double log2(double x) {
        return Math.log(x) / LOG2;
    }

    public static double log(double x) {
        double y = -690.7755D;
        if (x > 1.0E-300D) {
            y = Math.log(x);
        }

        return y;
    }

    public static double log1pe(double x) {
        double y = x;
        if (x <= 15.0D) {
            y = Math.log1p(Math.exp(x));
        }

        return y;
    }

    public static boolean isInt(float x) {
        return x == (float)Math.floor((double)x) && !Float.isInfinite(x);
    }

    public static boolean isInt(double x) {
        return x == Math.floor(x) && !Double.isInfinite(x);
    }

    public static boolean equals(double a, double b) {
        if (a == b) {
            return true;
        } else {
            double absa = Math.abs(a);
            double absb = Math.abs(b);
            return Math.abs(a - b) <= Math.min(absa, absb) * 2.220446049250313E-16D;
        }
    }

    public static double sigmoid(double x) {
        x = Math.max(-36.0D, Math.min(x, 36.0D));
        return 1.0D / (1.0D + Math.exp(-x));
    }

    public static double pow2(double x) {
        return x * x;
    }

    public static boolean isPower2(int x) {
        return x > 0 && (x & x - 1) == 0;
    }

Any idea what is causing the failed imports?

Thanks,

1

There are 1 answers

1
alex314159 On BEST ANSWER

As Juraj was hinting it was a dependency conflict - I was also using tech.ml.dataset in my project, version 6, which was using an older version of smile. Moving tech.ml.dataset to version 7, which doesn't include smile by default, sorted the issue.

Thanks!