Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
AtCoder.Extra.Semigroup.Matrix
Description
A simple HxW matrix backed by a vector, mainly for binary exponention.
The matrix is a left semigroup action: m2(m1v)=(m2∘m1)v.
Since: 1.1.0.0
Synopsis
- data Matrix a = Matrix {}
- new :: (HasCallStack, Unbox a) => Int -> Int -> Vector a -> Matrix a
- square :: (HasCallStack, Unbox a) => Int -> Vector a -> Matrix a
- zero :: (Unbox a, Num a) => Int -> Matrix a
- ident :: (Unbox a, Num a) => Int -> Matrix a
- diag :: (Unbox a, Num a) => Vector a -> Matrix a
- map :: (Unbox a, Unbox b) => (a -> b) -> Matrix a -> Matrix b
- mulToCol :: (Num a, Unbox a) => Matrix a -> Col a -> Col a
- mul :: forall e. (Num e, Unbox e) => Matrix e -> Matrix e -> Matrix e
- mulMod :: Int -> Matrix Int -> Matrix Int -> Matrix Int
- mulMint :: forall a. KnownNat a => Matrix (ModInt a) -> Matrix (ModInt a) -> Matrix (ModInt a)
- pow :: Int -> Matrix Int -> Matrix Int
- powMod :: Int -> Int -> Matrix Int -> Matrix Int
- powMint :: forall m. KnownNat m => Int -> Matrix (ModInt m) -> Matrix (ModInt m)
- rank :: (Fractional a, Eq a, Unbox a) => Matrix a -> Int
- inv :: forall a. (Fractional a, Eq a, Unbox a) => Matrix a -> Maybe (a, Matrix a)
- invRaw :: forall a. (Fractional a, Eq a, Unbox a) => Matrix a -> Maybe (a, Vector (Vector a))
- detMod :: Int -> Matrix Int -> Int
- detMint :: forall a. KnownNat a => Matrix (ModInt a) -> ModInt a
Matrix
A simple HxW matrix backed by a vector, mainly for binary exponention.
The matrix is a left semigroup action: m2(m1v)=(m2∘m1)v.
Since: 1.1.0.0
Constructors
Matrix | |
Constructors
new :: (HasCallStack, Unbox a) => Int -> Int -> Vector a -> Matrix a Source #
O(hw) Creates an HxW matrix.
Since: 1.1.0.0
square :: (HasCallStack, Unbox a) => Int -> Vector a -> Matrix a Source #
O(n2) Creates an NxN square matrix.
Since: 1.1.1.0
ident :: (Unbox a, Num a) => Int -> Matrix a Source #
O(n2) Creates an NxN identity matrix.
Since: 1.1.0.0
diag :: (Unbox a, Num a) => Vector a -> Matrix a Source #
O(n2) Creates an NxN diagonal matrix.
Since: 1.1.0.0
Mapping
map :: (Unbox a, Unbox b) => (a -> b) -> Matrix a -> Matrix b Source #
O(n2) Maps the Matrix
.
Since: 1.1.0.0
Multiplications
mulToCol :: (Num a, Unbox a) => Matrix a -> Col a -> Col a Source #
O(hw) Multiplies HxW matrix to a Hx1 column vector.
Since: 1.1.0.0
mul :: forall e. (Num e, Unbox e) => Matrix e -> Matrix e -> Matrix e Source #
O(h1Kw2) Multiplies H1xK matrix to a KxW2 matrix.
Since: 1.1.0.0
mulMod :: Int -> Matrix Int -> Matrix Int -> Matrix Int Source #
O(h1w2K) Multiplies H1xK matrix to a KxW2 matrix, taking the mod.
Since: 1.1.0.0
mulMint :: forall a. KnownNat a => Matrix (ModInt a) -> Matrix (ModInt a) -> Matrix (ModInt a) Source #
Powers
powMod :: Int -> Int -> Matrix Int -> Matrix Int Source #
O(wn3) Returns Mk, taking the mod.
Since: 1.1.0.0
powMint :: forall m. KnownNat m => Int -> Matrix (ModInt m) -> Matrix (ModInt m) Source #
O(wn3) Returns Mk, specialized to ModInt
.
Since: 1.1.0.0
Rank
rank :: (Fractional a, Eq a, Unbox a) => Matrix a -> Int Source #
O(hwmin(h,w)) Returns the rank of the matrix.
Since: 1.1.1.0
Inverse
inv :: forall a. (Fractional a, Eq a, Unbox a) => Matrix a -> Maybe (a, Matrix a) Source #
O(n3) Returns (det, invMatrix)
or Nothing
if the matrix does not have inverse (the
determinant is zero).
Constraints
- The input must be a square matrix.
Since: 1.1.1.0
invRaw :: forall a. (Fractional a, Eq a, Unbox a) => Matrix a -> Maybe (a, Vector (Vector a)) Source #
O(n3) Returns (det, invMatrix)
or Nothing
if the matrix does not have inverse (the
determinant is zero).
Constraints
- The input must be a square matrix.
Since: 1.1.1.0