-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bad interaction with StaticArrays broadcasting
- Loading branch information
Showing
3 changed files
with
59 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
name = "StandardPacked" | ||
uuid = "65f29c17-9e56-4606-972f-81e04007695c" | ||
authors = ["Benjamin Desef <[email protected]>"] | ||
version = "1.0.2" | ||
version = "1.0.3" | ||
|
||
[deps] | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
|
||
[weakdeps] | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
|
||
[extras] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Documenter", "Test"] | ||
test = ["Documenter", "Test", "StaticArrays"] | ||
|
||
[extensions] | ||
StandardPackedStaticArrays = "StaticArrays" | ||
|
||
[compat] | ||
julia = "1.8" | ||
Documenter = "1" | ||
LinearAlgebra = "1" | ||
SparseArrays = "1" | ||
StaticArrays = "1.4.2" | ||
Test = "1" |
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,36 @@ | ||
module StandardPackedStaticArrays | ||
|
||
import StandardPacked | ||
import StaticArrays | ||
|
||
# We need to be extra careful here - StaticArrays's broadcasting has higher precedence, but will try to write n^2 elements to | ||
# our linear index. But we can spell this out and only copy the upper triangle. | ||
@generated function StaticArrays._broadcast!(f, ::StaticArrays.Size{newsize}, dest::StandardPacked.SPMatrix, | ||
s::Tuple{Vararg{StaticArrays.Size}}, a...) where {newsize} | ||
sizes = [sz.parameters[1] for sz in s.parameters] | ||
|
||
indices = CartesianIndices(newsize) | ||
ps = StandardPacked.packedsize(newsize[1]) | ||
exprs_eval = similar(indices, Expr, ps) | ||
exprs_setindex = similar(indices, Expr, ps) | ||
cmp = StandardPacked.packed_isupper(dest) ? Base.:≤ : Base.:≥ | ||
j = 1 | ||
for current_ind ∈ indices | ||
if cmp(current_ind[1], current_ind[2]) | ||
exprs_vals = (StaticArrays.broadcast_getindex(sz, i, current_ind) for (i, sz) in enumerate(sizes)) | ||
symb_val_j = Symbol(:val_, j) | ||
exprs_eval[j] = :($symb_val_j = f($(exprs_vals...))) | ||
exprs_setindex[j] = :(dest[$j] = $symb_val_j) | ||
j += 1 | ||
end | ||
end | ||
|
||
return quote | ||
Base.@_inline_meta | ||
$(Expr(:block, exprs_eval...)) | ||
@inbounds $(Expr(:block, exprs_setindex...)) | ||
return dest | ||
end | ||
end | ||
|
||
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