static void crf1dt_delete(crf1dt_t* crf1dt) { /* Note: we don't own the model object (crf1t->model). */ if (crf1dt->ctx != NULL) { crf1dc_delete(crf1dt->ctx); crf1dt->ctx = NULL; } free(crf1dt); }
crf1d_context_t* crf1dc_new(int flag, int L, int T) { int ret = 0; crf1d_context_t* ctx = NULL; ctx = (crf1d_context_t*)calloc(1, sizeof(crf1d_context_t)); if (ctx != NULL) { ctx->flag = flag; ctx->num_labels = L; ctx->trans = (floatval_t*)calloc(L * L, sizeof(floatval_t)); if (ctx->trans == NULL) goto error_exit; if (ctx->flag & CTXF_MARGINALS) { ctx->exp_trans = (floatval_t*)_aligned_malloc((L * L + 4) * sizeof(floatval_t), 16); if (ctx->exp_trans == NULL) { goto error_exit; } ctx->mexp_trans = (floatval_t*)calloc(L * L, sizeof(floatval_t)); if (ctx->mexp_trans == NULL) { goto error_exit; } ctx->partial_mexp_trans = (floatval_t*)calloc(L * L, sizeof(floatval_t)); if (ctx->partial_mexp_trans == NULL) { goto error_exit; } } if (ret = crf1dc_set_num_items(ctx, T)) { goto error_exit; } /* T gives the 'hint' for maximum length of items. */ ctx->num_items = 0; } return ctx; error_exit: crf1dc_delete(ctx); return NULL; }