Skip to content

Commit

Permalink
Merge pull request #373 from nicaudinet/zeros-and-ones
Browse files Browse the repository at this point in the history
Functions to create constant matrices
  • Loading branch information
idontgetoutmuch authored Feb 21, 2024
2 parents 194617b + f254ecc commit 419715a
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 419715a

Please sign in to comment.