-
Notifications
You must be signed in to change notification settings - Fork 19
Getting started
Step one is to ensure that you have set up vectorz-clj
as a library dependency in your project.
Follow the instructions to install with Leiningen / Maven from Clojars:
This is needed to make the core.matrix
API available. Often the most convenient way to do this is to add a :use
clause in your namespace statement, e.g.
(ns your.brilliant.namespace
(:use [clojure.core.matrix]))
However you can also do this at the REPL, e.g. with
(use 'clojure.core.matrix)
Once core.matrix
is available, you can start using vectorz-clj
directly via the core.matrix API. You can now directly use the core.matrix
API to do whatever you like:
(def a (array :vectorz [1 2 3])
=> #vectorz/vector [1.0,2.0,3.0]
(def M (outer-product a a))
=> #vectorz/matrix [[1.0,2.0,3.0],[2.0,4.0,6.0],[3.0,6.0,9.0]]
(mmul M a)
=> #vectorz/vector [14.0,28.0,42.0]
For more usage examples see the Examples page.
If you want to use vectorz-clj
as the default implementation, then you can do:
(set-current-implementation :vectorz)
This will ensure that the core.matrix
functions use vectorz-clj
matrices and vectors by default. For example, the array
API function will now automatically return Vectorz instances:
(def B (array [[1 2] [3 4]]))
=> #vectorz/matrix [[1.0,2.0],[3.0,4.0]]
WARNING the default implementation is a global setting. Only do this if you are sure it won't interfere with any other code. In general, it is OK to do this in your own application code, but it's a bad idea to do it if you are writing a library that will be used by others, because it may cause conflicts with users that want to set a different core.matrix
implementation