Open BertvanderVeen opened 1 year ago
Hi @BertvanderVeen - thanks for posting this issue
I confirm this behaviour and also compare it to base R:
mat <- matrix(1:12, 3, 4)
greta_mat <- greta::as_data(mat)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#>
greta_mat[1:3, ]
#> greta array (operation)
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 1 4 7 10
#> [2,] 2 5 8 11
#> [3,] 3 6 9 12
mat[1:3, ]
#> [,1] [,2] [,3] [,4]
#> [1,] 1 4 7 10
#> [2,] 2 5 8 11
#> [3,] 3 6 9 12
mat[, 2:4] <- 1:9
mat
#> [,1] [,2] [,3] [,4]
#> [1,] 1 1 4 7
#> [2,] 2 2 5 8
#> [3,] 3 3 6 9
greta_mat[, 2:4] <- 1:9
greta_mat
#> greta array (operation)
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 1 1 4 7
#> [2,] 2 2 5 8
#> [3,] 3 3 6 9
diag(mat)
#> [1] 1 2 6
greta::diag(greta_mat)
#> Error: diagonal elements can only be extracted from square matrices
Created on 2023-02-08 with reprex v2.0.2
@goldingn was there any particular reason that this was only allowed to work for square matrices with greta arrays?
I've confirmed with @goldingn that we should mimic R's behaviour - so we will fix this to act as such.
Greta overloads the R base diag function, but the greta version does not seem to function as advertised; it should extract the main diagonal of a rectangular matrix but instead throws an error. Example from https://greta-stats.org/reference/extract-replace-combine.html below.