Skip to content

Commit

Permalink
Functions to create constant matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
nicaudinet committed Feb 15, 2024
1 parent 194617b commit f254ecc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/base/src/Numeric/LinearAlgebra/Static.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,25 @@ build f = r
where
r = mkL $ LA.build (size r) f

-- | Create a matrix where every element is the same.
constMatrix
:: forall m n . (KnownNat n, KnownNat m)
=>
-> L m n
constMatrix x = build (\_ _ -> x)

-- | Create a matrix where every element is zero.
zeros
:: forall m n . (KnownNat n, KnownNat m)
=> L m n
zeros = constMatrix 0

-- | Create a matrix where every element is one.
ones
:: forall m n . (KnownNat n, KnownNat m)
=> L m n
ones = constMatrix 1

--------------------------------------------------------------------------------

withVector
Expand Down

0 comments on commit f254ecc

Please sign in to comment.