Skip to content

Commit 86ea952

Browse files
committed
Add Colwise
1 parent 310ae8e commit 86ea952

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/TableTransforms.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ export
2222
# interface
2323
Transform,
2424
Stateless,
25+
Colwise,
2526
isrevertible,
26-
apply,
27+
apply, colapply,
28+
revert, colrevert,
2729
reapply,
28-
revert,
2930

3031
# built-in
3132
Select,

src/transforms.jl

+39-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ trait can be evaluated directly at any table implementing the
1717
"""
1818
abstract type Transform end
1919

20+
"""
21+
transform(table)
22+
23+
Automatically generated functor interface that calls [`apply`](@ref)
24+
with `transform` and `table`. New types don't need to implement this.
25+
"""
26+
(transform::Transform)(table) = apply(transform, table) |> first
27+
2028
"""
2129
isrevertible(transform)
2230
@@ -39,7 +47,7 @@ function apply end
3947
4048
Revert the `transform` on the `newtable` using the `cache` from the
4149
corresponding [`apply`](@ref) call and return the original `table`.
42-
Only defined when the transform [`isrevertible`](@ref).
50+
Only defined when the `transform` [`isrevertible`](@ref).
4351
"""
4452
function revert end
4553

@@ -62,12 +70,38 @@ that was created with a previous [`apply`](@ref) call.
6270
reapply(transform::Stateless, table, cache) = apply(transform, table)
6371

6472
"""
65-
transform(table)
73+
Colwise
6674
67-
Automatically generated functor interface that calls [`apply`](@ref)
68-
with `transform` and `table`.
75+
A transform that is applied column-by-column. In this case, the new type
76+
only needs to implement [`colapply`](@ref), [`colrevert`](@ref) and
77+
[`colcache`](@ref). Efficient fallbacks are provided that execute these
78+
functions in parallel for all columns with multiple threads.
6979
"""
70-
(transform::Transform)(table) = apply(transform, table) |> first
80+
abstract type Colwise <: Transform end
81+
82+
"""
83+
y = colapply(transform, x, c)
84+
85+
Apply `transform` to column `x` with cache `c` and return new column `y`.
86+
"""
87+
function colapply end
88+
89+
"""
90+
x = colrevert(transform, y, c)
91+
92+
Revert `transform` starting from column `y` with cache `c` and return
93+
original column `x`. Only defined when the `transform` [`isrevertible`](@ref).
94+
"""
95+
function colrevert end
96+
97+
"""
98+
c = colcache(transform, x)
99+
100+
Produce cache `c` necessary to [`colapply`](@ref) the `transform` on `x`.
101+
If the `transform` [`isrevertible`](@ref) then the cache `c` can also be
102+
used in [`colrevert`](@ref).
103+
"""
104+
function colcache end
71105

72106
# ----------------
73107
# IMPLEMENTATIONS

0 commit comments

Comments
 (0)