Skip to content

Commit

Permalink
Add method that can query missing keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Jul 22, 2024
1 parent 7b58fae commit 410d77e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/nnc/ccv_cnnp_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,25 @@ ccv_array_t* ccv_cnnp_model_parameters_filter(ccv_cnnp_model_t* const model, ccv

}

CCV_WARN_UNUSED(ccv_cnnp_model_io_t) ccv_cnnp_model_parameter_first_uninit(ccv_cnnp_model_t* const model)
{
ccv_cnnp_compiled_data_t* const compiled_data = model->compiled_data;
assert(compiled_data);
const int tensors_init = !!compiled_data->tensors_init.v;
if (!tensors_init) // If nothing initialized, we return parameter 0.
return ccv_cnnp_model_parameters(model, -1, 0);
const int parameter_size = compiled_data->parameters->rnum;
int i;
const uint32_t* const init_v = CCV_NNC_INIT_V(compiled_data->tensors_init.v);
for (i = 0; i < parameter_size; i++)
{
const int d = ((ccv_nnc_tensor_symbol_t*)ccv_array_get(compiled_data->parameters, i))->d;
if (!(init_v[d >> 5] & (1u << (d & 0x1f))))
return ccv_cnnp_model_parameters(model, -1, i);
}
return 0;
}

static ccv_array_t* _ccv_cnnp_model_parameter_indices(const ccv_cnnp_model_t* const model, const ccv_cnnp_model_io_t parameters, int* const param_ref)
{
const int to_param_sel = parameters->param_sel > 0 ? parameters->param_sel - 1 : parameters->param_sel;
Expand Down
6 changes: 6 additions & 0 deletions lib/nnc/ccv_nnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3997,6 +3997,12 @@ CCV_WARN_UNUSED(ccv_array_t*) ccv_cnnp_model_parameters_filter(ccv_cnnp_model_t*
* @return a ccv_cnnp_model_io_t or 0 if not found.
*/
CCV_WARN_UNUSED(ccv_cnnp_model_io_t) ccv_cnnp_model_parameter_first(ccv_cnnp_model_t* const model, ccv_cnnp_model_parameters_filter_f first, void* const context);
/**
* Loop over a compiled model to find a parameter that is not initialized.
* @param model A model that is compiled.
* @return a ccv_cnnp_model_io_t or 0 if not found.
*/
CCV_WARN_UNUSED(ccv_cnnp_model_io_t) ccv_cnnp_model_parameter_first_uninit(ccv_cnnp_model_t* const model);
/**
* Set parameters from another model. This will override whatever values in these parameters. The
* given parameters from another model should match the dimension of the parameter. It doesn't matter
Expand Down

0 comments on commit 410d77e

Please sign in to comment.