1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#![allow(warnings)]
//! Rust definition corresponding to metatensor-core C-API.
//!
//! This module is exported for advanced users of the metatensor crate, but
//! should not be needed by most.

#[cfg_attr(feature="static", link(name="metatensor", kind = "static", modifiers = "-whole-archive"))]
#[cfg_attr(all(not(feature="static"), not(target_os="windows")), link(name="metatensor", kind = "dylib"))]
#[cfg_attr(all(not(feature="static"), target_os="windows"), link(name="metatensor.dll", kind = "dylib"))]
extern "C" {}

pub const MTS_SUCCESS: i32 = 0;
pub const MTS_INVALID_PARAMETER_ERROR: i32 = 1;
pub const MTS_IO_ERROR: i32 = 2;
pub const MTS_SERIALIZATION_ERROR: i32 = 3;
pub const MTS_BUFFER_SIZE_ERROR: i32 = 254;
pub const MTS_INTERNAL_ERROR: i32 = 255;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mts_block_t {
    _unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mts_tensormap_t {
    _unused: [u8; 0],
}
pub type mts_status_t = i32;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mts_labels_t {
    pub internal_ptr_: *mut ::std::os::raw::c_void,
    pub names: *const *const ::std::os::raw::c_char,
    pub values: *const i32,
    pub size: usize,
    pub count: usize,
}
#[test]
fn bindgen_test_layout_mts_labels_t() {
    const UNINIT: ::std::mem::MaybeUninit<mts_labels_t> = ::std::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::std::mem::size_of::<mts_labels_t>(),
        40usize,
        concat!("Size of: ", stringify!(mts_labels_t))
    );
    assert_eq!(
        ::std::mem::align_of::<mts_labels_t>(),
        8usize,
        concat!("Alignment of ", stringify!(mts_labels_t))
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).internal_ptr_) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_labels_t),
            "::",
            stringify!(internal_ptr_)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).names) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_labels_t),
            "::",
            stringify!(names)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).values) as usize - ptr as usize },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_labels_t),
            "::",
            stringify!(values)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
        24usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_labels_t),
            "::",
            stringify!(size)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize },
        32usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_labels_t),
            "::",
            stringify!(count)
        )
    );
}
pub type mts_data_origin_t = u64;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mts_sample_mapping_t {
    pub input: usize,
    pub output: usize,
}
#[test]
fn bindgen_test_layout_mts_sample_mapping_t() {
    const UNINIT: ::std::mem::MaybeUninit<mts_sample_mapping_t> = ::std::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::std::mem::size_of::<mts_sample_mapping_t>(),
        16usize,
        concat!("Size of: ", stringify!(mts_sample_mapping_t))
    );
    assert_eq!(
        ::std::mem::align_of::<mts_sample_mapping_t>(),
        8usize,
        concat!("Alignment of ", stringify!(mts_sample_mapping_t))
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).input) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_sample_mapping_t),
            "::",
            stringify!(input)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).output) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_sample_mapping_t),
            "::",
            stringify!(output)
        )
    );
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct mts_array_t {
    pub ptr: *mut ::std::os::raw::c_void,
    pub origin: ::std::option::Option<
        unsafe extern "C" fn(
            array: *const ::std::os::raw::c_void,
            origin: *mut mts_data_origin_t,
        ) -> mts_status_t,
    >,
    pub data: ::std::option::Option<
        unsafe extern "C" fn(
            array: *mut ::std::os::raw::c_void,
            data: *mut *mut f64,
        ) -> mts_status_t,
    >,
    pub shape: ::std::option::Option<
        unsafe extern "C" fn(
            array: *const ::std::os::raw::c_void,
            shape: *mut *const usize,
            shape_count: *mut usize,
        ) -> mts_status_t,
    >,
    pub reshape: ::std::option::Option<
        unsafe extern "C" fn(
            array: *mut ::std::os::raw::c_void,
            shape: *const usize,
            shape_count: usize,
        ) -> mts_status_t,
    >,
    pub swap_axes: ::std::option::Option<
        unsafe extern "C" fn(
            array: *mut ::std::os::raw::c_void,
            axis_1: usize,
            axis_2: usize,
        ) -> mts_status_t,
    >,
    pub create: ::std::option::Option<
        unsafe extern "C" fn(
            array: *const ::std::os::raw::c_void,
            shape: *const usize,
            shape_count: usize,
            new_array: *mut mts_array_t,
        ) -> mts_status_t,
    >,
    pub copy: ::std::option::Option<
        unsafe extern "C" fn(
            array: *const ::std::os::raw::c_void,
            new_array: *mut mts_array_t,
        ) -> mts_status_t,
    >,
    pub destroy: ::std::option::Option<unsafe extern "C" fn(array: *mut ::std::os::raw::c_void)>,
    pub move_samples_from: ::std::option::Option<
        unsafe extern "C" fn(
            output: *mut ::std::os::raw::c_void,
            input: *const ::std::os::raw::c_void,
            samples: *const mts_sample_mapping_t,
            samples_count: usize,
            property_start: usize,
            property_end: usize,
        ) -> mts_status_t,
    >,
}
#[test]
fn bindgen_test_layout_mts_array_t() {
    const UNINIT: ::std::mem::MaybeUninit<mts_array_t> = ::std::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::std::mem::size_of::<mts_array_t>(),
        80usize,
        concat!("Size of: ", stringify!(mts_array_t))
    );
    assert_eq!(
        ::std::mem::align_of::<mts_array_t>(),
        8usize,
        concat!("Alignment of ", stringify!(mts_array_t))
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(ptr)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).origin) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(origin)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(data)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).shape) as usize - ptr as usize },
        24usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(shape)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).reshape) as usize - ptr as usize },
        32usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(reshape)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).swap_axes) as usize - ptr as usize },
        40usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(swap_axes)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).create) as usize - ptr as usize },
        48usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(create)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).copy) as usize - ptr as usize },
        56usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(copy)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).destroy) as usize - ptr as usize },
        64usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(destroy)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).move_samples_from) as usize - ptr as usize },
        72usize,
        concat!(
            "Offset of field: ",
            stringify!(mts_array_t),
            "::",
            stringify!(move_samples_from)
        )
    );
}
pub type mts_create_array_callback_t = ::std::option::Option<
    unsafe extern "C" fn(
        shape: *const usize,
        shape_count: usize,
        array: *mut mts_array_t,
    ) -> mts_status_t,
>;
extern "C" {
    pub fn mts_disable_panic_printing();
    pub fn mts_version() -> *const ::std::os::raw::c_char;
    pub fn mts_last_error() -> *const ::std::os::raw::c_char;
    #[must_use]
    pub fn mts_labels_position(
        labels: mts_labels_t,
        values: *const i32,
        values_count: usize,
        result: *mut i64,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_create(labels: *mut mts_labels_t) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_set_user_data(
        labels: mts_labels_t,
        user_data: *mut ::std::os::raw::c_void,
        user_data_delete: ::std::option::Option<
            unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void),
        >,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_user_data(
        labels: mts_labels_t,
        user_data: *mut *mut ::std::os::raw::c_void,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_clone(labels: mts_labels_t, clone: *mut mts_labels_t) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_union(
        first: mts_labels_t,
        second: mts_labels_t,
        result: *mut mts_labels_t,
        first_mapping: *mut i64,
        first_mapping_count: usize,
        second_mapping: *mut i64,
        second_mapping_count: usize,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_intersection(
        first: mts_labels_t,
        second: mts_labels_t,
        result: *mut mts_labels_t,
        first_mapping: *mut i64,
        first_mapping_count: usize,
        second_mapping: *mut i64,
        second_mapping_count: usize,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_labels_free(labels: *mut mts_labels_t) -> mts_status_t;
    #[must_use]
    pub fn mts_register_data_origin(
        name: *const ::std::os::raw::c_char,
        origin: *mut mts_data_origin_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_get_data_origin(
        origin: mts_data_origin_t,
        buffer: *mut ::std::os::raw::c_char,
        buffer_size: usize,
    ) -> mts_status_t;
    pub fn mts_block(
        data: mts_array_t,
        samples: mts_labels_t,
        components: *const mts_labels_t,
        components_count: usize,
        properties: mts_labels_t,
    ) -> *mut mts_block_t;
    #[must_use]
    pub fn mts_block_free(block: *mut mts_block_t) -> mts_status_t;
    pub fn mts_block_copy(block: *const mts_block_t) -> *mut mts_block_t;
    #[must_use]
    pub fn mts_block_labels(
        block: *const mts_block_t,
        axis: usize,
        labels: *mut mts_labels_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_block_gradient(
        block: *mut mts_block_t,
        parameter: *const ::std::os::raw::c_char,
        gradient: *mut *mut mts_block_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_block_data(block: *mut mts_block_t, data: *mut mts_array_t) -> mts_status_t;
    #[must_use]
    pub fn mts_block_add_gradient(
        block: *mut mts_block_t,
        parameter: *const ::std::os::raw::c_char,
        gradient: *mut mts_block_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_block_gradients_list(
        block: *const mts_block_t,
        parameters: *mut *const *const ::std::os::raw::c_char,
        parameters_count: *mut usize,
    ) -> mts_status_t;
    pub fn mts_tensormap(
        keys: mts_labels_t,
        blocks: *mut *mut mts_block_t,
        blocks_count: usize,
    ) -> *mut mts_tensormap_t;
    #[must_use]
    pub fn mts_tensormap_free(tensor: *mut mts_tensormap_t) -> mts_status_t;
    pub fn mts_tensormap_copy(tensor: *const mts_tensormap_t) -> *mut mts_tensormap_t;
    #[must_use]
    pub fn mts_tensormap_keys(
        tensor: *const mts_tensormap_t,
        keys: *mut mts_labels_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_tensormap_block_by_id(
        tensor: *mut mts_tensormap_t,
        block: *mut *mut mts_block_t,
        index: usize,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_tensormap_blocks_matching(
        tensor: *const mts_tensormap_t,
        block_indexes: *mut usize,
        count: *mut usize,
        selection: mts_labels_t,
    ) -> mts_status_t;
    pub fn mts_tensormap_keys_to_properties(
        tensor: *const mts_tensormap_t,
        keys_to_move: mts_labels_t,
        sort_samples: bool,
    ) -> *mut mts_tensormap_t;
    pub fn mts_tensormap_components_to_properties(
        tensor: *mut mts_tensormap_t,
        dimensions: *const *const ::std::os::raw::c_char,
        dimensions_count: usize,
    ) -> *mut mts_tensormap_t;
    pub fn mts_tensormap_keys_to_samples(
        tensor: *const mts_tensormap_t,
        keys_to_move: mts_labels_t,
        sort_samples: bool,
    ) -> *mut mts_tensormap_t;
    pub fn mts_tensormap_load(
        path: *const ::std::os::raw::c_char,
        create_array: mts_create_array_callback_t,
    ) -> *mut mts_tensormap_t;
    pub fn mts_tensormap_load_buffer(
        buffer: *const u8,
        buffer_count: usize,
        create_array: mts_create_array_callback_t,
    ) -> *mut mts_tensormap_t;
    #[must_use]
    pub fn mts_tensormap_save(
        path: *const ::std::os::raw::c_char,
        tensor: *const mts_tensormap_t,
    ) -> mts_status_t;
    #[must_use]
    pub fn mts_tensormap_save_buffer(
        buffer: *mut *mut u8,
        buffer_count: *mut usize,
        realloc_user_data: *mut ::std::os::raw::c_void,
        realloc: ::std::option::Option<
            unsafe extern "C" fn(
                user_data: *mut ::std::os::raw::c_void,
                ptr: *mut u8,
                new_size: usize,
            ) -> *mut u8,
        >,
        tensor: *const mts_tensormap_t,
    ) -> mts_status_t;
}