| 934 | } |
| 935 | |
| 936 | static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other) { |
| 937 | bool ok = true; |
| 938 | |
| 939 | const int n_kv = gguf_get_n_kv(ctx); |
| 940 | for (int id = 0; id < n_kv; ++id) { |
| 941 | const char * name = gguf_get_key(ctx, id); |
| 942 | |
| 943 | const int idx_other = gguf_find_key(other, name); |
| 944 | if (idx_other < 0) { |
| 945 | ok = false; |
| 946 | continue; |
| 947 | } |
| 948 | |
| 949 | const gguf_type type = gguf_get_kv_type(ctx, id); |
| 950 | if (type != gguf_get_kv_type(other, idx_other)) { |
| 951 | ok = false; |
| 952 | continue; |
| 953 | } |
| 954 | |
| 955 | if (type == GGUF_TYPE_ARRAY) { |
| 956 | const size_t arr_n = gguf_get_arr_n(ctx, id); |
| 957 | if (arr_n != gguf_get_arr_n(other, idx_other)) { |
| 958 | ok = false; |
| 959 | continue; |
| 960 | } |
| 961 | |
| 962 | const gguf_type type_arr = gguf_get_arr_type(ctx, id); |
| 963 | if (type_arr != gguf_get_arr_type(other, idx_other)) { |
| 964 | ok = false; |
| 965 | continue; |
| 966 | } |
| 967 | |
| 968 | if (type_arr == GGUF_TYPE_BOOL) { |
| 969 | const int8_t * data = reinterpret_cast<const int8_t *>(gguf_get_arr_data(ctx, id)); |
| 970 | const int8_t * data_other = reinterpret_cast<const int8_t *>(gguf_get_arr_data(other, idx_other)); |
| 971 | for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) { |
| 972 | if (bool(data[arr_i]) != bool(data_other[arr_i])) { |
| 973 | ok = false; |
| 974 | } |
| 975 | } |
| 976 | continue; |
| 977 | } |
| 978 | |
| 979 | if (type_arr == GGUF_TYPE_STRING) { |
| 980 | for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) { |
| 981 | const std::string str = gguf_get_arr_str(ctx, id, arr_i); |
| 982 | const std::string str_other = gguf_get_arr_str(other, idx_other, arr_i); |
| 983 | if (str != str_other) { |
| 984 | ok = false; |
| 985 | } |
| 986 | } |
| 987 | continue; |
| 988 | } |
| 989 | |
| 990 | const int8_t * data = reinterpret_cast<const int8_t *>(gguf_get_arr_data(ctx, id)); |
| 991 | const int8_t * data_other = reinterpret_cast<const int8_t *>(gguf_get_arr_data(other, idx_other)); |
| 992 | if (!std::equal(data, data + arr_n*gguf_type_size(type_arr), data_other)) { |
| 993 | ok = false; |
no test coverage detected