@@ -3,21 +3,15 @@ splitmap(g,d::Domain,pts) = Fun(g,split(d , pts))
3
3
4
4
function split (d:: IntervalOrSegment , pts)
5
5
a,b = endpoints (d)
6
- isendpoint = true
7
- for p in pts
8
- if ! (p ≈ a) && ! (p ≈ b)
9
- isendpoint = false
10
- break
11
- end
12
- end
6
+ isendpoint = all (p -> p ≈ a || p ≈ b, pts)
13
7
isendpoint && return d
14
8
15
- @assert all (in .(pts, Ref (d)) )
9
+ @assert all (in (d), pts )
16
10
PiecewiseSegment (sort! (union (endpoints (d), pts)))
17
11
end
18
12
19
13
function split (d:: PiecewiseSegment , pts)
20
- @assert all (in .(pts, Ref (d)) )
14
+ @assert all (in (d), pts )
21
15
PiecewiseSegment (sort! (union (d. points, pts)))
22
16
end
23
17
411
405
for SP in (:ConstantSpace ,:PointSpace )
412
406
for OP in (:abs ,:sign ,:exp ,:sqrt ,:angle )
413
407
@eval begin
414
- $ OP (z:: Fun{<:$SP,<:Complex} ) = Fun (space (z),$ OP .( coefficients (z)))
415
- $ OP (z:: Fun{<:$SP,<:Real} ) = Fun (space (z),$ OP .( coefficients (z)))
416
- $ OP (z:: Fun{<:$SP} ) = Fun (space (z),$ OP .( coefficients (z)))
408
+ $ OP (z:: Fun{<:$SP,<:Complex} ) = Fun (space (z),map ( $ OP, coefficients (z)))
409
+ $ OP (z:: Fun{<:$SP,<:Real} ) = Fun (space (z),map ( $ OP, coefficients (z)))
410
+ $ OP (z:: Fun{<:$SP} ) = Fun (space (z),map ( $ OP, coefficients (z)))
417
411
end
418
412
end
419
413
@@ -500,35 +494,42 @@ for op in (:(argmax),:(argmin))
500
494
end
501
495
end
502
496
497
+ if VERSION < v " 1.7"
498
+ _maybemap (rf, f, pts) = rf (map (f, pts))
499
+ else
500
+ _maybemap (rf, f, pts) = rf (f, pts)
501
+ end
502
+
503
503
for op in (:(findmax),:(findmin))
504
504
@eval begin
505
505
function $op (f:: Fun{<:RealSpace,<:Real} )
506
506
# the following avoids warning when differentiate(f)==0
507
507
pts = extremal_args (f)
508
- ext,ind = $ op ( f .( pts) )
509
- ext,pts[ind]
508
+ ext,ind = _maybemap ( $ op, f, pts)
509
+ ext,pts[ind]
510
510
end
511
511
end
512
512
end
513
513
514
- extremal_args (f:: Fun{<:PiecewiseSpace} ) = cat (1 ,[extremal_args (fp) for fp in components (f)]. .. , dims= 1 )
514
+ extremal_args (f:: Fun{<:PiecewiseSpace} ) = cat (1 ,[extremal_args (fp) for fp in components (f)], dims= 1 )
515
515
516
516
function extremal_args (f:: Fun )
517
517
d = domain (f)
518
-
519
- dab = strictconvert (Vector{Number}, collect (components (∂ (domain (f)))))
520
- if ncoefficients (f) <= 2 # TODO this is only relevant for Polynomial bases
521
- dab
522
- else
523
- [dab;roots (differentiate (f))]
518
+ T = prectype (d)
519
+ dab = strictconvert (Vector{T}, collect (components (∂ (domain (f)))))
520
+ if ncoefficients (f) > 2 # TODO this is only relevant for Polynomial bases
521
+ r = roots (differentiate (f))
522
+ if ! isempty (r)
523
+ append! (dab, r)
524
+ end
524
525
end
526
+ return dab
525
527
end
526
528
527
529
for op in (:(maximum),:(minimum),:(extrema))
528
530
@eval function $op (f:: Fun{<:RealSpace,<:Real} )
529
531
pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
530
- v = map (f, pts)
531
- $ op (v)
532
+ _maybemap ($ op, f, pts)
532
533
end
533
534
end
534
535
@@ -537,12 +538,12 @@ for op in (:(maximum),:(minimum))
537
538
@eval begin
538
539
function $op (:: typeof (abs), f:: Fun{<:RealSpace,<:Real} )
539
540
pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
540
- $ op ( f .( pts) )
541
+ _maybemap ( $ op, f, pts)
541
542
end
542
543
function $op (:: typeof (abs), f:: Fun )
543
544
# complex spaces/types can have different extrema
544
545
pts = extremal_args (abs (f))
545
- $ op ( f .( pts) )
546
+ _maybemap ( $ op, f, pts)
546
547
end
547
548
$ op (f:: Fun{PiecewiseSpace{<:Any,<:UnionDomain,<:Real},<:Real} ) =
548
549
$ op (map ($ op,components (f)))
0 commit comments