Commits

Bryan O'Sullivan committed 4d27bd2

Happier instances of Binary for vector

Comments (0)

Files changed (4)

Statistics/Resampling.hs

 import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
 import Data.Vector.Algorithms.Intro (sort)
+import Data.Vector.Binary ()
 import Data.Vector.Generic (unsafeFreeze)
 import Data.Word (Word32)
 import GHC.Conc (numCapabilities)
       fromResample :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Resample where
-    put (Resample v) = put (U.toList v)
-    get = (Resample . U.fromList) `fmap` get
+instance Binary Resample
 
 -- | /O(e*r*s)/ Resample a data set repeatedly, with replacement,
 -- computing each estimate over the resampled data.

Statistics/Sample/KernelDensity/Simple.hs

 
 import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
+import Data.Vector.Binary ()
 import GHC.Generics (Generic)
 import Numeric.MathFunctions.Constants (m_1_sqrt_2, m_2_sqrt_pi)
 import Statistics.Function (minMax)
       fromPoints :: U.Vector Double
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Points where
-    put (Points v) = put (G.toList v)
-    get = (Points . G.fromList) `fmap` get
+instance Binary Points
 
 -- | Bandwidth estimator for an Epanechnikov kernel.
 epanechnikovBW :: Double -> Bandwidth

Statistics/Sample/Powers.hs

 
 import Data.Binary (Binary(..))
 import Data.Data (Data, Typeable)
+import Data.Vector.Binary ()
 import Data.Vector.Generic   (unsafeFreeze)
 import Data.Vector.Unboxed   ((!))
 import GHC.Generics (Generic)
 newtype Powers = Powers (U.Vector Double)
     deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Powers where
-    put (Powers v) = put (G.toList v)
-    get = (Powers . G.fromList) `fmap` get
+instance Binary Powers
 
 -- | O(/n/) Collect the /n/ simple powers of a sample.
 --
     math-functions    >= 0.1.2,
     primitive         >= 0.3,
     vector            >= 0.7.1,
-    vector-algorithms >= 0.4
+    vector-algorithms >= 0.4,
+    vector-binary-instances >= 0.2.1
   if impl(ghc >= 6.10)
     build-depends:
       base >= 4