File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 100100# # put here, not with type definition, in case reuse is possible
101101# # `conv` can be used with matrix entries, unlike `fastconv`
102102function conv (p:: Vector{T} , q:: Vector{S} ) where {T,S}
103+ (isempty (p) || isempty (q)) && return promote_type (T, S)[]
103104 as = [p[1 ]* q[1 ]]
104- z = 0 * as[1 ]
105+ z = zero ( as[1 ])
105106 n,m = length (p)- 1 , length (q)- 1
106107 for i ∈ 1 : n+ m
107108 Σ = z
Original file line number Diff line number Diff line change 442442
443443 end
444444
445+ @testset " generic arithmetics" begin
446+ P = Polynomial
447+ # define a set algebra
448+ struct Setalg # not a number
449+ content:: Vector{Int}
450+ end
451+ Base.:(+ )(a:: Setalg , b:: Setalg ) = Setalg (a. content ∪ b. content)
452+ Base.:(* )(a:: Setalg , b:: Setalg ) = Setalg (vec ([x * y for x in a. content, y in b. content]))
453+ Base. zero (:: Setalg ) = Setalg (Int[])
454+ Base. one (:: Setalg ) = Setalg (Int[1 ])
455+ Base. zero (:: Type{Setalg} ) = Setalg (Int[])
456+ Base. one (:: Type{Setalg} ) = Setalg (Int[1 ])
457+ Base.:(== )(a:: Setalg , b:: Setalg ) = a. content == b. content
458+
459+ a = Setalg ([1 ])
460+ b = Setalg ([4 ,2 ])
461+ pNULL = P (Setalg[])
462+ p0 = P ([a])
463+ p1 = P ([a, b, b])
464+ @test pNULL * p0 == pNULL
465+ @test pNULL * p1 == pNULL
466+ @test p0 * p1 == p1
467+ end
468+
445469 @testset for P in Ps # ensure promotion of scalar +,*,/
446470 p = P ([1 ,2 ,3 ])
447471 @test p + 0.5 == ᵟ P ([1.5 , 2.0 , 3.0 ])
You can’t perform that action at this time.
0 commit comments