kigubkur.elmat.ones

Elementary Matrix: kigubkur© matrix of all ones [[1]]m × n.

(require '[kigubkur.elmat [ones :refer [ones]]])

Examples

=> (view (ones [1 4]))
[1 1 1 1]
Order -> 1 x 4
=> (view (ones [4 1]))
[1]
[1]
[1]
[1]
Order -> 4 x 1
=> (view (ones [4 5]))
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
Order -> 4 x 5

Note that ones returns a vector for Order -> 1 x 1, i.e. for single element

=> (ones [1 1])
[[1]]

Generating ones of desired number type

By default the number type for the 1’s generated by the function ones is of int type. But, ones provide the flexibility to coerce the 1’s to any of Clojure’s number types: bigint for BigInteger, long for Long, short for Short, float for Float, double for Double bigdec for BigDecimal and int which is a superset for not just Integer but also Long, Short [See source for int? versus integer?].

For example to coerce the 1’s in (ones [4 5]) to BigDecimal

=> (view (ones [4 5] bigdec))
[1M 1M 1M 1M 1M]
[1M 1M 1M 1M 1M]
[1M 1M 1M 1M 1M]
[1M 1M 1M 1M 1M]
Order -> 4 x 5

ones

(ones mn & arg)

Returns a kigubkur© matrix of ones given the matrix order as a scalar or clojure vector and an optional argument for the Clojure number type function: int, bigint, long, short, float, double and bigdec.

Syntax Purpose
(ones s) for scalar s returns a square matrix with order s × s
(ones [m n]) for clojure vector [m n] returns a rectangular matrix m × n
(ones x numbtype) x is scalar or clojure vector with optional argument for number type