Discussion: High-level functions that can convert between vector types
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by reading the Data.Vector.Generic map, convert, and generate APIs, then follow the linked underlying-problem comment. Compare the proposed convertingMap type with the existing solution and stream-fusion concerns; done would require a settled API design and an explicitly accepted implementation path.
Written by the indexing model from the issue text.
Description
Edit: Issue description of the underlying problem https://github.com/haskell/vector/issues/373#issuecomment-808821411
Below is the original question that led to it:
I often work with indices that I'd like to store in Unboxed.Vector Int vectors, and Generic.Vector vector a vectors into which those indices point.
At some point I have to resolve the indices back into the original generic vector type. I would like to do:
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Unboxed as VU
myIndexVector :: VU.Vector Int
atIndices :: (VG.Vector vector a) => vector a -> VU.Vector Int -> vector a
atIndices vals indices = VG.map (vals VG.!) indices
(This is basically the same as myVector[indicesVector] does in Python's numpy.)
However in the above, VG.map (xs VG.!) indices does not typecheck, beause map requires that the input vector type be the same as the output vector type.
Thus it would be awesome to have a convertingMap function that combines map with convert, of type:
convertingMap :: (Vector v a, Vector w b) => (a -> b) -> v a -> w b
Edit: Solution for this specific function due to @lehins in https://github.com/haskell/vector/issues/373#issuecomment-808820750.
Alternatives considered:
convertingMap vals f = VG.map f (VG.convert vals)orVG.convert (VG.map f vals)isn't great, because it requires thatvandwcan store the same elements, which sometimes isn't the case, e.g. I can have a dataD1that only works withUnboxedand dataD2that only works withStorable.- I currently use:
but I don't know if that's optimal stream-fusion-wise.convertingVectorMap :: (VG.Vector vectorA a, VG.Vector vectorB b) => (a -> b) -> vectorA a -> vectorB b convertingVectorMap f va = VG.generate (VG.length va) $ \i -> f (va VG.! i)
- Dominant language
- Haskell
- Stars
- 401
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from haskell/vector
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement tricorder
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
zip-archive-0.5 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
commercialhaskell/stackage#8124 · 1 comment ·
-
chore
Difficulty 1/5 Under an hour Newbie friendliness 91/100
alunduil/alunduil-chezmoi#792 ·