Changeset: 1879fa9fbb2d for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1879fa9fbb2d Modified Files: .hgtags gdk/gdk_arrays.c monetdb5/modules/kernel/arrays.c Branch: arrays Log Message:
projectCells just returns the vals BAT ignoring the dims diffs (276 lines): diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -606,3 +606,6 @@ 30be7bd4aec0b5daf3d2f3a26a1043c04b88bb6d c7c0a76e663e34bcddae683b385c8e5a919ffd84 Jul2015_5 30be7bd4aec0b5daf3d2f3a26a1043c04b88bb6d Jul2015_release c7c0a76e663e34bcddae683b385c8e5a919ffd84 Jul2015_release +10617155ecf728f6c7f2dbb245230271ae43687b initial +28f78514163fa9e6d40f7d57d9efd7e197bb069d columnMajor +a7542dacabd591aed585c582ca394169ef052d9a reuseDimValues diff --git a/gdk/gdk_arrays.c b/gdk/gdk_arrays.c --- a/gdk/gdk_arrays.c +++ b/gdk/gdk_arrays.c @@ -251,31 +251,39 @@ BAT *projectCells(gdk_array* dimCands, g * as needed to fill the resOIDs */ dim = dimCands->dims[0]; if(dim->idxs) { - for(j=0; j<resSize;) - for(i=0; i<dim->elsNum ; i++, j++) - resOIDs[j] = dim->idxs[i]; +// for(j=0; j<resSize;) + /*add each element one */ + for(i=0; i<dim->elsNum ; i++, j++) + resOIDs[j] = dim->idxs[i]; } else { - for(j=0; j<resSize;) - for(i=dim->min; i<=dim->max ; i+=dim->step, j++) - resOIDs[j] = i; +// for(j=0; j<resSize;) + /* add each element once */ + for(i=dim->min; i<=dim->max ; i+=dim->step, j++) + resOIDs[j] = i; } /* iterate over the rest of the dimensoins and add the values needed to make the correct oids */ for(i=1; i<dimCands->dimsNum; i++) { dim = dimCands->dims[i]; jumpSize *= array->dims[i-1]->elsNum; //each oid is increased by jumpSize * the idx of the dimension - elsR *= dimCands->dims[i-1]->elsNum; //each element is repeated elsR times + elsR *= dimCands->dims[i-1]->elsNum; //each element is repeated elsR times, this equals the number of elements that have been aready in the array if(dim->idxs) { - for(j=0; j<resSize; ) //until all elements have been set, repeat the groups - for(k=0; k<dim->elsNum; k++) //each qualifying idx - for(elsRi=0; elsRi<elsR; elsRi++, j++) //repeat it jumpSize times - resOIDs[j] += jumpSize*dim->idxs[k]; +// for(j=0; j<resSize; ) //until all elements have been set, repeat the groups + for(k=1; k<dim->elsNum; k++) //skip the first qualifying idx to avoid updating cells which need to be re-used + for(elsRi=0; elsRi<elsR; elsRi++, j++) //repeat it elsR times + resOIDs[j] = resOIDs[elsRi] + jumpSize*dim->idxs[k]; + /* now update the first elsR values */ + for(elsRi=0; elsRi<elsR; elsRi++) + resOIDs[elsRi] += jumpSize*dim->idxs[0]; + } else { - for(j=0; j<resSize; ) //until all elements have been set, repeat the groups - for(k=dim->min; k<=dim->max; k+=dim->step) //each qualifying idx - for(elsRi=0; elsRi<elsR; elsRi++, j++) //repeat it jumpSize times - resOIDs[j] += jumpSize*k; - +// for(j=0; j<resSize; ) //until all elements have been set, repeat the groups + for(k=dim->min+dim->step; k<=dim->max; k+=dim->step) //skip the first value to avoid updating cells which need to be re-used + for(elsRi=0; elsRi<elsR; elsRi++, j++) //repeat it jumpSize times + resOIDs[j] = resOIDs[elsRi]+jumpSize*k; + /* update the first elsR elements */ + for(elsRi=0; elsRi<elsR; elsRi++, j++) //repeat it jumpSize times + resOIDs[elsRi] += jumpSize*dim->min; } } diff --git a/monetdb5/modules/kernel/arrays.c b/monetdb5/modules/kernel/arrays.c --- a/monetdb5/modules/kernel/arrays.c +++ b/monetdb5/modules/kernel/arrays.c @@ -423,9 +423,51 @@ do { \ case TYPE_sht: computeValues(sht); break; - case TYPE_int: - computeValues(int); - break; + case TYPE_int: { + int min = *(int*)dimension->min; + int step = *(int*)dimension->step; + int *vals; + unsigned int i=0, elsRi=0, grpRi = 0, idx =0, initialisedIdx=0; + + if(!(resBAT = BATnew(TYPE_void, TYPE_int, resSize, TRANSIENT))) + throw(MAL, "algebra.leftfetchjoin", "Problem allocating new BAT"); + vals = (int*)Tloc(resBAT, BUNfirst(resBAT)); + + if(dimCand->idxs) { + /* iterate over the idxs and use each one as many times as defined by elsR */ + /* repeat the procedure as many times as defined my grpR */ + for(grpRi=0; grpRi<grpR; grpRi++) { + for(i=0; i<dimCand->elsNum; i++) { + int val = min + dimCand->idxs[i]*step; //the value at this position + for(elsRi=0; elsRi<elsR; elsRi++) { + *vals++ = val; + } + } + } + } else { + /* get the elements in the range and use each one as many times as defined by elsR */ + /* repeat the procedure as many times as defined my grpR */ + + /*create the elements for the first group*/ + for(i=dimCand->min; i<=dimCand->max; i+=dimCand->step) { + int val = min + i*step; + for(elsRi=0; elsRi<elsR; elsRi++, idx++) { + vals[idx] = val; + } + } + /* repeat te elements created during the first group to fill the rests of the groups + * (same elemnts no need to re-compute them */ + for(grpRi=1; grpRi<grpR; grpRi++) { + initialisedIdx =0; //for each group we repeat the same values + for(i=dimCand->min; i<=dimCand->max; i+=dimCand->step) { + for(elsRi=0; elsRi<elsR; elsRi++, idx++, initialisedIdx++) { + vals[idx] = vals[initialisedIdx]; + } + } + } + } + //computeValues(int); + } break; case TYPE_wrd: computeValues(wrd); break; @@ -962,80 +1004,73 @@ str ALGprojectNonDimension(bat *result, str ALGnonDimensionQRDecomposition(bat *oidsRes, ptr *dimsRes, const bat* vals, const ptr *dims) { gdk_array *array = (gdk_array*)*dims; - gdk_array *aCopy = NULL; - BAT *b; + gdk_array *array_out = arrayCopy(array); //TODO: Remove this. No need to return array + double *qarray, *rarray, *els; + unsigned int rowsNum, colsNum, rowNum, colNum, cellsNum; + + BAT *b; dbl *elements = NULL, *new_elements = NULL; - unsigned int maxX, maxY; - unsigned int sizeX, sizeY; - BUN j; - dbl *qarray = NULL, *rarray = NULL; - BUN i, k; - dbl s = 0; + rowsNum = array->dims[0]->elsNum; + colsNum = array->dims[1]->elsNum; + cellsNum = rowsNum*colsNum; - // we do not change array structure, all dimensions must be the same - aCopy = arrayCopy(array); - maxX = array->dims[0]->max; - sizeX = maxX + 1; + qarray = (dbl*)GDKmalloc(rowsNum*colsNum*sizeof(double)); + rarray = (dbl*)GDKmalloc(colsNum*colsNum*sizeof(double)); + els = (dbl*)GDKmalloc(rowsNum*colsNum*sizeof(double)); - maxY = array->dims[1]->max; - sizeY = maxY + 1; + /* copy the elements in column major to fit the access pattern */ + elements = (dbl*) Tloc(BATdescriptor(*vals), BUNfirst(BATdescriptor(*vals))); + for(rowNum=0; rowNum<rowsNum; rowNum++) { + unsigned int skip = rowNum*colsNum; + for(colNum=0; colNum<colsNum; colNum++) + *(els+colNum*rowsNum+rowNum) = elements[colNum+skip]; + } + + /* For each column */ + for(colNum =0 ; colNum<colsNum; colNum++) { + double s=0.0; + unsigned int colNum_tmp; - *dimsRes = aCopy; + unsigned int skip = colNum*rowsNum; + unsigned int rSkip = colNum*colNum; - if((b = BATnew(TYPE_void, TYPE_dbl, sizeX*sizeY, TRANSIENT)) == NULL) - return NULL; + /*get all rows*/ + for(rowNum=0; rowNum<rowsNum; rowNum++) + s+=(*(els+skip+rowNum))*(*(els+skip+rowNum)); - elements = (dbl*) Tloc(BATdescriptor(*vals), BUNfirst(BATdescriptor(*vals))); - new_elements = (dbl*) Tloc(b, BUNfirst(b)); + *(rarray+rSkip+colNum) = sqrt(s); - qarray = (double*)malloc(sizeX*sizeY*sizeof(double)); - rarray = (double*)malloc(sizeY*sizeY*sizeof(double)); + /* get all rows */ + for(rowNum=0; rowNum<rowsNum; rowNum++) + *(qarray+skip+rowNum) = (*(els+skip+rowNum))/(*(rarray+rSkip+colNum)); + for(colNum_tmp=colNum+1; colNum_tmp<colsNum; colNum_tmp++) { + unsigned int skip_tmp = colNum_tmp*rowsNum; + s = 0.0; - // resulting bat calculation + for(rowNum=0; rowNum<rowsNum; rowNum++) + s+=(*(els+skip_tmp+rowNum))*(*(qarray+skip+rowNum)); - for (j = 0; j < sizeX*sizeY; j++) - { - new_elements[j] = elements[j]; - } + *(rarray+rSkip+colNum_tmp) = s; - for (k = 0; k <= maxY; k++) - { + for(rowNum=0; rowNum<rowsNum; rowNum++) + *(els+skip_tmp+rowNum) -= s*(*(qarray+skip+rowNum)); + } + } - s = 0; - for (j = 0; j <= maxX; j++) - { - s = s + new_elements[j + k * sizeX] * new_elements[j + k * sizeX]; - } - rarray[k + k * sizeY] = sqrt(s); - for (j = 0; j <= maxX; j++) - { - qarray[j + k * sizeX] = new_elements[j + k * sizeX]/rarray[k + k * sizeY]; + if((b = BATnew(TYPE_void, TYPE_dbl, cellsNum, TRANSIENT)) == NULL) + return createException(MAL, "arrays.QQR", "Problem creating BAT"); + new_elements = (dbl*) Tloc(b, BUNfirst(b)); - } - for (i = k + 1; i <= maxY; i++) - { - s = 0; - for (j = 0; j <= maxX; j++) - { - s = s + new_elements[j + i * sizeX] * qarray[j + k * sizeX]; - } - rarray[k + i * sizeY] = s; - for (j = 0; j <= maxX; j++) - { - new_elements[j + i * sizeX] = new_elements[j + i * sizeX] - rarray[k + i * sizeY] * qarray[j + k * sizeX]; - } - } - } - for (j = 0; j < sizeX*sizeY; j++) - { - new_elements[j] = qarray[j]; - } + for(rowNum=0; rowNum<rowsNum; rowNum++) { + for(colNum=0; colNum<colsNum; colNum++) { + new_elements[rowNum+colNum*rowsNum] = *(qarray+colNum*rowsNum+rowNum); + } + } - - BATsetcount(b, sizeX*sizeY); + BATsetcount(b, cellsNum); b->tsorted = 0; b->trevsorted = b->batCount <= 1; b->tkey = 1; @@ -1048,12 +1083,13 @@ str ALGnonDimensionQRDecomposition(bat * b->hkey = 1; b->hrevsorted = b->batCount <= 1; - free(rarray); - free(qarray); - + GDKfree(rarray); + GDKfree(qarray); + GDKfree(els); BBPkeepref(*oidsRes = b->batCacheid); + *dimsRes = array_out; return MAL_SUCCEED; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list