File tree 3 files changed +23
-3
lines changed
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 7
7
8
8
The transform that applies a `function` elementwise.
9
9
"""
10
- struct Functional <: Colwise
11
- func:: Function
10
+ struct Functional{F} <: Colwise
11
+ func:: F
12
12
end
13
13
14
14
isrevertible (transform:: Functional ) =
@@ -23,7 +23,7 @@ inverse(::typeof(sin)) = asin
23
23
inverse (:: typeof (asin)) = sin
24
24
25
25
# fallback to nothing
26
- inverse (:: Function ) = nothing
26
+ inverse (:: Any ) = nothing
27
27
28
28
colcache (:: Functional , x) = nothing
29
29
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ islinux = Sys.islinux()
20
20
visualtests = ! isCI || (isCI && islinux)
21
21
datadir = joinpath (@__DIR__ ," data" )
22
22
23
+ # for functor tests in Functional testset
24
+ struct Polynomial{T<: Real }
25
+ coeffs:: Vector{T}
26
+ end
27
+ Polynomial (args:: T... ) where {T<: Real } = Polynomial (collect (args))
28
+ (p:: Polynomial )(x) = sum (a * x^ (i- 1 ) for (i, a) in enumerate (p. coeffs))
29
+
23
30
# list of tests
24
31
testfiles = [
25
32
" distributions.jl" ,
Original file line number Diff line number Diff line change 358
358
n, c = apply (T, t)
359
359
@test t == n
360
360
@test isrevertible (T) == false
361
+
362
+ # functor tests
363
+ x = rand (1500 )
364
+ y = rand (1500 )
365
+ t = Table (; x, y)
366
+ f = Polynomial (1 , 2 , 3 ) # f(x) = 1 + 2x + 3x²
367
+ T = Functional (f)
368
+ n, c = apply (T, t)
369
+ @test f .(x) == n. x
370
+ @test f .(y) == n. y
371
+ @test all (≥ (1 ), n. x)
372
+ @test all (≥ (1 ), n. y)
373
+ @test isrevertible (T) == false
361
374
end
362
375
363
376
@testset " EigenAnalysis" begin
You can’t perform that action at this time.
0 commit comments