dtaidistance/lib/DTAIDistanceC/DTAIDistanceC/dd_dtw_openmp.c
/**
 Check the arguments passed to dtw_distances_* and prepare the array of indices to be used.
 The indices are created upfront to allow for easy parallelization.
 
 @param block Block to indicate which series to compare.
 @param nb_series Number of series
 @param cbs Column begin indices for a row series index
 @param rls Location start for row in distances array
 @param length Length of (compact) distances matrix
 @param settings : Settings for DTW
 
 @return 0 if all is ok, other number if not.
 */
Check the arguments passed to dtw_distances_* and prepare the array of indices to be used.
The indices are created upfront to allow for easy parallelization.
Check the arguments passed to dtw_distances_ * and prepare the array of indices to be used . The indices are created upfront to allow for easy parallelization .
int dtw_distances_prepare(DTWBlock *block, idx_t nb_series, idx_t **cbs, idx_t **rls, idx_t *length, DTWSettings *settings) {
    idx_t cb, rs, ir;
    *length = dtw_distances_length(block, nb_series);
    if (length == 0) {
        return 1;
    }
    if (block->re == 0) {
        block->re = nb_series;
    }
    if (block->ce == 0) {
        block->ce = nb_series;
    }
    if (block->re <= block->rb) {
        *length = 0;
        return 1;
    }
    if (block->ce <= block->cb) {
        *length = 0;
        return 1;
    }
    *cbs = (idx_t *)malloc(sizeof(idx_t) * (block->re - block->rb));
    if (!cbs) {
        printf("Error: dtw_distances_* - cannot allocate memory (cbs length = %zu)", block->re - block->rb);
        *length = 0;
        return 1;
    }
    *rls = (idx_t *)malloc(sizeof(idx_t) * (block->re - block->rb));
    if (!rls) {
        printf("Error: dtw_distances_* - cannot allocate memory (rls length = %zu)", block->re - block->rb);
        *length = 0;
        return 1;
    }
    ir = 0;
    rs = 0;
    assert(block->rb < block->re);
    for (idx_t r=block->rb; r<block->re; r++) {
        if (r + 1 > block->cb) {
            cb = r+1;
        } else {
            cb = block->cb;
        }
        (*cbs)[ir] = cb;
        (*rls)[ir] = rs;
        rs += block->ce - cb;
        ir += 1;
    }
    return 0;
}
int dtw_distances_prepare ( DTWBlock * block , idx_t nb_series , idx_t * * cbs , idx_t * * rls , idx_t * length , DTWSettings * settings ) { idx_t cb , rs , ir ; * length = dtw_distances_length ( block , nb_series ) ; if ( length == 0 ) { return 1 ; } if ( block -> re == 0 ) { block -> re = nb_series ; } if ( block -> ce == 0 ) { block -> ce = nb_series ; } if ( block -> re <= block -> rb ) { * length = 0 ; return 1 ; } if ( block -> ce <= block -> cb ) { * length = 0 ; return 1 ; } * cbs = ( idx_t * ) malloc ( sizeof ( idx_t ) * ( block -> re - block -> rb ) ) ; if ( ! cbs ) { printf ( " " , block -> re - block -> rb ) ; * length = 0 ; return 1 ; } * rls = ( idx_t * ) malloc ( sizeof ( idx_t ) * ( block -> re - block -> rb ) ) ; if ( ! rls ) { printf ( " " , block -> re - block -> rb ) ; * length = 0 ; return 1 ; } ir = 0 ; rs = 0 ; assert ( block -> rb < block -> re ) ; for ( idx_t r = block -> rb ; r < block -> re ; r ++ ) { if ( r + 1 > block -> cb ) { cb = r + 1 ; } else { cb = block -> cb ; } ( * cbs ) [ ir ] = cb ; ( * rls ) [ ir ] = rs ; rs += block -> ce - cb ; ir += 1 ; } return 0 ; }
Check the arguments passed to dtw_distances_* and prepare the array of indices to be used.
Check the arguments passed to dtw_distances_ * and prepare the array of indices to be used .
// Correct block