kigubkur.mod.absolute
Modify: to absolute value of a number or all the elements (numbers) of a kigubkur© matrix.
abso
(require '[kigubkur.mod [absolute :refer [abso]]])
Examples
Absolute of a number
=> (abso -0)
0
Absolute of a vector
=> (def r [[1 -2 -3 4]])
=> (def c [[-1][-2][3][4]])
=> (view r)
[1 -2 -3 4]
Order -> 1 x 4
=> (abso r)
[[1 2 3 4]]
=> (view c)
[-1]
[-2]
[3]
[4]
Order -> 4 x 1
=> (abso c)
[[1] [2] [3] [4]]
Absolute of a matrix
=> (def M [[1 2 3 4 5] [-1 -2 -3 -4 -5] [1 -2 3 -4 5] [-1 2 -3 4 -5]])
=> (view M)
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 -2 3 -4 5]
[-1 2 -3 4 -5]
Order -> 4 x 5
=> (view (abso M))
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
Order -> 4 x 5
Absolute of a block
(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1 2 3 4 5 6 7 8 9 10]
[-1 -2 -3 -4 -5 -6 -7 -8 -9 -10]
[-1 2 -3 4 -5 6 -7 8 -9 10]
[1 -2 3 -4 5 -6 7 -8 9 -10]
[1 2 -3 4 5 -6 7 8 -9 10]
[1 2 3 -4 5 6 7 -8 9 10]
[1 2 3 4 -5 6 7 8 9 -10]])
=> (def B (block L 5))
=> (pprint B)
[[{:A11 [[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[-1 2 -3 4 -5]
[1 -2 3 -4 5]
[1 2 -3 4 5]],
:A12 [[6 7 8 9 10]
[-6 -7 -8 -9 -10]
[6 -7 8 -9 10]
[-6 7 -8 9 -10]
[-6 7 8 -9 10]]}]
[{:A21 [[1 2 3 -4 5]
[1 2 3 4 -5]],
:A22 [[6 7 -8 9 10]
[6 7 8 9 -10]]}]]
=> (pprint (abso B))
[[{:A11 [[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]],
:A12 [[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]]}]
[{:A21 [[1 2 3 4 5]
[1 2 3 4 5]],
:A22 [[6 7 8 9 10]
[6 7 8 9 10]]}]]
abso
(abso x)
Returns the absolute of a number or every element of a matrix or a block (i.e. element-wise absolute). Given x as a scalar or an element of a matrix (or block), that absolute of x is defined as
(abso x) where x is | ∣x∣ ≝ |
---|---|
<0 | −x |
≥0 | x |
Special case: if x ∈ {##NaN
, ##Inf
, ##-Inf
}, returns ##NaN
.