Skip to content

Commit b2849e6

Browse files
committed
reformat cj.c
1 parent 681e0cb commit b2849e6

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/cj.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
- The memory copying operations (blockwise replication of data using memcpy)
77
- The creation of all combinations of the input vectors over the cross-product space
88
*/
9-
SEXP cj(SEXP base_list) {
9+
SEXP cj(SEXP base_list)
10+
{
1011
int ncol = LENGTH(base_list);
1112
SEXP out = PROTECT(allocVector(VECSXP, ncol));
1213
int nrow = 1;
1314
// already confirmed to be less than .Machine$integer.max at R level
14-
for (int j=0; j<ncol; ++j) nrow *= length(VECTOR_ELT(base_list, j));
15+
for (int j = 0; j < ncol; j++) nrow *= length(VECTOR_ELT(base_list, j));
1516
int eachrep = 1;
16-
for (int j=ncol-1; j>=0; --j) {
17+
for (int j = ncol - 1; j >= 0; j--) {
1718
SEXP source = VECTOR_ELT(base_list, j), target;
18-
SET_VECTOR_ELT(out, j, target=allocVector(TYPEOF(source), nrow));
19+
SET_VECTOR_ELT(out, j, target = allocVector(TYPEOF(source), nrow));
1920
copyMostAttrib(source, target); // includes levels of factors, integer64, custom classes, etc
20-
if (nrow==0) continue; // one or more columns are empty so the result will be empty, #2511
21+
if (nrow == 0) continue; // one or more columns are empty so the result will be empty, #2511
2122
int thislen = LENGTH(source);
22-
int blocklen = thislen*eachrep;
23-
int ncopy = nrow/blocklen;
23+
int blocklen = thislen * eachrep;
24+
int ncopy = nrow / blocklen;
2425
switch(TYPEOF(source)) {
2526
case LGLSXP:
2627
case INTSXP: {
@@ -29,64 +30,64 @@ SEXP cj(SEXP base_list) {
2930
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
3031
// default static schedule so two threads won't write to same cache line in last column
3132
// if they did write to same cache line (and will when last column's thislen is small) there's no correctness issue
32-
for (int i=0; i<thislen; ++i) {
33+
for (int i = 0; i < thislen; i++) {
3334
const int item = sourceP[i];
34-
const int end = (i+1)*eachrep;
35-
for (int j=i*eachrep; j<end; ++j) targetP[j] = item; // no div, mod or read ops inside loop; just rep a const contiguous write
35+
const int end = (i + 1) * eachrep;
36+
for (int j = i * eachrep; j < end; j++) targetP[j] = item; // no div, mod or read ops inside loop; just rep a const contiguous write
3637
}
3738
#pragma omp parallel for num_threads(getDTthreads(ncopy*blocklen, true))
38-
for (int i=1; i<ncopy; ++i) {
39-
memcpy(targetP + i*blocklen, targetP, blocklen*sizeof(*targetP));
39+
for (int i = 1; i < ncopy; i++) {
40+
memcpy(targetP + i * blocklen, targetP, blocklen * sizeof(*targetP));
4041
}
4142
} break;
4243
case REALSXP: {
4344
const double *restrict sourceP = REAL(source);
4445
double *restrict targetP = REAL(target);
4546
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
46-
for (int i=0; i<thislen; ++i) {
47+
for (int i = 0; i < thislen; i++) {
4748
const double item = sourceP[i];
48-
const int end=(i+1)*eachrep;
49-
for (int j=i*eachrep; j<end; ++j) targetP[j] = item;
49+
const int end = (i + 1) * eachrep;
50+
for (int j = i * eachrep; j < end; j++) targetP[j] = item;
5051
}
5152
#pragma omp parallel for num_threads(getDTthreads(ncopy*blocklen, true))
52-
for (int i=1; i<ncopy; ++i) {
53-
memcpy(targetP + i*blocklen, targetP, blocklen*sizeof(double));
53+
for (int i = 1; i < ncopy; i++) {
54+
memcpy(targetP + i * blocklen, targetP, blocklen * sizeof(double));
5455
}
5556
} break;
5657
case CPLXSXP: {
5758
const Rcomplex *restrict sourceP = COMPLEX(source);
5859
Rcomplex *restrict targetP = COMPLEX(target);
5960
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
60-
for (int i=0; i<thislen; ++i) {
61+
for (int i = 0; i < thislen; i++) {
6162
const Rcomplex item = sourceP[i];
62-
const int end=(i+1)*eachrep;
63-
for (int j=i*eachrep; j<end; ++j) targetP[j] = item;
63+
const int end = (i + 1) * eachrep;
64+
for (int j = i * eachrep; j < end; j++) targetP[j] = item;
6465
}
6566
#pragma omp parallel for num_threads(getDTthreads(ncopy*blocklen, true))
66-
for (int i=1; i<ncopy; ++i) {
67-
memcpy(targetP + i*blocklen, targetP, blocklen*sizeof(Rcomplex));
67+
for (int i = 1; i < ncopy; i++) {
68+
memcpy(targetP + i * blocklen, targetP, blocklen * sizeof(Rcomplex));
6869
}
6970
} break;
7071
case STRSXP: {
7172
const SEXP *sourceP = STRING_PTR_RO(source);
7273
int start = 0;
73-
for (int i=0; i<ncopy; ++i) {
74-
for (int j=0; j<thislen; ++j) {
74+
for (int i = 0; i < ncopy; i++) {
75+
for (int j = 0; j < thislen; j++) {
7576
const SEXP item = sourceP[j];
76-
const int end = start+eachrep;
77-
for (int k=start; k<end; ++k) SET_STRING_ELT(target, k, item); // no div, mod, or read-API call to STRING_ELT
77+
const int end = start + eachrep;
78+
for (int k = start; k < end; k++) SET_STRING_ELT(target, k, item); // no div, mod, or read-API call to STRING_ELT
7879
start = end;
7980
}
8081
}
8182
} break;
8283
case VECSXP: {
8384
const SEXP *sourceP = SEXPPTR_RO(source);
8485
int start = 0;
85-
for (int i=0; i<ncopy; ++i) {
86-
for (int j=0; j<thislen; ++j) {
86+
for (int i = 0; i < ncopy; i++) {
87+
for (int j = 0; j < thislen; j++) {
8788
const SEXP item = sourceP[j];
88-
const int end = start+eachrep;
89-
for (int k=start; k<end; ++k) SET_VECTOR_ELT(target, k, item);
89+
const int end = start + eachrep;
90+
for (int k = start; k < end; k++) SET_VECTOR_ELT(target, k, item);
9091
start = end;
9192
}
9293
}

0 commit comments

Comments
 (0)