Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Function to replace slice of vector #73

Open
adamwalker opened this issue Sep 5, 2016 · 5 comments
Open

Function to replace slice of vector #73

adamwalker opened this issue Sep 5, 2016 · 5 comments

Comments

@adamwalker
Copy link

Would it be possible to add a function, replaceVec, similar to "replace" from CLaSH.Sized.Vector which replaces a slice instead of a single element?
Perhaps something like:

replaceVec :: (KnownNat m) => SNat o -> Vec m a -> Vec (o + p + m) a -> Vec (o + p + m) a
replaceVec offset replacement vec = vecTruncated ++ replacement ++ vecTail
    where
    vecTruncated =  take offset vec
    vecTail      =  drop (offset `addSNat` lengthS replacement) vec
@christiaanb
Copy link
Member

christiaanb commented Sep 5, 2016

@adamwalker Do you want a "static" version, like the example you posted (which is sorta similar to setSlice), or do you want a "dynamic" version, similar to the replace function you mentioned? Or do you want both?

@adamwalker
Copy link
Author

Good point. I actually want both, if thats doable.

@christiaanb
Copy link
Member

So what should be the out-of-bounds behaviour for the dynamic version?

  • Should it be similar to replace, and give a run-time error when the offset + length replacement > length vec?
  • Should it truncate the LSBs of replacement?

@adamwalker
Copy link
Author

Well, I think it should behave however you decide is most sensible :)
But, in my opinion it should behave similar to replace and give a runtime error.
What does replace do in actual hardware when the index is out of bounds?

@christiaanb
Copy link
Member

The worst thing possible: the index will wrap around.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants