-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NDTensors] Fix bugs in
SortedSets
, SmallVectors
, and `BlockSpars…
…eArrays` (#1211)
- Loading branch information
Showing
14 changed files
with
436 additions
and
297 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Custom version of `sort` (`SmallVectors.sort`) that directly uses an `order::Ordering`. | ||
function sort(v, order::Base.Sort.Ordering; alg::Base.Sort.Algorithm=Base.Sort.defalg(v)) | ||
mv = thaw(v) | ||
SmallVectors.sort!(mv, order; alg) | ||
return freeze(mv) | ||
end | ||
|
||
# Custom version of `sort!` (`SmallVectors.sort!`) that directly uses an `order::Ordering`. | ||
function sort!( | ||
v::AbstractVector{T}, | ||
order::Base.Sort.Ordering; | ||
alg::Base.Sort.Algorithm=Base.Sort.defalg(v), | ||
scratch::Union{Vector{T},Nothing}=nothing, | ||
) where {T} | ||
if VERSION < v"1.8.4" | ||
Base.sort!(v, alg, order) | ||
else | ||
Base.Sort._sort!( | ||
v, Base.Sort.maybe_apply_initial_optimizations(alg), order, (; scratch) | ||
) | ||
end | ||
return v | ||
end |
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
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
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
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
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,2 +1,35 @@ | ||
SmallVectors.insert(inds::AbstractIndices, i) = insert!(copy(inds), i) | ||
SmallVectors.delete(inds::AbstractIndices, i) = delete!(copy(inds), i) | ||
SmallVectors.insert(inds::AbstractIndices, i) = insert(InsertStyle(inds), inds, i) | ||
|
||
function SmallVectors.insert(::InsertStyle, inds::AbstractIndices, i) | ||
return error("Not implemented") | ||
end | ||
|
||
function SmallVectors.insert(::IsInsertable, inds::AbstractIndices, i) | ||
inds = copy(inds) | ||
insert!(inds, i) | ||
return inds | ||
end | ||
|
||
function SmallVectors.insert(::FastCopy, inds::AbstractIndices, i) | ||
minds = thaw(inds) | ||
insert!(minds, i) | ||
return freeze(minds) | ||
end | ||
|
||
SmallVectors.delete(inds::AbstractIndices, i) = delete(InsertStyle(inds), inds, i) | ||
|
||
function SmallVectors.delete(::InsertStyle, inds::AbstractIndices, i) | ||
return error("Not implemented") | ||
end | ||
|
||
function SmallVectors.delete(::IsInsertable, inds::AbstractIndices, i) | ||
inds = copy(inds) | ||
delete!(inds, i) | ||
return inds | ||
end | ||
|
||
function SmallVectors.delete(::FastCopy, inds::AbstractIndices, i) | ||
minds = thaw(inds) | ||
delete!(minds, i) | ||
return freeze(minds) | ||
end |
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.