File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import qualified Data.Map as M
1111import qualified Data.Text as T
1212import qualified Data.Vector as V
1313import qualified Data.Vector.Unboxed as VU
14+ import qualified Data.Vector.Generic as VG
1415
1516import Control.Monad (join )
1617import DataFrame.Display.Terminal.PrettyPrint
@@ -98,3 +99,20 @@ unsafeGetColumn name df = columns df V.! (columnIndices df M.! name)
9899
99100null :: DataFrame -> Bool
100101null df = V. null (columns df)
102+
103+ toMatrix :: DataFrame -> V. Vector (VU. Vector Float )
104+ toMatrix df = let
105+ m = V. map (toVector @ Double ) (columns df)
106+ in V. generate (fst (dataframeDimensions df)) (\ i -> foldl (\ acc j -> acc `VU.snoc` (realToFrac ((m V. ! j) V. ! i))) VU. empty [0 .. (V. length m - 1 )])
107+
108+ columnAsVector :: forall a . Columnable a => T. Text -> DataFrame -> V. Vector a
109+ columnAsVector name df = case unsafeGetColumn name df of
110+ (BoxedColumn (col :: V. Vector b )) -> case testEquality (typeRep @ a ) (typeRep @ b ) of
111+ Nothing -> error " Type error"
112+ Just Refl -> col
113+ (OptionalColumn (col :: V. Vector b )) -> case testEquality (typeRep @ a ) (typeRep @ b ) of
114+ Nothing -> error " Type error"
115+ Just Refl -> col
116+ (UnboxedColumn (col :: VU. Vector b )) -> case testEquality (typeRep @ a ) (typeRep @ b ) of
117+ Nothing -> error " Type error"
118+ Just Refl -> VG. convert col
You can’t perform that action at this time.
0 commit comments