Liking cljdoc? Tell your friends :D

fastmath.vector

Mathematical vector operations.

Types

  • Fixed size (custom types):
    • Number - 1d vector
    • Vec2 - 2d vector, creator vec2
    • Vec3 - 3d vector, creator vec3
    • Vec4 - 4d vector, creator vec4
    • ArrayVec - fixed size double array wrapper, n-dimensional, creator array-vec
  • Fixed size
    • doubles - double array itself
  • Variable size:
    • Clojure's IPersistentVector, creator []
    • Clojure's ISeq

[[VectorProto]] defines most of the functions.

Vectors implements also:

  • Sequable
  • Sequencial
  • IFn
  • Counted
  • Reversible
  • Indexed
  • ILookup
  • equals and toString from Object
  • IPersistentVector
  • Associative
  • clojure.core.matrix.protocols
  • IReduce and IReduceInit

That means that vectors can be destructured, treated as sequence or called as a function. See vec2 for examples.

Mathematical vector operations.

### Types

* Fixed size (custom types):
    * Number - 1d vector
    * Vec2 - 2d vector, creator [[vec2]]
    * Vec3 - 3d vector, creator [[vec3]]
    * Vec4 - 4d vector, creator [[vec4]]
    * ArrayVec - fixed size double array wrapper, n-dimensional, creator [[array-vec]]
* Fixed size
    * doubles - double array itself
* Variable size:
    * Clojure's IPersistentVector, creator `[]`
    * Clojure's ISeq

[[VectorProto]] defines most of the functions.

Vectors implements also:

* `Sequable`
* `Sequencial`
* `IFn`
* `Counted`
* `Reversible`
* `Indexed`
* `ILookup`
* `equals` and `toString` from `Object`
* `IPersistentVector`
* `Associative`
* `clojure.core.matrix.protocols`
* `IReduce` and `IReduceInit`

That means that vectors can be destructured, treated as sequence or called as a function. See [[vec2]] for examples.
raw docstring

absclj

(abs v)

Absolute value of vector elements

Absolute value of vector elements
sourceraw docstring

acosclj

(acos vector)

Apply acos to vector elements.

Apply acos to vector elements.
sourceraw docstring

acoshclj

(acosh vector)

Apply acosh to vector elements.

Apply acosh to vector elements.
sourceraw docstring

acotclj

(acot vector)

Apply acot to vector elements.

Apply acot to vector elements.
sourceraw docstring

acothclj

(acoth vector)

Apply acoth to vector elements.

Apply acoth to vector elements.
sourceraw docstring

acscclj

(acsc vector)

Apply acsc to vector elements.

Apply acsc to vector elements.
sourceraw docstring

acschclj

(acsch vector)

Apply acsch to vector elements.

Apply acsch to vector elements.
sourceraw docstring

addclj

(add v)
(add v1 v2)

Sum of two vectors.

Sum of two vectors.
sourceraw docstring

aligned?clj

(aligned? v1 v2)
(aligned? v1 v2 tol)

Are vectors aligned (have the same direction)?

Are vectors aligned (have the same direction)?
sourceraw docstring

angle-betweenclj

(angle-between v1 v2)

Angle between two vectors

See also relative-angle-between.

Angle between two vectors

See also [[relative-angle-between]].
sourceraw docstring

applyfcljdeprecated

Same as fmap. Deprecated.

Same as [[fmap]]. Deprecated.
sourceraw docstring

approxclj

(approx v)
(approx v d)

Round to 2 (or d) decimal places

Round to 2 (or `d`) decimal places
sourceraw docstring

array->vec2clj

(array->vec2 arr)

Doubles array to Vec2

Doubles array to Vec2
sourceraw docstring

array->vec3clj

(array->vec3 arr)

Doubles array to Vec3

Doubles array to Vec3
sourceraw docstring

array->vec4clj

(array->vec4 arr)

Doubles array to Vec4

Doubles array to Vec4
sourceraw docstring

array-vecclj

(array-vec xs)

Make ArrayVec type based on provided sequence xs.

Make ArrayVec type based on provided sequence `xs`.
sourceraw docstring

as-vecclj

(as-vec v)
(as-vec v xs)

Create vector from sequence as given type. If there is no sequence fill with 0.0.

Create vector from sequence as given type. If there is no sequence fill with `0.0`.
sourceraw docstring

asecclj

(asec vector)

Apply asec to vector elements.

Apply asec to vector elements.
sourceraw docstring

asechclj

(asech vector)

Apply asech to vector elements.

Apply asech to vector elements.
sourceraw docstring

asinclj

(asin vector)

Apply asin to vector elements.

Apply asin to vector elements.
sourceraw docstring

asinhclj

(asinh vector)

Apply asinh to vector elements.

Apply asinh to vector elements.
sourceraw docstring

atanclj

(atan vector)

Apply atan to vector elements.

Apply atan to vector elements.
sourceraw docstring

atanhclj

(atanh vector)

Apply atanh to vector elements.

Apply atanh to vector elements.
sourceraw docstring

averageclj

(average v)
(average v weights)

Mean or weighted average of the vector

Mean or weighted average of the vector
sourceraw docstring

average-vectorsclj

(average-vectors vs)
(average-vectors init vs)

Average / centroid of vectors. Input: initial vector (optional), list of vectors

Average / centroid of vectors. Input: initial vector (optional), list of vectors
sourceraw docstring

axis-rotateclj

(axis-rotate v angle axis)
(axis-rotate v angle axis pivot)

Rotate vector. Only for Vec3 types

Rotate vector. Only for `Vec3` types
sourceraw docstring

base-fromclj

(base-from v)

List of perpendicular vectors (basis). Works only for Vec2 and Vec3 types.

List of perpendicular vectors (basis). Works only for `Vec2` and `Vec3` types.
sourceraw docstring

cbclj

(cb vector)

Apply cb to vector elements.

Apply cb to vector elements.
sourceraw docstring

cbrtclj

(cbrt vector)

Apply cbrt to vector elements.

Apply cbrt to vector elements.
sourceraw docstring

ceilclj

(ceil vector)

Apply ceil to vector elements.

Apply ceil to vector elements.
sourceraw docstring

clampclj

(clamp v)
(clamp v mn mx)

Clamp elements.

Clamp elements.
sourceraw docstring

cosclj

(cos vector)

Apply cos to vector elements.

Apply cos to vector elements.
sourceraw docstring

coshclj

(cosh vector)

Apply cosh to vector elements.

Apply cosh to vector elements.
sourceraw docstring

cotclj

(cot vector)

Apply cot to vector elements.

Apply cot to vector elements.
sourceraw docstring

cothclj

(coth vector)

Apply coth to vector elements.

Apply coth to vector elements.
sourceraw docstring

crossclj

(cross v1 v2)

Cross product

Cross product
sourceraw docstring

cscclj

(csc vector)

Apply csc to vector elements.

Apply csc to vector elements.
sourceraw docstring

cschclj

(csch vector)

Apply csch to vector elements.

Apply csch to vector elements.
sourceraw docstring

degreesclj

(degrees vector)

Apply degrees to vector elements.

Apply degrees to vector elements.
sourceraw docstring

delta-eqclj

(delta-eq v1 v2)
(delta-eq v1 v2 abs-tol)
(delta-eq v1 v2 abs-tol rel-tol)

Equality with given absolute (and/or relative) toleance.

Equality with given absolute (and/or relative) toleance.
sourceraw docstring

dhash-codeclj

(dhash-code a)
(dhash-code state a)

double hashcode

double hashcode
sourceraw docstring

distclj

(dist v1 v2)

Euclidean distance between vectors

Euclidean distance between vectors
sourceraw docstring

dist-absclj

(dist-abs v1 v2)

Manhattan distance between vectors

Manhattan distance between vectors
sourceraw docstring

dist-angclj

(dist-ang v1 v2)

Angular distance

Angular distance
sourceraw docstring

dist-canberraclj

(dist-canberra v1 v2)

Canberra distance

Canberra distance
sourceraw docstring

dist-chebclj

(dist-cheb v1 v2)

Chebyshev distance between 2d vectors

Chebyshev distance between 2d vectors
sourceraw docstring

dist-discreteclj

(dist-discrete v1 v2)

Discrete distance between 2d vectors

Discrete distance between 2d vectors
sourceraw docstring

dist-emdclj

(dist-emd v1 v2)

Earth Mover's Distance

Earth Mover's Distance
sourceraw docstring

dist-sqclj

(dist-sq v1 v2)

Squared Euclidean distance between vectors

Squared Euclidean distance between vectors
sourceraw docstring

distancesclj

source

divclj

(div v1)
(div v1 v)

Vector division or reciprocal.

Vector division or reciprocal.
sourceraw docstring

dotclj

(dot v1 v2)

Dot product of two vectors.

Dot product of two vectors.
sourceraw docstring

econstrainclj

(econstrain v mn mx)

Element-wise constrain

Element-wise constrain
sourceraw docstring

edivclj

(ediv v1 v2)

Element-wise division of two vectors.

Element-wise division of two vectors.
sourceraw docstring

einterpolateclj

(einterpolate v1 v2 v)
(einterpolate v1 v2 v f)

Interpolate vector selement-wise, optionally set interpolation fn (default: lerp)

Interpolate vector selement-wise, optionally set interpolation fn (default: lerp)
sourceraw docstring

emnclj

(emn v1 v2)

Element-wise min from two vectors.

Element-wise min from two vectors.
sourceraw docstring

emultclj

(emult v1 v2)

Element-wise vector multiplication (Hadamard product).

Element-wise vector multiplication (Hadamard product).
sourceraw docstring

emxclj

(emx v1 v2)

Element-wise max from two vectors.

Element-wise max from two vectors.
sourceraw docstring

expclj

(exp vector)

Apply exp to vector elements.

Apply exp to vector elements.
sourceraw docstring

expm1clj

(expm1 vector)

Apply expm1 to vector elements.

Apply expm1 to vector elements.
sourceraw docstring

faceforwardclj

(faceforward n v)

Flip normal n to match the same direction as v.

Flip normal `n` to match the same direction as `v`.
sourceraw docstring

floorclj

(floor vector)

Apply floor to vector elements.

Apply floor to vector elements.
sourceraw docstring

fmapclj

(fmap v f)

Apply function to all vector values (like map but returns the same type).

Apply function to all vector values (like map but returns the same type).
sourceraw docstring

fracclj

(frac vector)

Apply frac to vector elements.

Apply frac to vector elements.
sourceraw docstring

from-polarclj

(from-polar v)

From polar coordinates (2d, 3d only)

From polar coordinates (2d, 3d only)
sourceraw docstring

generate-vec2clj

(generate-vec2 f)
(generate-vec2 f1 f2)

Generate Vec2 with fn(s)

Generate Vec2 with fn(s)
sourceraw docstring

generate-vec3clj

(generate-vec3 f)
(generate-vec3 f1 f2 f3)

Generate Vec3 with fn(s)

Generate Vec3 with fn(s)
sourceraw docstring

generate-vec4clj

(generate-vec4 f)
(generate-vec4 f1 f2 f3 f4)

Generate Vec4 with fn(s)

Generate Vec4 with fn(s)
sourceraw docstring

headingclj

(heading v)

Angle between vector and unit vector [1,0,...]

Angle between vector and unit vector `[1,0,...]`
sourceraw docstring

interpolateclj

(interpolate v1 v2 t)
(interpolate v1 v2 t f)

Interpolate vectors, optionally set interpolation fn (default: lerp)

Interpolate vectors, optionally set interpolation fn (default: lerp)
sourceraw docstring

is-near-zero?clj

(is-near-zero? v)
(is-near-zero? v abs-tol)
(is-near-zero? v abs-tol rel-tol)

Equality to zero 0 with given absolute (and/or relative) toleance.

Equality to zero `0` with given absolute (and/or relative) toleance.
sourceraw docstring

is-zero?clj

(is-zero? v)

Is vector zero?

Is vector zero?
sourceraw docstring

jincclj

(jinc vector)

Apply jinc to vector elements.

Apply jinc to vector elements.
sourceraw docstring

lerpclj

(lerp v1 v2 t)

Linear interpolation of vectors

Linear interpolation of vectors
sourceraw docstring

limitclj

(limit v len)

Limit length of the vector by given value

Limit length of the vector by given value
sourceraw docstring

lnclj

(ln vector)

Apply ln to vector elements.

Apply ln to vector elements.
sourceraw docstring

logclj

(log vector)

Apply log to vector elements.

Apply log to vector elements.
sourceraw docstring

log10clj

(log10 vector)

Apply log10 to vector elements.

Apply log10 to vector elements.
sourceraw docstring

log1mexpclj

(log1mexp vector)

Apply log1mexp to vector elements.

Apply log1mexp to vector elements.
sourceraw docstring

log1pclj

(log1p vector)

Apply log1p to vector elements.

Apply log1p to vector elements.
sourceraw docstring

log1pexpclj

(log1pexp vector)

Apply log1pexp to vector elements.

Apply log1pexp to vector elements.
sourceraw docstring

log1pmxclj

(log1pmx vector)

Apply log1pmx to vector elements.

Apply log1pmx to vector elements.
sourceraw docstring

log1psqclj

(log1psq vector)

Apply log1psq to vector elements.

Apply log1psq to vector elements.
sourceraw docstring

log2clj

(log2 vector)

Apply log2 to vector elements.

Apply log2 to vector elements.
sourceraw docstring

logexpm1clj

(logexpm1 vector)

Apply logexpm1 to vector elements.

Apply logexpm1 to vector elements.
sourceraw docstring

logitclj

(logit vector)

Apply logit to vector elements.

Apply logit to vector elements.
sourceraw docstring

logmeanexpclj

(logmeanexp v)
source

logmxp1clj

(logmxp1 vector)

Apply logmxp1 to vector elements.

Apply logmxp1 to vector elements.
sourceraw docstring

logsoftmaxclj

(logsoftmax v)
source

logsumexpclj

(logsumexp v)
source

magclj

(mag v)

Length of the vector.

Length of the vector.
sourceraw docstring

magsqclj

(magsq v)

Length of the vector squared.

Length of the vector squared.
sourceraw docstring

make-vectorclj

(make-vector dims)
(make-vector dims xs)

Returns fixed size vector for given number of dimensions.

Proper type is used.

Returns fixed size vector for given number of dimensions.

Proper type is used.
sourceraw docstring

maxdimclj

(maxdim v)

Index of maximum value.

Index of maximum value.
sourceraw docstring

mindimclj

(mindim v)

Index of minimum value.

Index of minimum value.
sourceraw docstring

mnclj

(mn v)

Minimum value of vector elements

Minimum value of vector elements
sourceraw docstring

multclj

(mult v x)

Multiply vector by number x.

Multiply vector by number `x`.
sourceraw docstring

mxclj

(mx v)

Maximum value of vector elements

Maximum value of vector elements
sourceraw docstring

near-zero?clj

(near-zero? v)
(near-zero? v abs-tol)
(near-zero? v abs-tol rel-tol)

Equality to zero 0 with given absolute (and/or relative) toleance.

Equality to zero `0` with given absolute (and/or relative) toleance.
sourceraw docstring

nonzero-countclj

(nonzero-count v)

Count non zero velues in vector

Count non zero velues in vector
sourceraw docstring

normalizeclj

(normalize v)

Normalize vector (set length = 1.0)

Normalize vector (set length = 1.0)
sourceraw docstring

permuteclj

(permute v idxs)

Permute vector elements with given indices.

Permute vector elements with given indices.
sourceraw docstring

perpendicularclj

(perpendicular v)
(perpendicular v1 v2)

Perpendicular vector. Only for Vec2 and Vec3 types.

Perpendicular vector. Only for `Vec2` and `Vec3` types.
sourceraw docstring

prodclj

(prod v)

Product of elements

Product of elements
sourceraw docstring

projectclj

(project v1 v2)

Project v1 onto v2

Project `v1` onto `v2`
sourceraw docstring

radiansclj

(radians vector)

Apply radians to vector elements.

Apply radians to vector elements.
sourceraw docstring

reciprocalclj

(reciprocal v)

Reciprocal of elements.

Reciprocal of elements.
sourceraw docstring

relative-angle-betweenclj

(relative-angle-between v1 v2)

Angle between two vectors relative to each other.

See also angle-between.

Angle between two vectors relative to each other.

See also [[angle-between]].
sourceraw docstring

rintclj

(rint vector)

Apply rint to vector elements.

Apply rint to vector elements.
sourceraw docstring

rotateclj

(rotate v angle)
(rotate v angle-x angle-y angle-z)

Rotate vector. Only for Vec2 and Vec3 types.

Rotate vector. Only for `Vec2` and `Vec3` types.
sourceraw docstring

roundclj

(round vector)

Apply round to vector elements.

Apply round to vector elements.
sourceraw docstring

safe-sqrtclj

(safe-sqrt vector)

Apply safe-sqrt to vector elements.

Apply safe-sqrt to vector elements.
sourceraw docstring

secclj

(sec vector)

Apply sec to vector elements.

Apply sec to vector elements.
sourceraw docstring

sechclj

(sech vector)

Apply sech to vector elements.

Apply sech to vector elements.
sourceraw docstring

seq->vec2clj

(seq->vec2 xs)

Any seq to Vec2

Any seq to Vec2
sourceraw docstring

seq->vec3clj

(seq->vec3 xs)

Any seq to Vec3

Any seq to Vec3
sourceraw docstring

seq->vec4clj

(seq->vec4 xs)

Any seq to Vec4

Any seq to Vec4
sourceraw docstring

set-magclj

(set-mag v len)

Set length of the vector

Set length of the vector
sourceraw docstring

sfracclj

(sfrac vector)

Apply sfrac to vector elements.

Apply sfrac to vector elements.
sourceraw docstring

sgnclj

(sgn vector)

Apply sgn to vector elements.

Apply sgn to vector elements.
sourceraw docstring

shiftclj

(shift v)
(shift v x)

Add value to every vector element.

Add value to every vector element.
sourceraw docstring

sigmoidclj

(sigmoid vector)

Apply sigmoid to vector elements.

Apply sigmoid to vector elements.
sourceraw docstring

signumclj

(signum vector)

Apply signum to vector elements.

Apply signum to vector elements.
sourceraw docstring

sim-cosclj

(sim-cos v1 v2)

Cosine similarity

Cosine similarity
sourceraw docstring

sinclj

(sin vector)

Apply sin to vector elements.

Apply sin to vector elements.
sourceraw docstring

sincclj

(sinc vector)

Apply sinc to vector elements.

Apply sinc to vector elements.
sourceraw docstring

sinhclj

(sinh vector)

Apply sinh to vector elements.

Apply sinh to vector elements.
sourceraw docstring

softmaxclj

(softmax v)
source

sqclj

(sq vector)

Apply sq to vector elements.

Apply sq to vector elements.
sourceraw docstring

sqrtclj

(sqrt vector)

Apply sqrt to vector elements.

Apply sqrt to vector elements.
sourceraw docstring

subclj

(sub v)
(sub v1 v2)

Subtraction of two vectors.

Subtraction of two vectors.
sourceraw docstring

sumclj

(sum v)

Sum of elements

Sum of elements
sourceraw docstring

tanclj

(tan vector)

Apply tan to vector elements.

Apply tan to vector elements.
sourceraw docstring

tanhclj

(tanh vector)

Apply tanh to vector elements.

Apply tanh to vector elements.
sourceraw docstring

to-polarclj

(to-polar v)

To polar coordinates (2d, 3d only), first element is length, the rest angle.

To polar coordinates (2d, 3d only), first element is length, the rest angle.
sourceraw docstring

to-veccljdeprecated

Same as vec->Vec. Deprecated.

Same as [[vec->Vec]]. Deprecated.
sourceraw docstring

transformclj

(transform v o vx vy)
(transform v o vx vy vz)

Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), Only for Vec2 and Vec3 types.

Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), Only for `Vec2` and `Vec3` types.
sourceraw docstring

triple-productclj

(triple-product a b c)

a o (b x c)

a o (b x c)
sourceraw docstring

truncclj

(trunc vector)

Apply trunc to vector elements.

Apply trunc to vector elements.
sourceraw docstring

vec->arrayclj

(vec->array v)

Convert to double array

Convert to double array
sourceraw docstring

vec->RealVectorclj

(vec->RealVector v)

Convert to Apache Commons Math RealVector

Convert to Apache Commons Math RealVector
sourceraw docstring

vec->Vecclj

(vec->Vec v)

Convert to Clojure primitive vector Vec.

Convert to Clojure primitive vector `Vec`.
sourceraw docstring

vec2clj

(vec2)
(vec2 x y)

Make 2d vector.

Make 2d vector.
sourceraw docstring

vec3clj

(vec3)
(vec3 v z)
(vec3 x y z)

Make Vec2 vector

Make Vec2 vector
sourceraw docstring

vec4clj

(vec4)
(vec4 v w)
(vec4 v z w)
(vec4 x y z w)

Make Vec4 vector

Make Vec4 vector
sourceraw docstring

xlogxclj

(xlogx vector)

Apply xlogx to vector elements.

Apply xlogx to vector elements.
sourceraw docstring

zero-countclj

(zero-count v)

Count zeros in vector

Count zeros in vector
sourceraw docstring

zero?clj

(zero? v)

Is vector zero?

Is vector zero?
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close