@@ -20211,78 +20211,94 @@ int gguf_find_key(const struct gguf_context * ctx, const char * key) {
20211
20211
return keyfound;
20212
20212
}
20213
20213
20214
- const char * gguf_get_key(const struct gguf_context * ctx, int i ) {
20215
- return ctx->kv[i ].key.data;
20214
+ const char * gguf_get_key(const struct gguf_context * ctx, int key_id ) {
20215
+ return ctx->kv[key_id ].key.data;
20216
20216
}
20217
20217
20218
- enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int i ) {
20219
- return ctx->kv[i ].type;
20218
+ enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int key_id ) {
20219
+ return ctx->kv[key_id ].type;
20220
20220
}
20221
20221
20222
- enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i) {
20223
- return ctx->kv[i].value.arr.type;
20222
+ enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int key_id) {
20223
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
20224
+ return ctx->kv[key_id].value.arr.type;
20224
20225
}
20225
20226
20226
- const void * gguf_get_arr_data(const struct gguf_context * ctx, int i) {
20227
- return ctx->kv[i].value.arr.data;
20227
+ const void * gguf_get_arr_data(const struct gguf_context * ctx, int key_id) {
20228
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
20229
+ return ctx->kv[key_id].value.arr.data;
20228
20230
}
20229
20231
20230
20232
const char * gguf_get_arr_str(const struct gguf_context * ctx, int key_id, int i) {
20233
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
20231
20234
struct gguf_kv * kv = &ctx->kv[key_id];
20232
20235
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
20233
20236
return str->data;
20234
20237
}
20235
20238
20236
- int gguf_get_arr_n(const struct gguf_context * ctx, int i) {
20237
- return ctx->kv[i].value.arr.n;
20239
+ int gguf_get_arr_n(const struct gguf_context * ctx, int key_id) {
20240
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_ARRAY);
20241
+ return ctx->kv[key_id].value.arr.n;
20238
20242
}
20239
20243
20240
- uint8_t gguf_get_val_u8(const struct gguf_context * ctx, int i) {
20241
- return ctx->kv[i].value.uint8;
20244
+ uint8_t gguf_get_val_u8(const struct gguf_context * ctx, int key_id) {
20245
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_UINT8);
20246
+ return ctx->kv[key_id].value.uint8;
20242
20247
}
20243
20248
20244
- int8_t gguf_get_val_i8(const struct gguf_context * ctx, int i) {
20245
- return ctx->kv[i].value.int8;
20249
+ int8_t gguf_get_val_i8(const struct gguf_context * ctx, int key_id) {
20250
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_INT8);
20251
+ return ctx->kv[key_id].value.int8;
20246
20252
}
20247
20253
20248
- uint16_t gguf_get_val_u16(const struct gguf_context * ctx, int i) {
20249
- return ctx->kv[i].value.uint16;
20254
+ uint16_t gguf_get_val_u16(const struct gguf_context * ctx, int key_id) {
20255
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_UINT16);
20256
+ return ctx->kv[key_id].value.uint16;
20250
20257
}
20251
20258
20252
- int16_t gguf_get_val_i16(const struct gguf_context * ctx, int i) {
20253
- return ctx->kv[i].value.int16;
20259
+ int16_t gguf_get_val_i16(const struct gguf_context * ctx, int key_id) {
20260
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_INT16);
20261
+ return ctx->kv[key_id].value.int16;
20254
20262
}
20255
20263
20256
- uint32_t gguf_get_val_u32(const struct gguf_context * ctx, int i) {
20257
- return ctx->kv[i].value.uint32;
20264
+ uint32_t gguf_get_val_u32(const struct gguf_context * ctx, int key_id) {
20265
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_UINT32);
20266
+ return ctx->kv[key_id].value.uint32;
20258
20267
}
20259
20268
20260
- int32_t gguf_get_val_i32(const struct gguf_context * ctx, int i) {
20261
- return ctx->kv[i].value.int32;
20269
+ int32_t gguf_get_val_i32(const struct gguf_context * ctx, int key_id) {
20270
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_INT32);
20271
+ return ctx->kv[key_id].value.int32;
20262
20272
}
20263
20273
20264
- float gguf_get_val_f32(const struct gguf_context * ctx, int i) {
20265
- return ctx->kv[i].value.float32;
20274
+ float gguf_get_val_f32(const struct gguf_context * ctx, int key_id) {
20275
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_FLOAT32);
20276
+ return ctx->kv[key_id].value.float32;
20266
20277
}
20267
20278
20268
- uint64_t gguf_get_val_u64(const struct gguf_context * ctx, int i) {
20269
- return ctx->kv[i].value.uint64;
20279
+ uint64_t gguf_get_val_u64(const struct gguf_context * ctx, int key_id) {
20280
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_UINT64);
20281
+ return ctx->kv[key_id].value.uint64;
20270
20282
}
20271
20283
20272
- int64_t gguf_get_val_i64(const struct gguf_context * ctx, int i) {
20273
- return ctx->kv[i].value.int64;
20284
+ int64_t gguf_get_val_i64(const struct gguf_context * ctx, int key_id) {
20285
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_INT64);
20286
+ return ctx->kv[key_id].value.int64;
20274
20287
}
20275
20288
20276
- double gguf_get_val_f64(const struct gguf_context * ctx, int i) {
20277
- return ctx->kv[i].value.float64;
20289
+ double gguf_get_val_f64(const struct gguf_context * ctx, int key_id) {
20290
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_FLOAT64);
20291
+ return ctx->kv[key_id].value.float64;
20278
20292
}
20279
20293
20280
- bool gguf_get_val_bool(const struct gguf_context * ctx, int i) {
20281
- return ctx->kv[i].value.bool_;
20294
+ bool gguf_get_val_bool(const struct gguf_context * ctx, int key_id) {
20295
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_BOOL);
20296
+ return ctx->kv[key_id].value.bool_;
20282
20297
}
20283
20298
20284
- const char * gguf_get_val_str (const struct gguf_context * ctx, int i) {
20285
- return ctx->kv[i].value.str.data;
20299
+ const char * gguf_get_val_str(const struct gguf_context * ctx, int key_id) {
20300
+ GGML_ASSERT(ctx->kv[key_id].type == GGUF_TYPE_STRING);
20301
+ return ctx->kv[key_id].value.str.data;
20286
20302
}
20287
20303
20288
20304
int gguf_get_n_tensors(const struct gguf_context * ctx) {
0 commit comments