-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify _buffer_index behavior #22
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
name = "CircularArrayBuffers" | ||
uuid = "9de3a189-e0c0-4e15-ba3b-b14b9fb0aec1" | ||
authors = ["Jun Tian <tianjun.cpp@gmail.com> and contributors"] | ||
version = "0.1.13" | ||
version = "0.1.14" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
|
||
[compat] | ||
Adapt = "2, 3, 4" | ||
julia = "1" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["CUDA", "Test"] |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -76,24 +76,42 @@ capacity(cb::CircularArrayBuffer{T,N}) where {T,N} = size(cb.buffer, N) | |||||
isfull(cb::CircularArrayBuffer) = cb.nframes == capacity(cb) | ||||||
Base.isempty(cb::CircularArrayBuffer) = cb.nframes == 0 | ||||||
|
||||||
""" | ||||||
_buffer_index(cb::CircularArrayBuffer, i::Int) | ||||||
|
||||||
Return the index of the `i`-th element in the buffer. | ||||||
""" | ||||||
@inline function _buffer_index(cb::CircularArrayBuffer, i::Int) | ||||||
ind = (cb.first - 1) * cb.step_size + i | ||||||
if ind > length(cb.buffer) | ||||||
ind - length(cb.buffer) | ||||||
idx = (cb.first - 1) * cb.step_size + i | ||||||
return wrap_index(idx, length(cb.buffer)) | ||||||
end | ||||||
@inline _buffer_index(cb::CircularArrayBuffer, I::AbstractVector{<:Integer}) = map(Base.Fix1(_buffer_index, cb), I) | ||||||
|
||||||
""" | ||||||
wrap_index(idx, n) | ||||||
|
||||||
Return the index of the `idx`-th element in the buffer, if index is one past the size, return 1, else error. | ||||||
""" | ||||||
function wrap_index(idx, n) | ||||||
if idx <= n | ||||||
return idx | ||||||
elseif idx <= 2n | ||||||
return idx - n | ||||||
else | ||||||
ind | ||||||
@info "oops! idx $(idx) > 2n $(2n)" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return idx - n | ||||||
end | ||||||
end | ||||||
@inline _buffer_index(cb::CircularArrayBuffer, I::AbstractVector{<:Integer}) = map(Base.Fix1(_buffer_index, cb), I) | ||||||
|
||||||
""" | ||||||
_buffer_frame(cb::CircularArrayBuffer, i::Int) | ||||||
|
||||||
Return the index of the `i`-th frame in the buffer. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
@inline function _buffer_frame(cb::CircularArrayBuffer, i::Int) | ||||||
n = capacity(cb) | ||||||
idx = cb.first + i - 1 | ||||||
if idx > n | ||||||
idx - n | ||||||
else | ||||||
idx | ||||||
end | ||||||
return wrap_index(idx, n) | ||||||
end | ||||||
|
||||||
_buffer_frame(cb::CircularArrayBuffer, I::CartesianIndex) = CartesianIndex(map(i->_buffer_frame(cb, i), Tuple(I))) | ||||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.