-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from JuliaAlgebra/sexponents
Make SExponents opaque isbits type
- Loading branch information
Showing
7 changed files
with
47 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
export SExponents | ||
|
||
struct SExponents{E} | ||
function SExponents{E}() where { E} | ||
@assert typeof(E) <: NTuple{N, Int} where N "Exponents type invalid" | ||
new() | ||
end | ||
struct SExponents{N} | ||
exponents::NTuple{N, UInt8} | ||
size::Tuple{Int,Int} # nvars, nterms | ||
end | ||
|
||
function SExponents(exponents::Matrix{<:Integer}) | ||
# NVars = size(exponents, 1) | ||
E = ntuple(i -> convert(Int, exponents[i]), length(exponents)) | ||
E = ntuple(i -> convert(UInt8, exponents[i]), length(exponents)) | ||
|
||
return SExponents(E, size(exponents)) | ||
end | ||
|
||
return SExponents{E}() | ||
Base.isbits(::Type{<:SExponents}) = true | ||
Base.length(::SExponents{N}) where N = N | ||
function Base.:(==)(f::SExponents{N}, g::SExponents{N}) where {N} | ||
f.exponents == g.exponents && f.size == g.size | ||
end | ||
Base.hash(f::SExponents, h) = hash(f.exponents, hash(f.size, h)) | ||
|
||
|
||
""" | ||
exponents(::SExponents) | ||
Converts exponents stored in a `SExponents` to a matrix. | ||
""" | ||
function exponents(::Type{SExponents{E}}, nvars) where {E} | ||
nterms = div(length(E), nvars) | ||
function exponents(SE::SExponents) | ||
nvars, nterms = SE.size | ||
exps = fill(0, nvars, nterms) | ||
for k=1:nvars*nterms | ||
exps[k] = E[k] | ||
exps[k] = SE.exponents[k] | ||
end | ||
exps | ||
end | ||
exponents(::S, nvars) where {S<:SExponents} = exponents(S, nvars) | ||
|
||
function Base.show(io::IO, ::Type{SExponents{E}}) where {E} | ||
exps_hash = num2hex(hash(E)) | ||
print(io, "SExponents{$(exps_hash)}") | ||
function Base.show(io::IO, SE::SExponents{N}) where {N} | ||
exps_hash = num2hex(hash(SE.exponents)) | ||
print(io, "SExponents{$N}($(exps_hash))") | ||
end | ||
Base.show(io::IO, S::SExponents) = print(io, typeof(S), "()") |
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