Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Add functor instance (operating elementwise) to Matrix #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/LinearAlgebra/Matrix.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module LinearAlgebra.Matrix
( Matrix
( Matrix
-- * Constructors
, fromArray
, fromColumn
Expand Down Expand Up @@ -44,6 +44,9 @@ instance showMatrix :: Show a => Show (Matrix a) where
<> ", ncols=" <> show c
<> ", data=" <> show ds

instance functorMatrix :: Functor (Matrix a) where
map f (Dense n m vs) = Dense n m (map f vs)


-- | Number of rows in matrix
nrows :: ∀ a. Matrix a -> Int
Expand Down Expand Up @@ -191,4 +194,4 @@ add :: Matrix Number -> Matrix Number -> Matrix Number
add (Dense r1 c1 vs1) (Dense r2 c2 vs2)
| r1 /= r2 || c1 /= c2 = zeros 1 1
| otherwise = Dense r1 c1 $ V.add vs1 vs2