Re: Digest for numerical-clojure@googlegroups.com - 1 update in 1 topic

49 views
Skip to first unread message

Jeff Rose

unread,
Jul 21, 2017, 4:42:38 PM7/21/17
to numerica...@googlegroups.com
Hi Seamus,
  As long as you have the aljabr dependency in your project.clj (don't need to include core.matrix also, as it will come with aljabr), then you shouldn't need to do anything besides require clojure.core.matrix and thinktopic.aljabr.core.  I just created a simple cljs test app with the 0.1.1 release on Clojars in the project.clj, and this works as expected.

The warning about dynamic loading is because in Clojure when you do (mat/set-current-implementation :vectorz) it will call require for you under the hood, loading the library as long as it is on your classpath.  In Clojurescript if you don't explicitly require aljabr in at least one namespace then the compiler might not send it to the browser, in which case a dynamic require won't be able to load.  Anyways, try it out as is below, and let us know if you have any more problems.

Cheers,
Jeff


(ns foo.core
    (:require [reagent.core :as reagent :refer [atom]]
              [secretary.core :as secretary :include-macros true]
              [accountant.core :as accountant]
              [thinktopic.aljabr.core :as aljabr]
              [clojure.core.matrix :as mat]))

;(mat/set-current-implementation :aljabr)
(enable-console-print!)

;; -------------------------
;; Views

(defn home-page []
  (let [a (mat/new-array [2 2])
        b (mat/new-array [2 2])
        c (mat/add a b)
        d (mat/mmul [[1 2] [3 4]] [[5 6] [7 8]])]
  [:div [:h2 "Welcome to foo"]
   [:div (str c)]
   [:div (str d)]
   [:div [:a {:href "/about"} "go to about page"]]]))

(defn about-page []
  [:div [:h2 "About foo"]
   [:div [:a {:href "/"} "go to the home page"]]])




Jeff Rose
CEO / Founder


1050 Walnut st, suite 500
Boulder, Co, USA, 80302


On Fri, Jul 21, 2017 at 1:08 AM, <numerica...@googlegroups.com> wrote:
Seamus O'Keefe <okee...@gmail.com>: Jul 20 06:51PM -0700

Hi. I was wondering if someone could point me in the right direction on
getting core.matrix set up for ClojureScript using the aljabr
implementation.
 
I have the following:
 
(ns hellomatrix.core
(:require [quil.core :as q :include-macros true]
[quil.middleware :as mw]
[clojure.core.matrix :as m :include-macros true]
[thinktopic.aljabr.core :as nd :include-macros true]))
 
(enable-console-print!)
(m/set-current-implementation thinktopic.aljabr.core)
(m/implementation-check)
 
Which gives me a "No current clojure.core.matrix implementation available
(no canonical)" error. Not sure what to try next, as my many Google
searches have come up with nothing. Anyone's help would be greatly
appreciated!
You have received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to numerical-clojure+unsubscribe@googlegroups.com.

Seamus O'Keefe

unread,
Jul 22, 2017, 3:00:48 PM7/22/17
to Numerical Clojure
Thanks for the great info, Jeff.  I switched up the dependencies/requirements as you demonstrated and things are loading properly without errors or warnings.

This may be my understanding of how aljabr is supposed to work, but when I run the following

(enable-console-print!)
(println (type (m/matrix [[1 2] [3 4]]))) 

the output states that the matrix's type is still a Persistent Vector.  It was my understanding that this is still the default core.matrix implementation and that aljabr would replace this with a different type (ndarray, I believe?).  Am I mistaken, or is core.matrix still not using aljabr?
To unsubscribe from this group and stop receiving emails from it send an email to numerical-cloj...@googlegroups.com.

Mars0i

unread,
Jul 23, 2017, 1:18:23 PM7/23/17
to Numerical Clojure


On Saturday, July 22, 2017 at 2:00:48 PM UTC-5, Seamus O'Keefe wrote:
Thanks for the great info, Jeff.  I switched up the dependencies/requirements as you demonstrated and things are loading properly without errors or warnings.

This may be my understanding of how aljabr is supposed to work, but when I run the following

(enable-console-print!)
(println (type (m/matrix [[1 2] [3 4]]))) 

the output states that the matrix's type is still a Persistent Vector.  It was my understanding that this is still the default core.matrix implementation and that aljabr would replace this with a different type (ndarray, I believe?).  Am I mistaken, or is core.matrix still not using aljabr?

Yes, persistent-vector is the default core.matrix implementation, but it's not ndarray.  persistent-vector uses normal Clojure vectors.  A matrix is a vector of vectors.

Apparently, (set-current-implementation :aljabr) is still needed in some contexts.  The following is at a figwheel prompt.  (If you're not using figwheel with Clojurescript, it is highly recommended by many folks.)

cljs.user=> (ns cljs.user (:require [clojure.core.matrix :as mx] [thinktopic.aljabr.core :as aj]))
nil

cljs.user=> (mx/matrix [[1 2][3 4]])
[[1 2] [3 4]]

cljs.user=> (type (mx/matrix [[1 2][3 4]]))
cljs.core/PersistentVector

cljs.user=> (mx/set-current-implementation :aljabr)
INFO: No dynamic loading of implementations in Clojurescript.
You must require an implementation explicitly in a namespace, for example thinktopic.aljabr.core
:aljabr

# Comment: Despite the warning, note that what's returned is what would be expected,
# i.e. the keyword :aljabr.

cljs.user=> (mx/matrix [[1 2][3 4]])
#object[thinktopic.aljabr.core.NDArray2float64]

cljs.user=> (type (mx/matrix [[1 2][3 4]]))
thinktopic.aljabr.core/NDArray2float64

# The following illustrates that persistent-vector's are Clojure vectors.

cljs.user=> (mx/set-current-implementation :persistent-vector)
INFO: No dynamic loading of implementations in Clojurescript.
You must require an implementation explicitly in a namespace, for example thinktopic.aljabr.core
:persistent-vector

cljs.user=> (first (mx/matrix [[1 2][3 4]]))
[1 2]

cljs.user=> (rest (mx/matrix [[1 2][3 4]]))
([3 4])
 
cljs.user=> (type (mx/matrix [[1 2][3 4]]))
cljs.core/PersistentVector

cljs.user=> (type [[1 2][3 4]])
cljs.core/PersistentVector

Seamus O'Keefe

unread,
Jul 23, 2017, 10:08:32 PM7/23/17
to numerica...@googlegroups.com
That worked!  I guess I should have tested the type myself despite the dynamic loading warning.  I appreciate your help immensely. Thanks again!

--
You received this message because you are subscribed to a topic in the Google Groups "Numerical Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/numerical-clojure/NdDjd1xXXiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to numerical-clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Anderson

unread,
Jul 25, 2017, 11:03:32 PM7/25/17
to Numerical Clojure
Thanks guys for testing core.matrix out with ClojureScript! It should all work in the same way as Clojure but I personally don't use ClojureScript much myself so if you run into any issues / oddities then please do file a GitHub issue or PR

Reply all
Reply to author
Forward
0 new messages