Skip to content

Commit

Permalink
Remove inference API-based code path (outtype)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Aug 18, 2019
1 parent 74ee4a2 commit 36f8211
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 605 deletions.
4 changes: 2 additions & 2 deletions benchmark/bench_dot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ suite["xf"] = @benchmarkable(

# This is a bit "cheating" since it's using non-public API. It is
# just to show the lower-bound of Transducers.jl runtime:
rf = Transducers._reducingfunction(
MapSplat(*), +, Tuple{Float64, Float64};
rf = reducingfunction(
MapSplat(*), +;
simd = true)
suite["rf"] = @benchmarkable(
transduce($rf, 0.0, zs),
Expand Down
23 changes: 11 additions & 12 deletions benchmark/bench_missing_argmax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ end
random_missings(n = 10^3, th=2) = [abs(x) > th ? missing : x for x in randn(n)]

argext_step(should_update) =
((oldindex, oldvalue), (index, value)) ->
should_update(oldvalue, value) ? (index, value) : (oldindex, oldvalue)
init_helper(::typeof(>), ::Type{Tuple{F, S}}) where {F, S} = (zero(F), typemax(S))
init_helper(::typeof(<), ::Type{Tuple{F, S}}) where {F, S} = (zero(F), typemin(S))
argext_init(should_update) = Initializer(TT -> init_helper(should_update, TT))
(old, (index, value)) ->
if old === nothing || should_update(old[2], value)
(index, value)
else
old
end

xf_scanext(should_update) = Scan(argext_step(should_update),
argext_init(should_update))
xf_scanext(should_update) = Scan(argext_step(should_update), nothing)

xf_argmax = Enumerate() |>
OfType(Tuple{Integer, Number}) |>
Expand All @@ -45,17 +45,16 @@ let xs = random_missings()
end

suite["xf"] = @benchmarkable(
foldl(right, ed; init=$(argext_init(<))),
foldl(right, ed; init=nothing),
setup=(ed = eduction(xf_argmax, random_missings())))

rf = Transducers._reducingfunction(
rf = reducingfunction(
xf_argmax,
right,
Union{Missing, Float64};
right;
# simd = true,
)
suite["rf"] = @benchmarkable(
transduce($rf, $(argext_init(<)), xs),
transduce($rf, nothing, xs),
setup=(xs = random_missings()))

suite["man"] = @benchmarkable(
Expand Down
12 changes: 4 additions & 8 deletions benchmark/bench_missing_dot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,18 @@ suite["xf"] = @benchmarkable(

# This is a bit "cheating" since it's using non-public API. It is
# just to show the lower-bound of Transducers.jl runtime:
rf_nota = Transducers._reducingfunction(
rf_nota = reducingfunction(
MapSplat(*) |> NotA(Missing),
+,
Tuple{Union{Missing, Float64},
Union{Missing, Float64}};
+;
# simd = true,
)
suite["rf_nota"] = @benchmarkable(
transduce($rf_nota, 0.0, zs),
setup=(zs = zip(random_missings.(($n, $n))...)))

rf_oftype = Transducers._reducingfunction(
rf_oftype = reducingfunction(
OfType(Tuple{Vararg{Number}}) |> MapSplat(*),
+,
Tuple{Union{Missing, Float64},
Union{Missing, Float64}};
+;
# simd = true,
)
suite["rf"] = @benchmarkable(
Expand Down
35 changes: 16 additions & 19 deletions docs/src/doctests/show_rf.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,48 @@ end
```

```jldoctest
Reduction(
Filter(isfinite) |> Map(sin),
+,
Float64)
Reduction(Filter(isfinite) |> Map(sin), +)
# output
Reduction{▶ Float64}(
Reduction(
Filter(isfinite),
Reduction{▶ Float64}(
Reduction(
Map(sin),
BottomRF{▶ Float64}(
BottomRF(
+)))
```

```jldoctest
rf = Reduction(Map(error), right, Int64)
rf = Reduction(Map(error), right)
# output
Reduction{▶ Int64}(
Reduction(
Map(error),
BottomRF{▶ Union{}}(
BottomRF(
Transducers.right))
```

```jldoctest
rf = Reduction(
TeeZip(Filter(isodd) |> Map(identity) |> TeeZip(Map(identity))),
right,
Any)
)
# output
Splitter{▶ Any}(
Reduction{▶ Any}(
Splitter(
Reduction(
Filter(isodd),
Reduction{▶ Any}(
Reduction(
Map(identity),
Splitter{▶ Any}(
Reduction{▶ Any}(
Splitter(
Reduction(
Map(identity),
Joiner{▶ ⦃Any, Any⦄}(
Joiner{▶ ⦃Any, ⦃Any, Any⦄⦄}(
BottomRF{▶ ⦃Any, ⦃Any, Any⦄⦄}(
Joiner(
Joiner(
BottomRF(
Transducers.right))))))))
```

Expand Down
1 change: 0 additions & 1 deletion docs/src/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Transducers.start
Transducers.next
Transducers.@next
Transducers.complete
Transducers.outtype
```

## Helpers for stateful transducers
Expand Down
1 change: 0 additions & 1 deletion docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ reducingfunction
Completing
OnInit
CopyInit
Initializer
right
setinput
AdHocFoldable
Expand Down
11 changes: 0 additions & 11 deletions examples/transducers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ end # hide

collect(AddOneIfInt(), Any[3, nothing, 2.0, missing, 5])

# Notice that output `eltype` is `Any`; it can be fixed by defining
# `outtype`:

Transducers.outtype(::AddOneIfInt, _intype) = Int

addone_out2 = begin # hide
collect(AddOneIfInt(), 1:5)
end # hide

# ## Stateful transducer
#
# `AddOneIfInt` is a stateless transducer which is very easy to
Expand Down Expand Up @@ -97,8 +88,6 @@ function Transducers.next(rf::R_{RandomRecall}, result, input)
end
end

Transducers.outtype(::RandomRecall, intype) = intype

# Any transducer with custom [`Transducers.start`](@ref) must have a
# corresponding [`Transducers.complete`](@ref). It is responsible for
# unwrapping the `result` and call the `complete` for the inner
Expand Down
4 changes: 1 addition & 3 deletions src/Transducers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export Transducer, Map, Filter, Cat, MapCat, Take, PartitionBy, Scan, Zip,
Interpose, Dedupe, Partition, Iterated, Count, GroupBy, ReduceIf,
TakeLast, FlagFirst, MapSplat, ScanEmit, Enumerate, NotA, OfType,
transduce, eduction, setinput, Reduced, reduced, unreduced, ifunreduced,
Completing, Initializer, OnInit, CopyInit, right, reducingfunction,
Completing, OnInit, CopyInit, right, reducingfunction,
AdHocFoldable

# Deprecated:
Expand Down Expand Up @@ -37,8 +37,6 @@ include("deprecated.jl")
include("interop/blockarrays.jl")
include("interop/lazyarrays.jl")

include("evals.jl")

function __init__()
@require BlockArrays="8e7c35d0-a365-5155-bbbb-fb81a777f24e" begin
__foldl__(rf, acc, coll::BlockArrays.BlockArray) =
Expand Down
Loading

0 comments on commit 36f8211

Please sign in to comment.