Skip to content

Instantly share code, notes, and snippets.

@leftaroundabout
Created September 11, 2017 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leftaroundabout/24427d8f59527c5b31823abd9778b63f to your computer and use it in GitHub Desktop.
Save leftaroundabout/24427d8f59527c5b31823abd9778b63f to your computer and use it in GitHub Desktop.
-- |
-- 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)
@leftaroundabout
Copy link
Author

Rough sketch of how a speculative implementation of nested unboxed vectors might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment