File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 3939# `mutable_copy` recursively copies the vector or vector of integers.
4040MA. mutable_copy (m:: MV ) where {MV<: MonomialVector } = MV (copy (m. vars), MA. mutable_copy (m. Z))
4141Base. copy (m:: MonomialVector ) = MA. mutable_copy (m)
42- function Base. getindex (x:: MonomialVector , I)
42+ function Base. getindex (x:: MonomialVector , I:: AbstractVector{Bool} )
43+ return typeof (x)(x. vars, x. Z[I])
44+ end
45+ function Base. getindex (x:: MonomialVector , I:: AbstractVector{<:Integer} )
4346 return typeof (x)(x. vars, x. Z[sort (I)])
4447end
4548Base. getindex (x:: MonomialVector , i:: Integer ) = Monomial (x. vars, x. Z[i])
Original file line number Diff line number Diff line change @@ -142,4 +142,13 @@ using Test
142142 @test y == DynamicPolynomials. MP. mapexponents_to! (z, - , x * y^ 2 , x * y)
143143 end
144144 end
145+ # TODO add to MP
146+ @testset " Indexing with boolean" begin
147+ @polyvar x y
148+ X = monomials ([x, y], 2 )
149+ @test X[[true , false , true ]] == monovec ([x^ 2 , y^ 2 ])
150+ X = monomials ([x, y], 0 : 1 )
151+ @test filter (mono -> degree (mono) == 1 , X) == monovec ([x, y])
152+ @test filter (mono -> degree (mono) == 0 , X) == monovec ([x^ 0 ])
153+ end
145154end
You can’t perform that action at this time.
0 commit comments