-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
memcmp for complex instead of == on double
- Loading branch information
Showing
1 changed file
with
19 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,14 +196,13 @@ SEXP rleid(SEXP l, SEXP cols) { | |
break; | ||
case REALSXP : { | ||
long long *ll = (long long *)REAL(jcol); | ||
same = ll[i]==ll[i-1]; } | ||
same = ll[i]==ll[i-1]; | ||
// 8 bytes of bits are identical. For real (no rounding currently) and integer64 | ||
// long long == 8 bytes checked in init.c | ||
break; | ||
} break; | ||
case CPLXSXP: { | ||
// tried to make long long complex * but got a warning that it's a GNU extension | ||
Rcomplex *pz = COMPLEX(jcol); | ||
same = pz[i].r == pz[i-1].r && pz[i].i == pz[i-1].i; | ||
same = memcmp(&pz[i], &pz[i-1], sizeof(Rcomplex))==0; // compiler optimization should replace library call with best 16-byte fixed method | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mattdowle
Author
Member
|
||
} break; | ||
default : | ||
error("Type '%s' not supported", type2char(TYPEOF(jcol))); // # nocov | ||
|
@@ -215,32 +214,30 @@ SEXP rleid(SEXP l, SEXP cols) { | |
SEXP jcol = VECTOR_ELT(l, icols[0]-1); | ||
switch (TYPEOF(jcol)) { | ||
case INTSXP : case LGLSXP : { | ||
int *ijcol = INTEGER(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = ijcol[i]==ijcol[i-1]; | ||
ians[i] = (grp+=!same); | ||
} | ||
int *ijcol = INTEGER(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = ijcol[i]==ijcol[i-1]; | ||
ians[i] = (grp+=!same); | ||
} | ||
break; | ||
} break; | ||
case STRSXP : { | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = STRING_ELT(jcol,i)==STRING_ELT(jcol,i-1); | ||
ians[i] = (grp+=!same); | ||
} | ||
const SEXP *jd = STRING_PTR(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = jd[i]==jd[i-1]; | ||
ians[i] = (grp+=!same); | ||
} | ||
break; | ||
} break; | ||
case REALSXP : { | ||
long long *lljcol = (long long *)REAL(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = lljcol[i]==lljcol[i-1]; | ||
ians[i] = (grp+=!same); | ||
} | ||
long long *lljcol = (long long *)REAL(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = lljcol[i]==lljcol[i-1]; | ||
ians[i] = (grp+=!same); | ||
} | ||
break; | ||
} break; | ||
case CPLXSXP: { | ||
Rcomplex *pzjcol = COMPLEX(jcol); | ||
for (R_xlen_t i=1; i<nrow; i++) { | ||
bool same = pzjcol[i].r == pzjcol[i-1].r && pzjcol[i].i == pzjcol[i-1].i; | ||
bool same = memcmp(&pzjcol[i], &pzjcol[i-1], sizeof(Rcomplex))==0; | ||
ians[i] = (grp += !same); | ||
} | ||
} break; | ||
|
if memcmp for complex, why not for the other types as well?