Liking cljdoc? Tell your friends :D

fastmath.vector

Provides mathematical vector operations for various vector types, inspired by libraries like Processing and openFrameworks.

Supported vector representations include:

  • Fixed-size custom types: Vec2 (2D), Vec3 (3D), Vec4 (4D), and ArrayVec (N-dimensional wrapper around double[]).
  • Built-in array type: double arrays ([D).
  • Variable-size Clojure collections: persistent vectors ([]) and sequences (ISeq).
  • Numbers: Treated as 1D vectors.

Most operations are defined via the [[VectorProto]] protocol, which is extended for all supported types.

These vector types also implement standard Clojure/Java protocols like Seqable, Indexed, IFn, Counted, Associative, IReduce, ILookup, etc., enabling them to be used flexibly as sequences, arrays, or functions.

Provides mathematical vector operations for various vector types, inspired by libraries like Processing and openFrameworks.

Supported vector representations include:

*   **Fixed-size custom types**: `Vec2` (2D), `Vec3` (3D), `Vec4` (4D), and `ArrayVec` (N-dimensional wrapper around `double[]`).
*   **Built-in array type**: `double` arrays (`[D`).
*   **Variable-size Clojure collections**: persistent vectors (`[]`) and sequences (`ISeq`).
*   **Numbers**: Treated as 1D vectors.

Most operations are defined via the [[VectorProto]] protocol, which is extended for all supported types.

These vector types also implement standard Clojure/Java protocols like `Seqable`, `Indexed`, `IFn`, `Counted`, `Associative`, `IReduce`, `ILookup`, etc., enabling them to be used flexibly as sequences, arrays, or functions.
raw docstring

absclj

(abs v)

Absolute value of vector elements

Absolute value of vector elements
sourceraw docstring

acosclj

(acos vector)

Applies acos to vector elements.

Applies acos to vector elements.
sourceraw docstring

acoshclj

(acosh vector)

Applies acosh to vector elements.

Applies acosh to vector elements.
sourceraw docstring

acotclj

(acot vector)

Applies acot to vector elements.

Applies acot to vector elements.
sourceraw docstring

acothclj

(acoth vector)

Applies acoth to vector elements.

Applies acoth to vector elements.
sourceraw docstring

acscclj

(acsc vector)

Applies acsc to vector elements.

Applies acsc to vector elements.
sourceraw docstring

acschclj

(acsch vector)

Applies acsch to vector elements.

Applies 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)

Checks if two vectors are aligned, meaning they point in approximately the same direction. This is determined by checking if the angle between them (calculated using angle-between) is less than the specified tolerance.

Defaults to an absolute tolerance of 1.0e-6.

Checks if two vectors are aligned, meaning they point in approximately the same direction.
This is determined by checking if the angle between them (calculated using [[angle-between]])
is less than the specified `tolerance`.

Defaults to an absolute tolerance of `1.0e-6`.
sourceraw docstring

angle-betweenclj

(angle-between v1 v2)

Returns the angle between two vectors in radians.

The angle is always positive and lies between 0 and π. Returns 0 if either vector is zero.

Returns the angle between two vectors in radians.

The angle is always positive and lies between 0 and π.
Returns 0 if either vector is zero.
sourceraw docstring

applyfcljdeprecated

Same as fmap. Deprecated.

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

approxclj

(approx v)
(approx v d)

Rounds to d (default: 2) decimal places

Rounds to `d` (default: 2) decimal places
sourceraw docstring

array->vec2clj

(array->vec2 arr)

Converts doubles array to Vec2

Converts doubles array to Vec2
sourceraw docstring

array->vec3clj

(array->vec3 arr)

Converts doubles array to Vec3

Converts doubles array to Vec3
sourceraw docstring

array->vec4clj

(array->vec4 arr)

Converts doubles array to Vec4

Converts doubles array to Vec4
sourceraw docstring

array-vecclj

(array-vec xs)

Creates ArrayVec type based on provided sequence xs.

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

as-vecclj

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

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

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

asecclj

(asec vector)

Applies asec to vector elements.

Applies asec to vector elements.
sourceraw docstring

asechclj

(asech vector)

Applies asech to vector elements.

Applies asech to vector elements.
sourceraw docstring

asinclj

(asin vector)

Applies asin to vector elements.

Applies asin to vector elements.
sourceraw docstring

asinhclj

(asinh vector)

Applies asinh to vector elements.

Applies asinh to vector elements.
sourceraw docstring

atanclj

(atan vector)

Applies atan to vector elements.

Applies atan to vector elements.
sourceraw docstring

atanhclj

(atanh vector)

Applies atanh to vector elements.

Applies 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)

Rotates vector. Only for Vec3 types

Rotates 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)

Applies cb to vector elements.

Applies cb to vector elements.
sourceraw docstring

cbrtclj

(cbrt vector)

Applies cbrt to vector elements.

Applies cbrt to vector elements.
sourceraw docstring

ceilclj

(ceil vector)

Applies ceil to vector elements.

Applies ceil to vector elements.
sourceraw docstring

clampclj

(clamp v)
(clamp v mn mx)

Clamps the elements of vector v element-wise between a minimum (mn) and maximum (mx) value.

In the single-arity version [v], elements are clamped between 0.0 and Double/MAX_VALUE.

Clamps the elements of vector `v` element-wise between a minimum (`mn`) and maximum (`mx`) value.

In the single-arity version `[v]`, elements are clamped between 0.0 and `Double/MAX_VALUE`.
sourceraw docstring

cosclj

(cos vector)

Applies cos to vector elements.

Applies cos to vector elements.
sourceraw docstring

coshclj

(cosh vector)

Applies cosh to vector elements.

Applies cosh to vector elements.
sourceraw docstring

cotclj

(cot vector)

Applies cot to vector elements.

Applies cot to vector elements.
sourceraw docstring

cothclj

(coth vector)

Applies coth to vector elements.

Applies coth to vector elements.
sourceraw docstring

crossclj

(cross v1 v2)

Cross product

Cross product
sourceraw docstring

cscclj

(csc vector)

Applies csc to vector elements.

Applies csc to vector elements.
sourceraw docstring

cschclj

(csch vector)

Applies csch to vector elements.

Applies csch to vector elements.
sourceraw docstring

degreesclj

(degrees vector)

Applies degrees to vector elements.

Applies 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

differencesclj

(differences v)
(differences v diffs)
(differences v diffs lag)

Computes the lagged differences of a vector or sequence.

This function calculates the difference between elements separated by a fixed distance (lag) and can apply this operation diffs times.

It supports multiple arities:

  • [v]: Computes the 1st difference with lag 1 (default: diffs=1, lag=1).
  • [v diffs]: Computes the diffs-th difference with lag 1 (default: lag=1).
  • [v diffs lag]: Computes the diffs-th difference with the specified lag.

Returns a sequence of the computed differences.

Computes the lagged differences of a vector or sequence.

This function calculates the difference between elements separated by a fixed distance (`lag`)
and can apply this operation `diffs` times.

It supports multiple arities:
- `[v]`: Computes the 1st difference with lag 1 (default: `diffs=1`, `lag=1`).
- `[v diffs]`: Computes the `diffs`-th difference with lag 1 (default: `lag=1`).
- `[v diffs lag]`: Computes the `diffs`-th difference with the specified `lag`.

Returns a sequence of the computed differences.
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)
(dist-discrete v1 v2 eps)

Computes the discrete distance between two vectors v1 and v2.

This is the number of positions where the corresponding elements are considered different. With an optional absolute tolerance eps, elements at index i are considered different if |v1_i - v2_i| > eps.

Returns the count of differing elements.

Computes the discrete distance between two vectors `v1` and `v2`.

This is the number of positions where the corresponding elements are considered different.
With an optional absolute tolerance `eps`, elements at index `i` are considered different if `|v1_i - v2_i| > eps`.

Returns the count of differing elements.
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

edelta-eqclj

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

Element-wise equality with given absolute (and/or relative) toleance.

Element-wise equality with given absolute (and/or relative) toleance.
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)

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

Interpolates 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)
(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)

Applies exp to vector elements.

Applies exp to vector elements.
sourceraw docstring

expm1clj

(expm1 vector)

Applies expm1 to vector elements.

Applies expm1 to vector elements.
sourceraw docstring

faceforwardclj

(faceforward n v)

Flips vector n if dot(n, v) is negative. Returns n if dot(n, v) is non-negative. Useful for ensuring consistent vector orientation, such as making a normal vector face towards a reference vector v.

Flips vector `n` if `dot(n, v)` is negative. Returns `n` if `dot(n, v)` is non-negative. Useful for ensuring consistent vector orientation, such as making a normal vector face towards a reference vector `v`.
sourceraw docstring

floorclj

(floor vector)

Applies floor to vector elements.

Applies floor to vector elements.
sourceraw docstring

fmapclj

(fmap v f)

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

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

fracclj

(frac vector)

Applies frac to vector elements.

Applies 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)

Generates Vec2 with fn(s)

Generates Vec2 with fn(s)
sourceraw docstring

generate-vec3clj

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

Generates Vec3 with fn(s)

Generates Vec3 with fn(s)
sourceraw docstring

generate-vec4clj

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

Generates Vec4 with fn(s)

Generates 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)

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

Interpolates 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

lerpclj

(lerp v1 v2 t)

Linear interpolation of vectors

Linear interpolation of vectors
sourceraw docstring

limitclj

(limit v len)

Limits length of the vector by given value

Limits length of the vector by given value
sourceraw docstring

lnclj

(ln vector)

Applies ln to vector elements.

Applies ln to vector elements.
sourceraw docstring

logclj

(log vector)

Applies log to vector elements.

Applies log to vector elements.
sourceraw docstring

log10clj

(log10 vector)

Applies log10 to vector elements.

Applies log10 to vector elements.
sourceraw docstring

log1mexpclj

(log1mexp vector)

Applies log1mexp to vector elements.

Applies log1mexp to vector elements.
sourceraw docstring

log1pclj

(log1p vector)

Applies log1p to vector elements.

Applies log1p to vector elements.
sourceraw docstring

log1pexpclj

(log1pexp vector)

Applies log1pexp to vector elements.

Applies log1pexp to vector elements.
sourceraw docstring

log1pmxclj

(log1pmx vector)

Applies log1pmx to vector elements.

Applies log1pmx to vector elements.
sourceraw docstring

log1psqclj

(log1psq vector)

Applies log1psq to vector elements.

Applies log1psq to vector elements.
sourceraw docstring

log2clj

(log2 vector)

Applies log2 to vector elements.

Applies log2 to vector elements.
sourceraw docstring

logexpm1clj

(logexpm1 vector)

Applies logexpm1 to vector elements.

Applies logexpm1 to vector elements.
sourceraw docstring

logitclj

(logit vector)

Applies logit to vector elements.

Applies logit to vector elements.
sourceraw docstring

logmeanexpclj

(logmeanexp v)

Calculates the numerically stable log of the mean of the exponential of each element in vector v.

This is equivalent to log(mean(exp(v_i))) for all elements v_i in v. It provides a numerically stable way to compute log(sum(exp(v_i))) - log(count(v)) by shifting values to prevent overflow during exponentiation.

Often used in machine learning and statistical contexts where dealing with large values inside exponentials is common.

Returns a double value.

Calculates the numerically stable log of the mean of the exponential of each element in vector `v`.

This is equivalent to `log(mean(exp(v_i)))` for all elements `v_i` in `v`.
It provides a numerically stable way to compute `log(sum(exp(v_i))) - log(count(v))` by shifting values to prevent overflow during exponentiation.

Often used in machine learning and statistical contexts where dealing with large values inside exponentials is common.

Returns a double value.
sourceraw docstring

logmxp1clj

(logmxp1 vector)

Applies logmxp1 to vector elements.

Applies logmxp1 to vector elements.
sourceraw docstring

logsoftmaxclj

(logsoftmax v)
(logsoftmax v t)

Calculates the element-wise natural logarithm of the softmax function for the given vector v.

The standard log-softmax of an element $v_i$ is $\log(\operatorname{softmax}(v)_i)$, which is mathematically equivalent to $v_i - \log(\sum_j \exp(v_j))$. This function provides a numerically stable implementation of this calculation, particularly useful for avoiding overflow and underflow issues when dealing with large or small exponential values.

It supports two arities:

  • [v]: Computes the standard log-softmax using the numerically stable form.
  • [v t]: Computes the temperature-scaled log-softmax. Elements are divided by the temperature t before applying the log-softmax formula, i.e., $\frac{v_i}{t} - \log(\sum_j \wxp(\fac{v_j}{t}))$. The temperature influences the shape of the corresponding softmax output distribution: $t > 1$ softens it, $t < 1$ sharpens it.

Log-softmax is frequently used in numerical computations, especially in machine learning (e.g., as part of the cross-entropy loss function) for its superior numerical properties.

Returns a new vector of the same type and dimension as the input.

Calculates the element-wise natural logarithm of the softmax function for the given vector `v`.

The standard log-softmax of an element $v_i$ is $\log(\operatorname{softmax}(v)_i)$, which is mathematically equivalent to $v_i - \log(\sum_j \exp(v_j))$.
This function provides a numerically stable implementation of this calculation, particularly useful for avoiding overflow and underflow issues when dealing with large or small exponential values.

It supports two arities:
- `[v]`: Computes the standard log-softmax using the numerically stable form.
- `[v t]`: Computes the temperature-scaled log-softmax. Elements are divided by the temperature `t` *before* applying the log-softmax formula, i.e., $\frac{v_i}{t} - \log(\sum_j \wxp(\fac{v_j}{t}))$. The temperature influences the shape of the corresponding softmax output distribution: $t > 1$ softens it, $t < 1$ sharpens it.

Log-softmax is frequently used in numerical computations, especially in machine learning (e.g., as part of the cross-entropy loss function) for its superior numerical properties.

Returns a new vector of the same type and dimension as the input.
sourceraw docstring

logsumexpclj

(logsumexp v)

Calculates the LogSumExp of the vector v.

This is the numerically stable computation of log(sum(exp(x_i))) for all elements x_i in v. It is often used to prevent overflow when exponentiating large numbers, especially in machine learning and statistics.

Returns a double value.

Calculates the LogSumExp of the vector `v`.

This is the numerically stable computation of `log(sum(exp(x_i)))` for all elements `x_i` in `v`.
It is often used to prevent overflow when exponentiating large numbers, especially in machine learning and statistics.

Returns a double value.
sourceraw docstring

magclj

(mag v)

Returns length of the vector.

Returns length of the vector.
sourceraw docstring

magsqclj

(magsq v)

Returns length of the vector squared.

Returns 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)
(mult v x)

Multiplies vector by number x.

Multiplies 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)

Counts non zero velues in vector

Counts non zero velues in vector
sourceraw docstring

normalizeclj

(normalize v)

Returns a new vector with the same direction as v but with a magnitude of 1.

If v is a zero vector (magnitude is zero), returns a zero vector of the same type.

Returns a new vector with the same direction as `v` but with a magnitude of 1.

If `v` is a zero vector (magnitude is zero), returns a zero vector of the same type.
sourceraw docstring

orthogonal-polynomialsclj

(orthogonal-polynomials xs)

Generates a sequence of orthogonal vectors by evaluating orthogonal polynomials at the points specified in the input sequence xs.

The output vectors represent the values of orthogonal polynomials evaluated at the elements of xs. Orthogonality is defined with respect to the discrete inner product based on summation over the points in xs.

The sequence starts with the vector for the polynomial of degree 1 and includes vectors up to degree (count xs) - 1.

This function is useful for constructing orthogonal bases for polynomial approximation or regression on discrete data.

Generates a sequence of orthogonal vectors by evaluating orthogonal polynomials at the points specified in the input sequence `xs`.

The output vectors represent the values of orthogonal polynomials evaluated at the elements of `xs`. Orthogonality is defined with respect to the discrete inner product based on summation over the points in `xs`.

The sequence starts with the vector for the polynomial of degree 1 and includes vectors up to degree `(count xs) - 1`.

This function is useful for constructing orthogonal bases for polynomial approximation or regression on discrete data.
sourceraw docstring

orthonormal-polynomialsclj

(orthonormal-polynomials xs)

Generates a sequence of orthonormal vectors by evaluating orthogonal polynomials at the points specified in the input sequence xs and normalizing the resulting vectors.

The sequence starts with the vector for the polynomial of degree 1 and includes vectors up to degree (count xs) - 1. Orthogonality (and thus orthonormality after normalization) is with respect to the discrete inner product based on summation over the points in xs.

This function produces an orthonormal basis suitable for polynomial approximation or regression on discrete data points defined by xs, derived from the orthogonal basis computed by orthogonal-polynomials.

Generates a sequence of orthonormal vectors by evaluating orthogonal polynomials at the points specified in the input sequence `xs` and normalizing the resulting vectors.

The sequence starts with the vector for the polynomial of degree 1 and includes vectors up to degree `(count xs) - 1`. Orthogonality (and thus orthonormality after normalization) is with respect to the discrete inner product based on summation over the points in `xs`.

This function produces an orthonormal basis suitable for polynomial approximation or regression on discrete data points defined by `xs`, derived from the orthogonal basis computed by [[orthogonal-polynomials]].
sourceraw docstring

permuteclj

(permute v idxs)

Permutes vector elements with given indices.

Permutes 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

powclj

(pow v exponent)

Applies power to a vector elements.

Applies power to a vector elements.
sourceraw docstring

pow10clj

(pow10 vector)

Applies pow10 to vector elements.

Applies pow10 to vector elements.
sourceraw docstring

prodclj

(prod)
(prod v)

Product of elements

Product of elements
sourceraw docstring

projectclj

(project v1 v2)

Calculates the vector projection of v1 onto v2. The projection is a vector along the direction of v2 that represents the component of v1 in that direction.

Calculates the vector projection of `v1` onto `v2`.
The projection is a vector along the direction of `v2` that represents the component of `v1` in that direction.
sourceraw docstring

radiansclj

(radians vector)

Applies radians to vector elements.

Applies radians to vector elements.
sourceraw docstring

real-vectorclj

(real-vector v)

Converts to Apache Commons Math RealVector

Converts to Apache Commons Math RealVector
sourceraw docstring

reciprocalclj

(reciprocal v)

Reciprocal of elements.

Reciprocal of elements.
sourceraw docstring

relative-angle-betweenclj

(relative-angle-between v1 v2)

Returns the difference between the heading of v2 and the heading of v1. The heading is the angle relative to the positive primary axis ([1,0,...]). For 2D vectors, this is the difference between their polar angles.

Returns value from $-2\pi$ to $2\pi$.

See also angle-between (absolute angle between vectors) and heading.

Returns the difference between the heading of `v2` and the heading of `v1`.
The heading is the angle relative to the positive primary axis ([1,0,...]).
For 2D vectors, this is the difference between their polar angles.

Returns value from $-2\pi$ to $2\pi$.

See also [[angle-between]] (absolute angle between vectors) and [[heading]].
sourceraw docstring

rintclj

(rint vector)

Applies rint to vector elements.

Applies rint to vector elements.
sourceraw docstring

rotateclj

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

Rotates vector. Only for Vec2 and Vec3 types.

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

roundclj

(round vector)

Applies round to vector elements.

Applies round to vector elements.
sourceraw docstring

safe-sqrtclj

(safe-sqrt vector)

Applies safe-sqrt to vector elements.

Applies safe-sqrt to vector elements.
sourceraw docstring

secclj

(sec vector)

Applies sec to vector elements.

Applies sec to vector elements.
sourceraw docstring

sechclj

(sech vector)

Applies sech to vector elements.

Applies sech to vector elements.
sourceraw docstring

seq->vec2clj

(seq->vec2 xs)

Converts any seq to Vec2

Converts any seq to Vec2
sourceraw docstring

seq->vec3clj

(seq->vec3 xs)

Converts any seq to Vec3

Converts any seq to Vec3
sourceraw docstring

seq->vec4clj

(seq->vec4 xs)

Converts any seq to Vec4

Converts any seq to Vec4
sourceraw docstring

set-magclj

(set-mag v len)

Sets length of the vector.

Sets length of the vector.
sourceraw docstring

sfracclj

(sfrac vector)

Applies sfrac to vector elements.

Applies sfrac to vector elements.
sourceraw docstring

sgnclj

(sgn vector)

Applies sgn to vector elements.

Applies sgn to vector elements.
sourceraw docstring

shiftclj

(shift v)
(shift v x)

Adds a value to every vector element.

Adds a value to every vector element.
sourceraw docstring

sigmoidclj

(sigmoid vector)

Applies sigmoid to vector elements.

Applies sigmoid to vector elements.
sourceraw docstring

signumclj

(signum vector)

Applies signum to vector elements.

Applies signum to vector elements.
sourceraw docstring

sim-cosclj

(sim-cos v1 v2)

Cosine similarity

Cosine similarity
sourceraw docstring

sinclj

(sin vector)

Applies sin to vector elements.

Applies sin to vector elements.
sourceraw docstring

sincclj

(sinc vector)

Applies sinc to vector elements.

Applies sinc to vector elements.
sourceraw docstring

sinhclj

(sinh vector)

Applies sinh to vector elements.

Applies sinh to vector elements.
sourceraw docstring

sizeclj

(size v)

Returns elements count of the vector.

Returns elements count of the vector.
sourceraw docstring

softmaxclj

(softmax v)
(softmax v t)

Calculates the softmax function for the given vector v.

The softmax function transforms a vector of arbitrary real values into a probability distribution, where each element is a value between 0 and 1, and all elements sum to 1.

It has two arities:

  • [v]: Computes the standard softmax: softmax(v)_i = exp(v_i) / sum_j(exp(v_j)).
  • [v t]: Computes the temperature-scaled softmax: softmax(v)_i = exp(v_i / t) / sum_j(exp(v_j / t)). The t parameter (temperature, defaults to 1) controls the shape of the output distribution; higher temperatures produce softer, more uniform distributions, while lower temperatures produce sharper distributions closer to a one-hot encoding.

The implementation uses a numerically stable approach (by shifting values based on the vector's maximum) to prevent overflow when exponentiating large numbers.

Returns a new vector of the same type and dimension as the input.

Calculates the softmax function for the given vector `v`.

The softmax function transforms a vector of arbitrary real values into a probability distribution, where each element is a value between 0 and 1, and all elements sum to 1.

It has two arities:
- `[v]`: Computes the standard softmax: `softmax(v)_i = exp(v_i) / sum_j(exp(v_j))`.
- `[v t]`: Computes the temperature-scaled softmax: `softmax(v)_i = exp(v_i / t) / sum_j(exp(v_j / t))`. The `t` parameter (temperature, defaults to 1) controls the shape of the output distribution; higher temperatures produce softer, more uniform distributions, while lower temperatures produce sharper distributions closer to a one-hot encoding.

The implementation uses a numerically stable approach (by shifting values based on the vector's maximum) to prevent overflow when exponentiating large numbers.

Returns a new vector of the same type and dimension as the input.
sourceraw docstring

sqclj

(sq vector)

Applies sq to vector elements.

Applies sq to vector elements.
sourceraw docstring

sqrtclj

(sqrt vector)

Applies sqrt to vector elements.

Applies sqrt to vector elements.
sourceraw docstring

subclj

(sub v)
(sub v1 v2)

Subtraction of two vectors.

Subtraction of two vectors.
sourceraw docstring

sumclj

(sum)
(sum v)

Sum of elements

Sum of elements
sourceraw docstring

tanclj

(tan vector)

Applies tan to vector elements.

Applies tan to vector elements.
sourceraw docstring

tanhclj

(tanh vector)

Applies tanh to vector elements.

Applies 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)

Transforms vector.

Maps point to a coordinate system defined by origin, vx, vy and vz (as bases).

Only for Vec2 and Vec3 types.

Transforms vector.

Maps point to a coordinate system defined by origin, vx, vy and vz (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)

Applies trunc to vector elements.

Applies trunc to vector elements.
sourceraw docstring

vec->arrayclj

(vec->array v)

Converts to double array

Converts to double array
sourceraw docstring

vec->RealVectorclj

(vec->RealVector v)

Converts to Apache Commons Math RealVector

Converts to Apache Commons Math RealVector
sourceraw docstring

vec->seqclj

(vec->seq v)

Converts to sequence (same as seq)

Converts to sequence (same as seq)
sourceraw docstring

vec->Vecclj

(vec->Vec v)

Converts to Clojure primitive vector Vec.

Converts to Clojure primitive vector `Vec`.
sourceraw docstring

vec2clj

(vec2)
(vec2 [x y])
(vec2 x y)

Creates 2d vector.

Creates 2d vector.
sourceraw docstring

vec3clj

(vec3)
(vec3 [x y z])
(vec3 v z)
(vec3 x y z)

Creates Vec2 vector

Creates Vec2 vector
sourceraw docstring

vec4clj

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

Creates Vec4 vector

Creates Vec4 vector
sourceraw docstring

xlogxclj

(xlogx vector)

Applies xlogx to vector elements.

Applies xlogx to vector elements.
sourceraw docstring

zero-countclj

(zero-count v)

Counts zeros in vector

Counts zeros in vector
sourceraw docstring

zero?clj

(zero? v)

Is vector zero?

Is vector zero?
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close