@@ -46,7 +46,7 @@ Sample(size::Int, weights::AbstractWeights;
46
46
Sample (size:: Int , weights; kwargs... ) =
47
47
Sample (size, Weights (collect (weights)); kwargs... )
48
48
49
- isrevertible (:: Type{<:Sample} ) = false
49
+ isrevertible (:: Type{<:Sample} ) = true
50
50
51
51
function preprocess (transform:: Sample , table)
52
52
# retrieve valid indices
@@ -60,24 +60,47 @@ function preprocess(transform::Sample, table)
60
60
rng = transform. rng
61
61
62
62
# sample a subset of indices
63
- if isnothing (weights)
63
+ sinds = if isnothing (weights)
64
64
sample (rng, inds, size; replace, ordered)
65
65
else
66
66
sample (rng, inds, weights, size; replace, ordered)
67
67
end
68
+ rinds = setdiff (inds, sinds)
69
+
70
+ sinds, rinds
68
71
end
69
72
70
73
function applyfeat (:: Sample , table, prep)
71
74
# collect all rows
72
75
rows = Tables. rowtable (table)
73
76
74
77
# preprocessed indices
75
- sinds = prep
78
+ sinds, rinds = prep
76
79
77
80
# select rows
78
81
srows = view (rows, sinds)
82
+ rrows = view (rows, rinds)
83
+
84
+ stable = srows |> Tables. materializer (table)
85
+
86
+ stable, (sinds, rinds, rrows)
87
+ end
88
+
89
+ function revertfeat (:: Sample , newtable, fcache)
90
+ # collect all rows
91
+ rows = Tables. rowtable (newtable)
92
+
93
+ sinds, rinds, rrows = fcache
79
94
80
- newtable = srows |> Tables. materializer (table)
95
+ uinds = sort (unique (sinds))
96
+ urows = map (uinds) do i
97
+ j = findfirst (== (i), sinds)
98
+ rows[j]
99
+ end
100
+
101
+ for (i, row) in zip (rinds, rrows)
102
+ insert! (urows, i, row)
103
+ end
81
104
82
- newtable, nothing
105
+ urows |> Tables . materializer (newtable)
83
106
end
0 commit comments