+class NDArrayInput a where\r
+ ndarrayInput :: a -> ([Integer], [Double])\r
+ \r
+instance NDArrayInput [Double] where\r
+ ndarrayInput v = ([length v], v)\r
+ \r
+instance (NDArrayInput [a]) => NDArrayInput [[a]] where\r
+ ndarrayInput v = let\r
+ inp = map ndarrayInput v\r
+ dims = map fst inp\r
+ vals = join $ map snd inp\r
+ in\r
+ if not (all (== (dims!0)) dims) then\r
+ fail "List of lists not of uniform dimension"\r
+ else\r
+ ([length v] + (dims!0), vals)\r
+\r
+ndarrayFromList :: NDArrayInput a => a -> NDArray\r
+ndarrayFromList v = ndarrayN (vector dims) (vector vals) where\r
+ (dims, vals) = ndarrayInput v\r
+\r