Refactor Mult and add MultNeutral
This commit is contained in:
parent
015b7f8cb1
commit
a0d9c766c0
|
@ -11,10 +11,6 @@ import Data.NumIdr.Array.Coords
|
||||||
|
|
||||||
%default total
|
%default total
|
||||||
|
|
||||||
infix 2 !!
|
|
||||||
infix 2 !?
|
|
||||||
infixl 3 !!..
|
|
||||||
infix 3 !?..
|
|
||||||
|
|
||||||
||| Arrays are the central data structure of NumIdr. They are an `n`-dimensional
|
||| Arrays are the central data structure of NumIdr. They are an `n`-dimensional
|
||||||
||| grid of values, where `n` is a value known as the *rank* of the array. Arrays
|
||| grid of values, where `n` is a value known as the *rank* of the array. Arrays
|
||||||
|
@ -223,6 +219,10 @@ array v = MkArray COrder (calcStrides COrder s) s (fromList $ collapse v)
|
||||||
-- Indexing
|
-- Indexing
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
infix 10 !!
|
||||||
|
infix 10 !?
|
||||||
|
infixl 11 !!..
|
||||||
|
infix 11 !?..
|
||||||
|
|
||||||
||| Index the array using the given `Coords` object.
|
||| Index the array using the given `Coords` object.
|
||||||
export
|
export
|
||||||
|
@ -462,13 +462,11 @@ export
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
Num a => Mult a (Array {rk} s a) where
|
Num a => Mult a (Array {rk} s a) (Array s a) where
|
||||||
Result = Array {rk} s a
|
|
||||||
(*.) x = map (*x)
|
(*.) x = map (*x)
|
||||||
|
|
||||||
export
|
export
|
||||||
Num a => Mult (Array {rk} s a) a where
|
Num a => Mult (Array {rk} s a) a (Array s a) where
|
||||||
Result = Array {rk} s a
|
|
||||||
(*.) = flip (*.)
|
(*.) = flip (*.)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,12 @@ fromDiag ds o = fromFunction [m,n] (\[i,j] => maybe o (`index` ds) $ i `eq` j)
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
identity : Num a => {n : _} -> Matrix n n a
|
identity : Num a => {n : _} -> Matrix' n a
|
||||||
identity = repeatDiag 1 0
|
identity = repeatDiag 1 0
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
scaling : Num a => {n : _} -> a -> Matrix n n a
|
scaling : Num a => {n : _} -> a -> Matrix' n a
|
||||||
scaling x = repeatDiag x 0
|
scaling x = repeatDiag x 0
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
|
@ -4,10 +4,34 @@ module Data.NumIdr.Multiply
|
||||||
|
|
||||||
|
|
||||||
infixr 9 *.
|
infixr 9 *.
|
||||||
|
infixr 10 ^
|
||||||
|
|
||||||
||| A generalized multiplication/transformation operator. This interface is
|
||| A generalized multiplication/transformation operator. This interface is
|
||||||
||| necessary since the standard multiplication operator is homogenous.
|
||| necessary since the standard multiplication operator is homogenous.
|
||||||
public export
|
public export
|
||||||
interface Mult a b where
|
interface Mult a b c | a,b where
|
||||||
0 Result : Type
|
(*.) : a -> b -> c
|
||||||
(*.) : a -> b -> Result
|
|
||||||
|
public export
|
||||||
|
interface (Mult a a a) => MultNeutral a where
|
||||||
|
neutral : a
|
||||||
|
|
||||||
|
|
||||||
|
public export
|
||||||
|
[MultSemigroup] Mult a a a => Semigroup a where
|
||||||
|
(<+>) = (*.)
|
||||||
|
|
||||||
|
public export
|
||||||
|
[MultMonoid] MultNeutral a => Monoid a using MultSemigroup where
|
||||||
|
neutral = Multiply.neutral
|
||||||
|
|
||||||
|
|
||||||
|
public export
|
||||||
|
power : MultNeutral a => Nat -> a -> a
|
||||||
|
power 0 _ = neutral
|
||||||
|
power 1 x = x
|
||||||
|
power (S n@(S _)) x = x *. power n x
|
||||||
|
|
||||||
|
public export
|
||||||
|
(^) : MultNeutral a => a -> Nat -> a
|
||||||
|
(^) = flip power
|
||||||
|
|
|
@ -56,6 +56,8 @@ unit3D pol az = vector [cos az * sin pol, sin az * sin pol, cos pol]
|
||||||
-- Indexing
|
-- Indexing
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
infix 10 !!
|
||||||
|
infix 10 !?
|
||||||
|
|
||||||
export
|
export
|
||||||
index : Fin n -> Vector n a -> a
|
index : Fin n -> Vector n a -> a
|
||||||
|
|
Loading…
Reference in a new issue