@@ -342,28 +342,42 @@ using Base: oneto
342342
343343 @test F (1.5 ,1.5im ) ≈ hankelh1 (0 ,10 abs (1.5im - 1.5 ))
344344
345+ P = ProductFun ((x,y)-> x^ 2 * y^ 3 , Chebyshev () ⊗ Chebyshev ())
346+ @test (Derivative () * P)(0.1 , 0.2 ) ≈ ProductFun ((x,y)-> 2 x* y^ 3 )(0.1 , 0.2 )
347+ @test (P * Derivative ())(0.1 , 0.2 ) ≈ ProductFun ((x,y)-> x^ 2 * 3 y^ 2 )(0.1 , 0.2 )
348+
345349 P = ProductFun ((x,y)-> x* y, Chebyshev () ⊗ Chebyshev ())
346- x = Fun (); y = x;
347- @test Evaluation (1 ) * P == x
348- @test Evaluation (- 1 ) * P == - x
350+ xf = Fun (); yf = xf;
351+ xi, yi = 0.1 , 0.2
352+ x, y = xf (xi), yf (yi)
353+ @test Evaluation (1 ) * P == xf
354+ @test Evaluation (- 1 ) * P == - xf
349355 D1 = Derivative (Chebyshev () ⊗ Chebyshev (), [1 ,0 ])
350356 D2 = Derivative (Chebyshev () ⊗ Chebyshev (), [0 ,1 ])
351- @test (D2 * P)(0.1 , 0.2 ) ≈ x (0.1 )
352- @test (D1 * P)(0.1 , 0.2 ) ≈ y (0.2 )
353- @test ((P * D1) * P)(0.1 , 0.2 ) ≈ x (0.1 ) * (y (0.2 ))^ 2
354- @test ((P * D2) * P)(0.1 , 0.2 ) ≈ (x (0.1 ))^ 2 * y (0.2 )
355- @test ((I ⊗ Derivative ()) * P)(0.1 , 0.2 ) ≈ x (0.1 )
356- @test ((Derivative () ⊗ I) * P)(0.1 , 0.2 ) ≈ y (0.2 )
357+ @test (D2 * P)(xi, yi) ≈ x
358+ @test (D1 * P)(xi, yi) ≈ y
359+ @test ((P * D1) * P)(xi, yi) ≈ x * y^ 2
360+ @test ((P * D2) * P)(xi, yi) ≈ x^ 2 * y
361+ @test ((I ⊗ Derivative ()) * P)(xi, yi) ≈ x
362+ @test ((Derivative () ⊗ I) * P)(xi, yi) ≈ y
363+
364+ # distribute over plus operator
365+ @test ((D1 + Multiplication (xf)⊗ I) * P)(xi, yi) ≈ y + x^ 2 * y
366+ @test ((P * (D1 + Multiplication (xf)⊗ I)) * P)(xi, yi) ≈ x * y^ 2 + x^ 3 * y^ 2
367+
368+ A = (Multiplication (xf)⊗ I) * Derivative (Chebyshev ()^ 2 , [0 ,1 ])
369+ @test (A * P)(xi, yi) ≈ x^ 2
357370
358371 # MultivariateFun methods
359372 f = invoke (* , Tuple{KroneckerOperator, ApproxFunBase. MultivariateFun},
360373 Derivative () ⊗ I, P)
361- @test f (0.1 , 0.2 ) ≈ y ( 0.2 )
374+ @test f (xi, yi ) ≈ y
362375 O = invoke (* , Tuple{ApproxFunBase. MultivariateFun, KroneckerOperator},
363376 P, Derivative () ⊗ I)
364- @test (O * Fun (P))(0.1 , 0.2 ) ≈ x ( 0.1 ) * ( y ( 0.2 )) ^ 2
377+ @test (O * Fun (P))(xi, yi ) ≈ x * y ^ 2
365378
366379 @testset " chopping" begin
380+ local P
367381 M = [0 0 0 ; 0 1 0 ; 0 0 1 ]
368382 P = ProductFun (M, Chebyshev () ⊗ Chebyshev (), chopping = true )
369383 @test coefficients (P) == M
@@ -377,6 +391,23 @@ using Base: oneto
377391 P = ProductFun (M, Chebyshev () ⊗ Chebyshev (), chopping = true )
378392 @test all (iszero, coefficients (P))
379393 end
394+
395+ @testset " KroneckerOperator" begin
396+ local P
397+ P = ProductFun ((x,y)-> x^ 2 * y^ 3 , Chebyshev () ⊗ Chebyshev ())
398+ A = Multiplication (xf)⊗ I
399+ a = (KroneckerOperator (A) * P)(xi, yi)
400+ b = (A * P)(xi, yi)
401+ @test a ≈ b
402+ a = ((P * KroneckerOperator (A)) * P)(xi, yi)
403+ b = ((P * A) * P)(xi, yi)
404+ @test a ≈ b
405+ # distribute a KroneckerOperator over a times operator
406+ A = (Multiplication (xf)⊗ I) * Derivative (Chebyshev ()^ 2 , [0 ,1 ])
407+ a = ((P * A) * P)(xi, yi)
408+ b = ((P * KroneckerOperator (A)) * P)(xi, yi)
409+ @test a ≈ b
410+ end
380411 end
381412
382413 @testset " Functional*Fun" begin
@@ -395,4 +426,13 @@ using Base: oneto
395426 f= Fun ((x,y)-> [exp (x* cos (y)) cos (x* sin (y)); 2 1 ],ChebyshevInterval ()^ 2 )
396427 @test f (0.1 ,0.2 ) ≈ [exp (0.1 * cos (0.2 )) cos (0.1 * sin (0.2 ));2 1 ]
397428 end
429+
430+ @testset " grad" begin
431+ f = Fun ((x,y)-> x^ 2 * y^ 3 , Chebyshev ()^ 2 )
432+ g = grad (f)
433+ @test g == grad (space (f))* f == grad (domain (f)) * f
434+ x = 0.1 ; y = 0.2
435+ @test g[1 ](x, y) ≈ 2 x* y^ 3
436+ @test g[2 ](x, y) ≈ x^ 2 * 3 y^ 2
437+ end
398438end
0 commit comments