• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    Clojure
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Julia bindings for Clojure -- Currently somewhat unstable --

julia-clj

Clojars Project travis integration

Usage

Install julia and set JULIA_HOME:

scripts/activate-julia

In your repl, load the julia base namespace and initialize the system.

user> (require '[libjulia-clj.julia :as julia])
nil
user> (julia/initialize!)
07:07:06.228 [nREPL-session-e1c7b4a4-54f4-4298-80bb-972e83b902ff] INFO libjulia-clj.impl.base - Attempting to initialize Julia at /home/chrisn/dev/cnuernber/libjulia-clj/julia-1.5.3/lib/libjulia.so
07:07:07.121 [nREPL-session-e1c7b4a4-54f4-4298-80bb-972e83b902ff] INFO tech.v3.jna.base - Library /home/chrisn/dev/cnuernber/libjulia-clj/julia-1.5.3/lib/libjulia.so found at [:system "/home/chrisn/dev/cnuernber/libjulia-clj/julia-1.5.3/lib/libjulia.so"]
:ok
user> (def ones-fn (julia/jl "Base.ones"))
#'user/ones-fn
user> (ones-fn 3 4)
[1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0]
user> (def julia-ary *1)
#'user/julia-ary
user> (require '[tech.v3.tensor :as dtt])
nil
user> (dtt/ensure-tensor julia-ary)
#tech.v3.tensor<float64>[3 4]
[[1.000 1.000 1.000 1.000]
 [1.000 1.000 1.000 1.000]
 [1.000 1.000 1.000 1.000]]
user> (def clj-tens *1)
#'user/clj-tens
user> (dtt/mset! clj-tens 0 25)
#tech.v3.tensor<float64>[3 4]
[[25.00 25.00 25.00 25.00]
 [1.000 1.000 1.000 1.000]
 [1.000 1.000 1.000 1.000]]
user> julia-ary
[25.0 25.0 25.0 25.0; 1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0]

Something Fun

user> (require '[tech.v3.libs.buffered-image :as bufimg])
nil
user> (require '[tech.v3.datatype :as dtype])
nil
user> (def fract-width 1920)
(def fract-height 1080)
(def i1 0.31)
(def i2 -0.6)
(def d 11)
(def zoom-factor 0.2)
#'user/fract-width#'user/fract-height#'user/i1#'user/i2#'user/d#'user/zoom-factor
user> (def julia-code
  "function juliaSet(i1,i2,d,zoomFactor,imgWidth,imgHeight)
    # Allocating a widthxheight matrix as our Clojure client is row-major
    matrix = Array{UInt8}(undef,imgWidth,imgHeight)
    icomp = Complex{Float64}(i1,i2)
    Threads.@threads for i in CartesianIndices(matrix)
        ## Julia has 1-based indexing...
        pos =  complex(((i[1]-1) - (0.5 * imgWidth)) / (zoomFactor * imgWidth),
                       ((i[2]-1) - (0.5 * imgHeight)) / (zoomFactor * imgHeight))

        for c in (1:d) pos = (pos * pos) + icomp end
        absval = abs(pos)
        if (absval != NaN && absval < (d-1))
            matrix[i] = 255
        else
            matrix[i] = 0
        end
    end
    return matrix
end")
#'user/julia-code
user> (def fractal-fn (julia/jl julia-code))
#'user/fractal-fn
user> (defn jl-fractal
        []
        (-> (fractal-fn i1 i2 d zoom-factor fract-width fract-height)
            (dtt/ensure-tensor)
            ;;Julia is column-major so our image comes out widthxheight
            ;;datatype is row major.
            (dtt/transpose [1 0])
            ;;The tensor library *knows* the original was transposed so transposing the result
            ;;back into row-major means the memory can be read in order and thus
            ;;the copy operation below is one large memcopy into a jvm byte array.
            (dtype/copy! (bufimg/new-image fract-height fract-width :byte-gray))))
#'user/jl-fractal
user> (jl-fractal)
#object[java.awt.image.BufferedImage 0x4d63b28f "BufferedImage@4d63b28f: type = 10 ColorModel: #pixelBits = 8 numComponents = 1 color space = java.awt.color.ICC_ColorSpace@2703464d transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 1920 height = 1080 #numDataElements 1 dataOff[0] = 0"]
;; Roughly 1920*1080*11*3, or 68428800 complex number operations
user> (time (def ignored (jl-fractal)))
"Elapsed time: 31.487044 msecs"
#'user/ignored
user> (bufimg/save! (jl-fractal) "julia.png")
true

julia-img

License

Copyright © 2021 Chris Nuernberger

More Repositories

1

dtype-next

A Clojure library designed to aid in the implementation of high performance algorithms and systems.
Clojure
310
star
2

charred

zero dependency efficient read/write of json and csv data.
Clojure
194
star
3

ham-fisted

High performance HAMT
Clojure
148
star
4

tmdjs

High Performance Data Processing for ClojureScript
Clojure
98
star
5

avclj

libavcodec pathways for Clojure.
Clojure
57
star
6

cljs-lambda-gateway-example

Simple bare-bones example of launching a full website using API gateway and AWS lambda
Clojure
53
star
7

facial-rec

Facial rec tech
Python
31
star
8

depsviz

Graphiz visualization for deps.edn
Clojure
22
star
9

streams

Simple monte carlo simulation system based on lazy non-caching streams.
Clojure
20
star
10

ames-house-prices

exploring aimes house prices comp
Jupyter Notebook
20
star
11

lambinator

Clojure 3d graphics editing platform
Clojure
10
star
12

ds-graal

Example of tech.ml.dataset and graalvm reading a CSV and writing Parquet.
Shell
9
star
13

berger-emacs

clean emacs setup for clojure
Emacs Lisp
8
star
14

fast-json

Clojure
7
star
15

ham-scripted

High performance js primitives
JavaScript
7
star
16

simpledata

A simple example project with a few datasets and sql bindings
Clojure
6
star
17

kmeans-mnist

An example of Clojure/Julia integration.
Clojure
6
star
18

mkl

Basic mkl bindings based on dtype-next's ffi system
Clojure
3
star
19

garmin-fit-clj

Clojure parser for garmin fit files
Clojure
2
star
20

thinksm

Thinktopic state machine implementation.
Clojure
1
star
21

siemplify-graal-native-example

Shell
1
star
22

benchmark

Simple benchmarking tools
Clojure
1
star
23

d3meetup

Working through a bunch of garmin/strava data for d3 meetup vega demonstration
Jupyter Notebook
1
star
24

difftest

Comparison of diff-1d algorithms
Clojure
1
star