Skip to content
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

Jishnub aqua #546

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
immutable path for zero
  • Loading branch information
jverzani committed Dec 2, 2023
commit 52246fc8e609ba82963d340fbe7672c8e4008676
19 changes: 11 additions & 8 deletions src/polynomial-container-types/immutable-dense-polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@
"""
struct ImmutableDensePolynomial{B,T,X,N} <: AbstractDenseUnivariatePolynomial{B,T,X}
coeffs::NTuple{N,T}
function ImmutableDensePolynomial{B,T,X,N}(cs::NTuple{N}) where {B,N,T,X}
#function ImmutableDensePolynomial{B,T,X,N}(cs::NTuple{N,T}) where {B,N,T,X}
# new{B,T,Symbol(X),N}(cs)
#end
function ImmutableDensePolynomial{B,T,X,N}(cs::Tuple{S,Vararg{S}}) where {B,N,T,X, S}
m = length(cs)
m > N && throw(ArgumentError("Tuple too large for N"))
m < N && (cs = ntuple(i -> i <= m ? cs[i] : zero(T), Val(N)))
new{B,T,Symbol(X),N}(T.(cs))
end
function ImmutableDensePolynomial{B,T,X,N}(cs::Tuple{}) where {B,N,T,X}
new{B,T,Symbol(X),N}(cs)
end
end


ImmutableDensePolynomial{B,T,X,N}(check::Type{Val{false}}, cs::NTuple{N,T}) where {B,N,T,X} =
ImmutableDensePolynomial{B,T,X}(cs)

ImmutableDensePolynomial{B,T,X,N}(check::Type{Val{true}}, cs::NTuple{N,T}) where {B,N, T,X} =
ImmutableDensePolynomial{B,T,X,N}(cs)

# tuple with mismatched size
function ImmutableDensePolynomial{B,T,X,N}(xs::Tuple{S,Vararg{S}}) where {B,T,S,X,N}
M = length(xs)
p = ImmutableDensePolynomial{B,S,X,M}(xs)
convert(ImmutableDensePolynomial{B,T,X,N}, ImmutableDensePolynomial{B,T,X,M}(xs))
end

# vector case with N
function ImmutableDensePolynomial{B,T,X,N}(xs::AbstractVector{S}) where {B,T,S,X,N}
ImmutableDensePolynomial{B,T,X,N}(ntuple(Base.Fix1(getindex, xs), Val(N)))
Expand All @@ -47,9 +50,9 @@
cs = ntuple(i -> i == 1 ? T(c) : zero(T), Val(N))
return ImmutableDensePolynomial{B,T,X,N}(cs)
end
function ImmutableDensePolynomial{B,T,X}(::Val{false}, xs::Tuple{S,Vararg{S}}) where {B,T,S,X}
N = length(xs)
ImmutableDensePolynomial{B,T,X,N}(convert(NTuple{N,T}, xs))

Check warning on line 55 in src/polynomial-container-types/immutable-dense-polynomial.jl

View check run for this annotation

Codecov / codecov/patch

src/polynomial-container-types/immutable-dense-polynomial.jl#L53-L55

Added lines #L53 - L55 were not covered by tests
end
ImmutableDensePolynomial{B,T,X}(xs::NTuple{N}) where {B,T,X,N} = ImmutableDensePolynomial{B,T,X,N}(convert(NTuple{N,T}, xs))
ImmutableDensePolynomial{B,T}(xs::NTuple{N}, var::SymbolLike=Var(:x)) where {B,T,N} = ImmutableDensePolynomial{B,T,Symbol(var),N}(xs)
Expand Down
Loading