Skip to content

Commit bfb4b00

Browse files
Merge pull request #68 from r-lib/no-names-data1
No names for data1 list
2 parents 10dce2a + 8c0a166 commit bfb4b00

10 files changed

+21
-47
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sparsevctrs (development version)
22

3+
* All sparse vector types now have a significant smaller base object size. (#67)
4+
35
# sparsevctrs 0.1.0
46

57
* Initial CRAN submission.

R/sparse_character.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ sparse_character <- function(values, positions, length, default = "") {
7171

7272
new_sparse_character <- function(values, positions, length, default) {
7373
x <- list(
74-
val = values,
75-
pos = positions,
76-
len = length,
77-
default = default
74+
values,
75+
positions,
76+
length,
77+
default
7878
)
7979

8080
.Call(ffi_altrep_new_sparse_string, x)

R/sparse_double.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ sparse_double <- function(values, positions, length, default = 0) {
8282

8383
new_sparse_double <- function(values, positions, length, default) {
8484
x <- list(
85-
val = values,
86-
pos = positions,
87-
len = length,
88-
default = default
85+
values,
86+
positions,
87+
length,
88+
default
8989
)
9090

9191
.Call(ffi_altrep_new_sparse_double, x)

R/sparse_integer.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ sparse_integer <- function(values, positions, length, default = 0L) {
8282

8383
new_sparse_integer <- function(values, positions, length, default) {
8484
x <- list(
85-
val = values,
86-
pos = positions,
87-
len = length,
88-
default = default
85+
values,
86+
positions,
87+
length,
88+
default
8989
)
9090

9191
.Call(ffi_altrep_new_sparse_integer, x)

R/sparse_logical.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ sparse_logical <- function(values, positions, length, default = FALSE) {
6969

7070
new_sparse_logical <- function(values, positions, length, default) {
7171
x <- list(
72-
val = values,
73-
pos = positions,
74-
len = length,
75-
default = default
72+
values,
73+
positions,
74+
length,
75+
default
7676
)
7777

7878
.Call(ffi_altrep_new_sparse_logical, x)

src/altrep-sparse-double.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ static SEXP altrep_sparse_double_Extract_subset(SEXP x, SEXP indx, SEXP call) {
140140
SEXP out_default = extract_default(x);
141141
SET_VECTOR_ELT(out, 3, out_default);
142142

143-
SEXP names = Rf_allocVector(STRSXP, 4);
144-
Rf_setAttrib(out, R_NamesSymbol, names);
145-
SET_STRING_ELT(names, 0, Rf_mkChar("val"));
146-
SET_STRING_ELT(names, 1, Rf_mkChar("pos"));
147-
SET_STRING_ELT(names, 2, Rf_mkChar("len"));
148-
SET_STRING_ELT(names, 3, Rf_mkChar("default"));
149-
150143
R_xlen_t i_out = 0;
151144

152145
for (R_xlen_t i = 0; i < size; ++i) {

src/altrep-sparse-integer.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ static SEXP altrep_sparse_integer_Extract_subset(SEXP x, SEXP indx, SEXP call) {
140140
SEXP out_default = extract_default(x);
141141
SET_VECTOR_ELT(out, 3, out_default);
142142

143-
SEXP names = Rf_allocVector(STRSXP, 4);
144-
Rf_setAttrib(out, R_NamesSymbol, names);
145-
SET_STRING_ELT(names, 0, Rf_mkChar("val"));
146-
SET_STRING_ELT(names, 1, Rf_mkChar("pos"));
147-
SET_STRING_ELT(names, 2, Rf_mkChar("len"));
148-
SET_STRING_ELT(names, 3, Rf_mkChar("default"));
149-
150143
R_xlen_t i_out = 0;
151144

152145
for (R_xlen_t i = 0; i < size; ++i) {

src/altrep-sparse-logical.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ static SEXP altrep_sparse_logical_Extract_subset(SEXP x, SEXP indx, SEXP call) {
140140
SEXP out_default = extract_default(x);
141141
SET_VECTOR_ELT(out, 3, out_default);
142142

143-
SEXP names = Rf_allocVector(STRSXP, 4);
144-
Rf_setAttrib(out, R_NamesSymbol, names);
145-
SET_STRING_ELT(names, 0, Rf_mkChar("val"));
146-
SET_STRING_ELT(names, 1, Rf_mkChar("pos"));
147-
SET_STRING_ELT(names, 2, Rf_mkChar("len"));
148-
SET_STRING_ELT(names, 3, Rf_mkChar("default"));
149-
150143
R_xlen_t i_out = 0;
151144

152145
for (R_xlen_t i = 0; i < size; ++i) {

src/altrep-sparse-string.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ static SEXP altrep_sparse_string_Extract_subset(SEXP x, SEXP indx, SEXP call) {
137137
SEXP out_default = extract_default(x);
138138
SET_VECTOR_ELT(out, 3, out_default);
139139

140-
SEXP names = Rf_allocVector(STRSXP, 4);
141-
Rf_setAttrib(out, R_NamesSymbol, names);
142-
SET_STRING_ELT(names, 0, Rf_mkChar("val"));
143-
SET_STRING_ELT(names, 1, Rf_mkChar("pos"));
144-
SET_STRING_ELT(names, 2, Rf_mkChar("len"));
145-
SET_STRING_ELT(names, 3, Rf_mkChar("default"));
146-
147140
R_xlen_t i_out = 0;
148141

149142
for (R_xlen_t i = 0; i < size; ++i) {

vignettes/articles/when-to-use.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ obj_size(integer(2000))
4040
obj_size(integer(3000))
4141
```
4242

43-
The vectors above only contained the value `0`. We can replicate that sparsely with `sparse_integer(integer(), integer(), length = 0)`. We see that the size of a 0-length sparse integer vector has a size of `1304 B = 1.3 kB`.
43+
The vectors above only contained the value `0`. We can replicate that sparsely with `sparse_integer(integer(), integer(), length = 0)`. We see that the size of a 0-length sparse integer vector has a size of `888 B`.
4444

4545
```{r}
4646
obj_size(sparse_integer(integer(), integer(), length = 0))
@@ -80,9 +80,9 @@ sparse_x <- sparse_integer(1:200, 1:200, 1000)
8080
obj_size(sparse_x)
8181
```
8282

83-
So it all comes down to a trade-off. Dense integer vectors with a size of 313 or less will be smaller than their sparse counterparts no matter what. Dense integer vector vectors with 314 elements will take up the same amount of memory as their sparse counterpart with no values.
83+
So it all comes down to a trade-off. Dense integer vectors with a size of 210 or less will be smaller than their sparse counterparts no matter what. Dense integer vector vectors with 211 elements will take up the same amount of memory as their sparse counterpart with no values.
8484

85-
From these values we can calculate memory equivalent vectors to determine which would be more efficient, noting that sparse vectors increase in size by twice for each non-default value that their dense counterpart. For a vector of length 1000, the sparse vector will be equivalent in size if it has `343` non-default values. And these values continue to go up.
85+
From these values we can calculate memory equivalent vectors to determine which would be more efficient, noting that sparse vectors increase in size by twice for each non-default value that their dense counterpart. For a vector of length 1000, the sparse vector will be equivalent in size if it has `210` non-default values. And these values continue to go up.
8686

8787
## Conversion speed
8888

0 commit comments

Comments
 (0)