@@ -2861,6 +2861,12 @@ def test_mpolys():
28612861
28622862 ctx = get_context (("x" , 2 ))
28632863
2864+ def mpoly (x ):
2865+ return ctx .from_dict (x )
2866+
2867+ def quick_poly ():
2868+ return mpoly ({(0 , 0 ): 1 , (0 , 1 ): 2 , (1 , 0 ): 3 , (2 , 2 ): 4 })
2869+
28642870 assert raises (lambda : ctx .__class__ ("x" , flint .Ordering .lex ), RuntimeError )
28652871 assert raises (lambda : get_context (("x" , 2 ), ordering = "bad" ), ValueError )
28662872 assert raises (lambda : get_context (("x" , - 1 )), ValueError )
@@ -2877,17 +2883,41 @@ def test_mpolys():
28772883 assert raises (lambda : P (val = {"bad" : 1 }, ctx = None ), ValueError )
28782884 assert raises (lambda : P (val = "1" , ctx = None ), ValueError )
28792885
2886+ ctx1 = get_context (("x" , 4 ))
2887+ ctx2 = get_context (("x" , 4 ), ordering = "deglex" )
2888+ assert ctx1 .drop_gens (* ctx1 .names ()).names () == tuple ()
2889+ assert ctx1 .drop_gens (ctx1 .name (1 ), ctx1 .name (2 )).names () == (ctx1 .name (0 ), ctx1 .name (3 ))
2890+ assert ctx1 .drop_gens ().names () == ctx1 .names ()
2891+ assert ctx1 .drop_gens (- 1 ).names () == ctx1 .names ()[:- 1 ]
2892+
2893+ assert ctx .infer_generator_mapping (ctx ) == {i : i for i in range (ctx .nvars ())}
2894+ assert ctx1 .infer_generator_mapping (ctx ) == {0 : 0 , 1 : 1 }
2895+ assert ctx1 .drop_gens (* ctx .names ()).infer_generator_mapping (ctx ) == {}
2896+
2897+ # FIXME: Remove this guard when https://github.com/flintlib/flint/pull/2068 is
2898+ # resolved
2899+ if P is not flint .fmpz_mod_mpoly :
2900+ assert quick_poly ().coerce_to_context (ctx1 ) == \
2901+ ctx1 .from_dict (
2902+ {(0 , 0 , 0 , 0 ): 1 , (0 , 1 , 0 , 0 ): 2 , (1 , 0 , 0 , 0 ): 3 , (2 , 2 , 0 , 0 ): 4 }
2903+ )
2904+ assert quick_poly ().coerce_to_context (ctx1 ).drop_unused_gens () == (ctx , quick_poly ())
2905+
2906+ new_ctx , new_poly = quick_poly ().coerce_to_context (ctx2 ).drop_unused_gens ()
2907+ assert new_ctx != ctx
2908+ assert new_poly != quick_poly ()
2909+
2910+ new_ctx = new_ctx .from_context (new_ctx , ordering = ctx .ordering ())
2911+ assert new_ctx == ctx
2912+ assert new_poly .coerce_to_context (new_ctx ) == quick_poly ()
2913+ else :
2914+ assert raises (lambda : quick_poly ().coerce_to_context (ctx1 ), NotImplementedError )
2915+
28802916 assert P (val = {(0 , 0 ): 1 }, ctx = ctx ) == ctx .from_dict ({(0 , 0 ): 1 })
28812917 assert P (ctx = ctx ).context () == ctx
28822918 assert P (1 , ctx = ctx ).is_one ()
28832919 assert ctx .gen (1 ) == ctx .from_dict ({(0 , 1 ): 1 })
28842920
2885- def mpoly (x ):
2886- return ctx .from_dict (x )
2887-
2888- def quick_poly ():
2889- return mpoly ({(0 , 0 ): 1 , (0 , 1 ): 2 , (1 , 0 ): 3 , (2 , 2 ): 4 })
2890-
28912921 assert ctx .nvars () == 2
28922922 assert ctx .ordering () == flint .Ordering .lex
28932923
0 commit comments