{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Numeric.LAPACK.Matrix.Banded (
   Banded,
   General,
   Square,
   Upper,
   Lower,
   Diagonal,
   Hermitian,
   height, width,
   fromList,
   squareFromList,
   lowerFromList,
   upperFromList,
   mapExtent,
   diagonal,
   takeDiagonal,
   toFull,
   toLowerTriangular,
   toUpperTriangular,
   transpose,
   adjoint,
   multiplyVector,
   multiply,
   multiplyFull,

   solve,
   determinant,
   ) where

import qualified Numeric.LAPACK.Matrix.Banded.Linear as Linear
import qualified Numeric.LAPACK.Matrix.Banded.Basic as Basic

import qualified Numeric.LAPACK.Matrix.Array.Triangular as Tri
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Shape.Private as MatrixShape
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import Numeric.LAPACK.Matrix.Array.Banded
         (Banded, General, Square, Lower, Upper, Diagonal, Hermitian)
import Numeric.LAPACK.Matrix.Array (Full)
import Numeric.LAPACK.Matrix.Shape.Private (Order, UnaryProxy)
import Numeric.LAPACK.Vector (Vector)

import qualified Numeric.Netlib.Class as Class

import qualified Type.Data.Num.Unary as Unary
import Type.Data.Num.Unary ((:+:))

import qualified Data.Array.Comfort.Shape as Shape

import Foreign.Storable (Storable)


height ::
   (Extent.C vert, Extent.C horiz) =>
   Banded sub super vert horiz height width a -> height
height :: Banded sub super vert horiz height width a -> height
height = Banded sub super vert horiz height width -> height
forall vert horiz sub super height width.
(C vert, C horiz) =>
Banded sub super vert horiz height width -> height
MatrixShape.bandedHeight (Banded sub super vert horiz height width -> height)
-> (Banded sub super vert horiz height width a
    -> Banded sub super vert horiz height width)
-> Banded sub super vert horiz height width a
-> height
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded sub super vert horiz height width a
-> Banded sub super vert horiz height width
forall sh a. ArrayMatrix sh a -> sh
ArrMatrix.shape

width ::
   (Extent.C vert, Extent.C horiz) =>
   Banded sub super vert horiz height width a -> width
width :: Banded sub super vert horiz height width a -> width
width = Banded sub super vert horiz height width -> width
forall vert horiz sub super height width.
(C vert, C horiz) =>
Banded sub super vert horiz height width -> width
MatrixShape.bandedWidth (Banded sub super vert horiz height width -> width)
-> (Banded sub super vert horiz height width a
    -> Banded sub super vert horiz height width)
-> Banded sub super vert horiz height width a
-> width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded sub super vert horiz height width a
-> Banded sub super vert horiz height width
forall sh a. ArrayMatrix sh a -> sh
ArrMatrix.shape



fromList ::
   (Unary.Natural sub, Unary.Natural super,
    Shape.C height, Shape.C width, Storable a) =>
   (UnaryProxy sub, UnaryProxy super) -> Order -> height -> width -> [a] ->
   General sub super height width a
fromList :: (UnaryProxy sub, UnaryProxy super)
-> Order
-> height
-> width
-> [a]
-> General sub super height width a
fromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order height
height_ width
width_ =
   Array (BandedGeneral sub super height width) a
-> General sub super height width a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (BandedGeneral sub super height width) a
 -> General sub super height width a)
-> ([a] -> Array (BandedGeneral sub super height width) a)
-> [a]
-> General sub super height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnaryProxy sub, UnaryProxy super)
-> Order
-> height
-> width
-> [a]
-> Array (BandedGeneral sub super height width) a
forall sub super height width a.
(Natural sub, Natural super, C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> height
-> width
-> [a]
-> General sub super height width a
Basic.fromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order height
height_ width
width_

squareFromList ::
   (Unary.Natural sub, Unary.Natural super, Shape.C size, Storable a) =>
   (UnaryProxy sub, UnaryProxy super) -> Order -> size -> [a] ->
   Square sub super size a
squareFromList :: (UnaryProxy sub, UnaryProxy super)
-> Order -> size -> [a] -> Square sub super size a
squareFromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order size
size =
   Array (BandedSquare sub super size) a -> Square sub super size a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (BandedSquare sub super size) a -> Square sub super size a)
-> ([a] -> Array (BandedSquare sub super size) a)
-> [a]
-> Square sub super size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnaryProxy sub, UnaryProxy super)
-> Order -> size -> [a] -> Array (BandedSquare sub super size) a
forall sub super size a.
(Natural sub, Natural super, C size, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order -> size -> [a] -> Square sub super size a
Basic.squareFromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order size
size

lowerFromList ::
   (Unary.Natural sub, Shape.C size, Storable a) =>
   UnaryProxy sub -> Order -> size -> [a] -> Lower sub size a
lowerFromList :: UnaryProxy sub -> Order -> size -> [a] -> Lower sub size a
lowerFromList UnaryProxy sub
numOff Order
order size
size =
   Array (BandedSquare sub U0 size) a -> Lower sub size a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (BandedSquare sub U0 size) a -> Lower sub size a)
-> ([a] -> Array (BandedSquare sub U0 size) a)
-> [a]
-> Lower sub size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnaryProxy sub
-> Order -> size -> [a] -> Array (BandedSquare sub U0 size) a
forall sub size a.
(Natural sub, C size, Storable a) =>
UnaryProxy sub -> Order -> size -> [a] -> Lower sub size a
Basic.lowerFromList UnaryProxy sub
numOff Order
order size
size

upperFromList ::
   (Unary.Natural super, Shape.C size, Storable a) =>
   UnaryProxy super -> Order -> size -> [a] -> Upper super size a
upperFromList :: UnaryProxy super -> Order -> size -> [a] -> Upper super size a
upperFromList UnaryProxy super
numOff Order
order size
size =
   Array (BandedSquare U0 super size) a -> Upper super size a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (BandedSquare U0 super size) a -> Upper super size a)
-> ([a] -> Array (BandedSquare U0 super size) a)
-> [a]
-> Upper super size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnaryProxy super
-> Order -> size -> [a] -> Array (BandedSquare U0 super size) a
forall super size a.
(Natural super, C size, Storable a) =>
UnaryProxy super -> Order -> size -> [a] -> Upper super size a
Basic.upperFromList UnaryProxy super
numOff Order
order size
size

mapExtent ::
   (Extent.C vertA, Extent.C horizA) =>
   (Extent.C vertB, Extent.C horizB) =>
   Extent.Map vertA horizA vertB horizB height width ->
   Banded super sub vertA horizA height width a ->
   Banded super sub vertB horizB height width a
mapExtent :: Map vertA horizA vertB horizB height width
-> Banded super sub vertA horizA height width a
-> Banded super sub vertB horizB height width a
mapExtent = (Array (Banded super sub vertA horizA height width) a
 -> Array (Banded super sub vertB horizB height width) a)
-> Banded super sub vertA horizA height width a
-> Banded super sub vertB horizB height width a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Banded super sub vertA horizA height width) a
  -> Array (Banded super sub vertB horizB height width) a)
 -> Banded super sub vertA horizA height width a
 -> Banded super sub vertB horizB height width a)
-> (Map vertA horizA vertB horizB height width
    -> Array (Banded super sub vertA horizA height width) a
    -> Array (Banded super sub vertB horizB height width) a)
-> Map vertA horizA vertB horizB height width
-> Banded super sub vertA horizA height width a
-> Banded super sub vertB horizB height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map vertA horizA vertB horizB height width
-> Array (Banded super sub vertA horizA height width) a
-> Array (Banded super sub vertB horizB height width) a
forall vertA horizA vertB horizB height width super sub a.
(C vertA, C horizA, C vertB, C horizB) =>
Map vertA horizA vertB horizB height width
-> Banded super sub vertA horizA height width a
-> Banded super sub vertB horizB height width a
Basic.mapExtent

transpose ::
   (Extent.C vert, Extent.C horiz) =>
   Banded sub super vert horiz height width a ->
   Banded super sub horiz vert width height a
transpose :: Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
transpose = (Array (Banded sub super vert horiz height width) a
 -> Array (Banded super sub horiz vert width height) a)
-> Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Banded sub super vert horiz height width) a
-> Array (Banded super sub horiz vert width height) a
forall vert horiz sub super height width a.
(C vert, C horiz) =>
Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
Basic.transpose

adjoint ::
   (Unary.Natural sub, Unary.Natural super, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Banded sub super vert horiz height width a ->
   Banded super sub horiz vert width height a
adjoint :: Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
adjoint = (Array (Banded sub super vert horiz height width) a
 -> Array (Banded super sub horiz vert width height) a)
-> Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Banded sub super vert horiz height width) a
-> Array (Banded super sub horiz vert width height) a
forall sub super vert horiz height width a.
(Natural sub, Natural super, C vert, C horiz, C height, C width,
 Floating a) =>
Banded sub super vert horiz height width a
-> Banded super sub horiz vert width height a
Basic.adjoint

diagonal ::
   (Shape.C sh, Class.Floating a) => Order -> Vector sh a -> Diagonal sh a
diagonal :: Order -> Vector sh a -> Diagonal sh a
diagonal Order
order = Array (BandedSquare U0 U0 sh) a -> Diagonal sh a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (BandedSquare U0 U0 sh) a -> Diagonal sh a)
-> (Vector sh a -> Array (BandedSquare U0 U0 sh) a)
-> Vector sh a
-> Diagonal sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Order -> Vector sh a -> Array (BandedSquare U0 U0 sh) a
forall sh a.
(C sh, Floating a) =>
Order -> Vector sh a -> Diagonal sh a
Basic.diagonal Order
order

takeDiagonal ::
   (Unary.Natural sub, Unary.Natural super, Shape.C sh, Class.Floating a) =>
   Square sub super sh a -> Vector sh a
takeDiagonal :: Square sub super sh a -> Vector sh a
takeDiagonal = Square sub super sh a -> Vector sh a
forall sub super sh a.
(Natural sub, Natural super, C sh, Floating a) =>
Square sub super sh a -> Vector sh a
Basic.takeDiagonal (Square sub super sh a -> Vector sh a)
-> (Square sub super sh a -> Square sub super sh a)
-> Square sub super sh a
-> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sub super sh a -> Square sub super sh a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector

multiplyVector ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width, Eq width,
    Class.Floating a) =>
   Banded sub super vert horiz height width a ->
   Vector width a -> Vector height a
multiplyVector :: Banded sub super vert horiz height width a
-> Vector width a -> Vector height a
multiplyVector = Banded sub super vert horiz height width a
-> Vector width a -> Vector height a
forall sub super vert horiz height width a.
(Natural sub, Natural super, C vert, C horiz, C height, C width,
 Eq width, Floating a) =>
Banded sub super vert horiz height width a
-> Vector width a -> Vector height a
Basic.multiplyVector (Banded sub super vert horiz height width a
 -> Vector width a -> Vector height a)
-> (Banded sub super vert horiz height width a
    -> Banded sub super vert horiz height width a)
-> Banded sub super vert horiz height width a
-> Vector width a
-> Vector height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded sub super vert horiz height width a
-> Banded sub super vert horiz height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector

multiply ::
   (Unary.Natural subA, Unary.Natural superA,
    Unary.Natural subB, Unary.Natural superB,
    (subA :+: subB) ~ subC,
    (superA :+: superB) ~ superC,
    Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   Banded subA superA vert horiz height fuse a ->
   Banded subB superB vert horiz fuse width a ->
   Banded subC superC vert horiz height width a
multiply :: Banded subA superA vert horiz height fuse a
-> Banded subB superB vert horiz fuse width a
-> Banded subC superC vert horiz height width a
multiply = (Array (Banded subA superA vert horiz height fuse) a
 -> Array (Banded subB superB vert horiz fuse width) a
 -> Array (Banded subC superC vert horiz height width) a)
-> Banded subA superA vert horiz height fuse a
-> Banded subB superB vert horiz fuse width a
-> Banded subC superC vert horiz height width a
forall shA a shB b shC c.
(Array shA a -> Array shB b -> Array shC c)
-> ArrayMatrix shA a -> ArrayMatrix shB b -> ArrayMatrix shC c
ArrMatrix.lift2 Array (Banded subA superA vert horiz height fuse) a
-> Array (Banded subB superB vert horiz fuse width) a
-> Array (Banded subC superC vert horiz height width) a
forall subA superA subB superB subC superC vert horiz height width
       fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 (subA :+: subB) ~ subC, (superA :+: superB) ~ superC, C vert,
 C horiz, C height, C width, C fuse, Eq fuse, Floating a) =>
Banded subA superA vert horiz height fuse a
-> Banded subB superB vert horiz fuse width a
-> Banded subC superC vert horiz height width a
Basic.multiply

multiplyFull ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   Banded sub super vert horiz height fuse a ->
   Full vert horiz fuse width a -> Full vert horiz height width a
multiplyFull :: Banded sub super vert horiz height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
multiplyFull = (Array (Banded sub super vert horiz height fuse) a
 -> Array (Full vert horiz fuse width) a
 -> Array (Full vert horiz height width) a)
-> Banded sub super vert horiz height fuse a
-> Full vert horiz fuse width a
-> Full vert horiz height width a
forall shA a shB b shC c.
(Array shA a -> Array shB b -> Array shC c)
-> ArrayMatrix shA a -> ArrayMatrix shB b -> ArrayMatrix shC c
ArrMatrix.lift2 Array (Banded sub super vert horiz height fuse) a
-> Array (Full vert horiz fuse width) a
-> Array (Full vert horiz height width) a
forall sub super vert horiz height width fuse a.
(Natural sub, Natural super, C vert, C horiz, C height, C width,
 C fuse, Eq fuse, Floating a) =>
Banded sub super vert horiz height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
Basic.multiplyFull

toLowerTriangular ::
   (Unary.Natural sub, Shape.C sh, Class.Floating a) =>
   Lower sub sh a -> Tri.Lower sh a
toLowerTriangular :: Lower sub sh a -> Lower sh a
toLowerTriangular = (Array (BandedSquare sub U0 sh) a
 -> Array (LowerTriangular NonUnit sh) a)
-> Lower sub sh a -> Lower sh a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (BandedSquare sub U0 sh) a
-> Array (LowerTriangular NonUnit sh) a
forall sub sh a.
(Natural sub, C sh, Floating a) =>
Lower sub sh a -> Lower sh a
Basic.toLowerTriangular

toUpperTriangular ::
   (Unary.Natural super, Shape.C sh, Class.Floating a) =>
   Upper super sh a -> Tri.Upper sh a
toUpperTriangular :: Upper super sh a -> Upper sh a
toUpperTriangular = (Array (BandedSquare U0 super sh) a
 -> Array (UpperTriangular NonUnit sh) a)
-> Upper super sh a -> Upper sh a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (BandedSquare U0 super sh) a
-> Array (UpperTriangular NonUnit sh) a
forall super sh a.
(Natural super, C sh, Floating a) =>
Upper super sh a -> Upper sh a
Basic.toUpperTriangular

toFull ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Banded sub super vert horiz height width a ->
   Full vert horiz height width a
toFull :: Banded sub super vert horiz height width a
-> Full vert horiz height width a
toFull = (Array (Banded sub super vert horiz height width) a
 -> Array (Full vert horiz height width) a)
-> Banded sub super vert horiz height width a
-> Full vert horiz height width a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Banded sub super vert horiz height width) a
-> Array (Full vert horiz height width) a
forall sub super vert horiz height width a.
(Natural sub, Natural super, C vert, C horiz, C height, C width,
 Floating a) =>
Banded sub super vert horiz height width a
-> Full vert horiz height width a
Basic.toFull



solve ::
   (Unary.Natural sub, Unary.Natural super, Extent.C vert, Extent.C horiz,
    Shape.C sh, Eq sh, Shape.C nrhs, Class.Floating a) =>
   Square sub super sh a ->
   Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solve :: Square sub super sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solve = (Array (BandedSquare sub super sh) a
 -> Array (Full vert horiz sh nrhs) a
 -> Array (Full vert horiz sh nrhs) a)
-> Square sub super sh a
-> Full vert horiz sh nrhs a
-> Full vert horiz sh nrhs a
forall shA a shB b shC c.
(Array shA a -> Array shB b -> Array shC c)
-> ArrayMatrix shA a -> ArrayMatrix shB b -> ArrayMatrix shC c
ArrMatrix.lift2 Array (BandedSquare sub super sh) a
-> Array (Full vert horiz sh nrhs) a
-> Array (Full vert horiz sh nrhs) a
forall sub super vert horiz sh nrhs a.
(Natural sub, Natural super, C vert, C horiz, C sh, Eq sh, C nrhs,
 Floating a) =>
Square sub super sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
Linear.solve

determinant ::
   (Unary.Natural sub, Unary.Natural super, Shape.C sh, Class.Floating a) =>
   Square sub super sh a -> a
determinant :: Square sub super sh a -> a
determinant = Square sub super sh a -> a
forall sub super sh a.
(Natural sub, Natural super, C sh, Floating a) =>
Square sub super sh a -> a
Linear.determinant (Square sub super sh a -> a)
-> (Square sub super sh a -> Square sub super sh a)
-> Square sub super sh a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sub super sh a -> Square sub super sh a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector