Skip to content
Fast primitive based math library
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs new snapshot - refactoring Jun 13, 2019
example/fastmath bayesian opt Jun 4, 2019
lib cross validations Jan 10, 2019
resources 1.3.0 snapshot, vectors and classification tests Jan 4, 2019
src cleaning param name inconsistancy Jun 27, 2019
test/fastmath 1.3.0 snapshot, vectors and classification tests Jan 4, 2019
utils examples removed from main files May 30, 2018
.gitignore cross validations Jan 10, 2019 new snapshot - refactoring Jun 13, 2019
LICENSE new snapshot - refactoring Jun 13, 2019
codrna.clj cl Jan 17, 2019
project.clj new snapshot - refactoring Jun 13, 2019


Fast and primitive based math library.

Originally it was a part of generative art/glich Clojure2d library.


[generateme/fastmath "1.2.0"]

Development version

[generateme/fastmath "1.4.0-SNAPSHOT"]





Code adopted from Zach Tellmans' library.

[* + - / > < >= <= == rem quot mod bit-or bit-and bit-xor bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right inc dec zero? neg? pos? min max even? odd? bool-and bool-or bool-xor bool-not << >> >>> not==]

Math functions

  • Trigonometric functions
  • Power: log, ln, logb, exp, pow, sqrt
  • Rounding functions: round, floor, ceil, trunc, frac, approx + other
  • Normalizations: norm wrap, constrain
  • Interpolations: lerp, cos-interpolation, smooth-interpolation, quad-interpolation, smoothstep
  • Special functions: erf, beta, gamma + other
  • Distance: dist, hypot
  • Sign: sgn, signum, abs
  • Other: gcd

Most of them backed by Jafama FastMath 2.3.1 or Apache Commons Math 3.6.1

Vector operations protocol and implementations

  • 2d (Vec2), 3d (Vec3) and 4d (Vec4) vector types.
  • ArrayVector for fixed length long vectors (fixed sized double-array)
  • Clojure vector

With following groups of functions:

  • Basic linear operations: add, mult, div, sub, dot, cross, hadamard product
  • mag, magsq, heading, angle-between, limit, normalize
  • rotations (2d,3d)
  • translations (2d, 3d)
  • various distances
  • centroid, interpolations
  • and other

Complex number functions

  • primitive operations: mult, div, add, sub
  • abs, arg, conjugate, reciprocal, neg
  • atan, asin, acos, csc, sec, tanh, tan, sinh, sin, cosh, cos
  • log, exp, pow
  • sqrt, sq, sqrt1z

Random numbers

  • Collection of random number generators
  • Collection of distributions (count: 28)
  • Random generator functions for each primitive type (drand - double, lrand - long, frand - float, irand - int)
  • Additional RNG functions: brand - true/false, grand - gaussian distributed double
  • Random sequences: from distribution, halton, sobol, R2, sphere, uniform


  • 4 noise types: value, gradient, simplex, discrete
  • 3 noise blends: fbm, ridgedmulti, billow
  • Ready to use fbm functions: noise (perlin), vnoise (value noise), simplex


  • Descriptive statistics: size, min, max, mode, mean, median, percentiles, kurtosis, skewness, IQR, LAV, UAV and other
  • Correlations


1d, 2d interpolations


Several easing functions (in, out, in-out)


  • Wavelets: 1d, 2d (haar, biorthogonal, symlet, coiflet, daubechies, legendre)
  • 1d Fast Sine, Cosine and Hadamard

Vector fields

Great collection (100+) of R^2->R^2 functions.


SMILE bindings for clustering

Classifcations (dev version)

SMILE, LIBLINEAR and XGBoost classification bindings


To enable XGBoost under Windows please add following lines to your lein profile:

:exclusions [[org.slf4j/slf4j-simple] [ml.dmlc/xgboost4j] [asm]]
:resource-paths ["resources/" "lib/xgboost4j-0.81-criteo-20180821_2.11-win64.jar"]


Hexagonal, squared, triangular, rhomboidal grid functions


Plenty of constant values

Almost all functions optimized to work on double and long primitives

Supporting libraries


Since this library is only JVM version, you can check following Clojure/ClojureScript libraries as replacement

  • PrimitiveMath - for primitive operators
  • Kixi stats - for pure clj(s) statistics/distributions (tends to be 2-10x slower)
  • - for vectors, general math, noise, complex numbers, transforms (fourier)
  • vectorz-clj - fast vector operations
  • Incanter - statistics/distributions/probability


Java classes are compiled for java 1.8


  • Change images to plots with axes
  • More tests
  • Move vector fields

How To Help

If you see place of improvement, I'm accepting PRs.


The Unlicence

You can’t perform that action at this time.