AA
SomeMatrix
{-# LANGUAGE DataKinds, PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}
import Eigen.Matrix
import GHC.Natural
import GHC.TypeNats
import Data.List
import Data.Proxy
main = do
xs <- readLn @[[Double]]
ys <- readLn @[[Double]]
print $ case someNatVal . genericLength $ xs of
SomeNat pn ->
case someNatVal . genericLength . head $ xs of
SomeNat pm ->
case someNatVal . genericLength $ ys of
SomeNat pm' ->
case someNatVal . genericLength . head $ ys of
SomeNat pn' ->
case mmult pn pm pn' xs ys of
Just m -> toList m
mmult :: forall n m n' . (KnownNat n, KnownNat m, KnownNat n')
=> Proxy n -> Proxy m -> Proxy n' -> [[Double]] -> [[Double]] -> Maybe (MatrixXd n n')
mmult _ _ _ xs ys = do
a :: MatrixXd n m <- fromList xs
b :: MatrixXd m n' <- fromList ys
return $ mul a b
{-
[[1,2,3],[4,5,6]]
[[3,4,5],[3,4,5],[4,5,6]]
[[21.0,27.0,33.0],[51.0,66.0,81.0]]
-}