Conversation
Don't overwrite list elements unless necessary. Also visit and adjust lists inside attributes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7820 +/- ##
=======================================
Coverage 99.02% 99.02%
=======================================
Files 88 88
Lines 17266 17282 +16
=======================================
+ Hits 17097 17113 +16
Misses 169 169 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Generated via commit 3439810 Download link for the artifact containing the test results: ↓ atime-results.zip
|
|
What immediately comes to my mind. How fast is this in terms of speed? |
| x = list() | ||
| attr(x, 'dt') = data.table() | ||
| test(2379, truelength(attr(copy(x), 'dt')) > 0L) | ||
| rm(x) |
There was a problem hiding this comment.
should we add a test for nested tables?
inner = data.table(a=1)
DT = data.table(x=1:2, y=list(inner, inner))
DT2 = copy(DT)
test(2379.1, truelength(DT2$y[[1L]]) > 0L) # is FALSE in current master
test(2379.2, DT2$y[[1L]][, b := 2][, b], 2) # warns in current master
| # copy() reallocates data.tables inside list attributes, #7820 | ||
| x = list() | ||
| attr(x, 'dt') = data.table() | ||
| test(2379, truelength(attr(copy(x), 'dt')) > 0L) |
There was a problem hiding this comment.
what if we have multiple attributes like:
x = list()
attr(x, 'foo') = 1:2
attr(x, 'dt') = data.table()
truelength(attr(copy(x), 'dt'))|
Not sure how atime works internally, but could this be because of some C interface overhead? |
ben-schwen
left a comment
There was a problem hiding this comment.
Change LGTM. Might want to look deeper into timings before merging though
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Co-Authored-By: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Co-Authored-By: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
|
TY. Great work, feel free to merge |

Rewrite
copy()in C so that instead of callingy[] <- lapply(y, reallocate)we can consider each individual list element and only callSET_VECTOR_ELTwhen necessary. This avoids the problem withxgboost's special altlist that must never be altered.Also walk the attributes of the object being copied, look for
data.tables and reallocate them. Maybe that's not necessary (copy()has been working fine without it) and can be taken out.Test 2224.3 points out an important detail: when
yis aLISTSXPpairlist,y[] <- lapply(y, reallocate)makes it into aVECSXPlist instead. It turns out we've been relying oncopy()automatically coercing pairlist columns into vector lists when constructingdata.tables. Should this become more explicit and be moved somewhere into thedata.table()constructor, leavingcopy()to just duplicate + reallocatedata.tables?Unfortunately this is hard to test without loading
xgboostor creating a different altclass.Fixes: #7456