Created
September 11, 2017 10:54
-
-
Save leftaroundabout/24427d8f59527c5b31823abd9778b63f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | | |
-- Module : Data.Vector.Unboxed.Nested | |
-- Copyright : (c) Justus Sagemüller 2017 | |
-- License : BSD-style | |
-- | |
-- Maintainer : (@) jsagemue $ uni-koeln.de | |
-- Stability : experimental | |
-- Portability : portable | |
-- | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Data.Vector.Unboxed.Nested where | |
import Data.Vector.Generic as G | |
import Data.Vector.Generic.Mutable as GM | |
import Data.Vector.Unboxed as U | |
import Data.Vector as B | |
import Control.Monad | |
data instance U.Vector (U.Vector a) = NestedVector { | |
nestedSubvectors :: U.Vector Int | |
, flattenedVector :: U.Vector a | |
} | |
newtype instance U.MVector s (U.Vector a) = NestedMVector { | |
getNestedMVector :: B.MVector s (U.Vector a) | |
} | |
instance U.Unbox a => G.Vector U.Vector (U.Vector a) where | |
basicLength = pred . G.basicLength . nestedSubvectors | |
basicUnsafeIndexM (NestedVector ixs flt) i = do | |
i₀ <- basicUnsafeIndexM ixs i | |
ie <- basicUnsafeIndexM ixs (i+1) | |
return $ G.basicUnsafeSlice i₀ (ie-i₀) flt | |
basicUnsafeSlice (NestedVector ixs flt) i = do | |
instance U.Unbox a => GM.MVector U.MVector (U.Vector a) where | |
-- instance U.Unbox a => U.Unbox (U.Vector a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rough sketch of how a speculative implementation of nested unboxed vectors might work.