Skip to content

GForce double brackets #3209

@renkun-ken

Description

@renkun-ken

I'm not sure if there's a reason that [[ is not gforce-optimized while [ is?

library(data.table)

dt <- data.table(group = rep(1:10, each = 100))
dt[, x := rnorm(.N)]
dt[, y := rnorm(.N)]

dt[, .(x1 = x[1], y = y[1]), keyby = group, verbose = TRUE]
#> Detected that j uses these columns: x,y 
#> Finding groups using forderv ... 0.008s elapsed (0.034s cpu) 
#> Finding group sizes from the positions (can be avoided to save RAM) ... 0.000s elapsed (0.000s cpu) 
#> lapply optimization is on, j unchanged as 'list(x[1], y[1])'
#> GForce optimized j to 'list(`g[`(x, 1), `g[`(y, 1))'
#> Making each group and running j (GForce TRUE) ... 0.000s elapsed (0.001s cpu)
#>     group          x1          y
#>  1:     1  0.53517123 -0.9882846
#>  2:     2  0.51018979 -0.2830759
#>  3:     3  1.24404772  0.3771081
#>  4:     4  0.04945898  0.2840527
#>  5:     5 -0.94713301  0.5256134
#>  6:     6  1.05691797 -0.7430845
#>  7:     7  0.53789528 -0.4212249
#>  8:     8  0.69661191 -0.0915251
#>  9:     9  1.74234732 -0.6924493
#> 10:    10  1.11381907  0.2091079

dt[, .(x1 = x[[1]], y = y[[1]]), keyby = group, verbose = TRUE]
#> Detected that j uses these columns: x,y 
#> Finding groups using forderv ... 0.000s elapsed (0.000s cpu) 
#> Finding group sizes from the positions (can be avoided to save RAM) ... 0.000s elapsed (0.000s cpu) 
#> lapply optimization is on, j unchanged as 'list(x[[1]], y[[1]])'
#> GForce is on, left j unchanged
#> Old mean optimization is on, left j unchanged.
#> Making each group and running j (GForce FALSE) ... 
#>   memcpy contiguous groups took 0.000s for 10 groups
#>   eval(j) took 0.000s for 10 calls
#> 0.000s elapsed (0.000s cpu)
#>     group          x1          y
#>  1:     1  0.53517123 -0.9882846
#>  2:     2  0.51018979 -0.2830759
#>  3:     3  1.24404772  0.3771081
#>  4:     4  0.04945898  0.2840527
#>  5:     5 -0.94713301  0.5256134
#>  6:     6  1.05691797 -0.7430845
#>  7:     7  0.53789528 -0.4212249
#>  8:     8  0.69661191 -0.0915251
#>  9:     9  1.74234732 -0.6924493
#> 10:    10  1.11381907  0.2091079

Metadata

Metadata

Assignees

No one assigned

    Labels

    GForceissues relating to optimized grouping calculations (GForce)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions