-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_save_open.c
More file actions
69 lines (53 loc) · 1.8 KB
/
Copy pathexample_save_open.c
File metadata and controls
69 lines (53 loc) · 1.8 KB
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
/*
* Copyright ironArray SL 2021.
*
* All rights reserved.
*
* This software is the confidential and proprietary information of ironArray SL
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license agreement.
*
*/
#include <libiarray/iarray.h>
#include "iarray_private.h"
int main(void) {
iarray_init();
iarray_context_t *ctx;
iarray_config_t cfg = IARRAY_CONFIG_DEFAULTS;
iarray_context_new(&cfg, &ctx);
int64_t shape[] = {123};
int8_t ndim = 1;
iarray_dtshape_t dtshape;
dtshape.dtype = IARRAY_DATA_TYPE_DOUBLE;
int8_t itemsize = sizeof(double);
dtshape.ndim = ndim;
int64_t nelem = 1;
for (int i = 0; i < ndim; ++i) {
dtshape.shape[i] = shape[i];
nelem *= shape[i];
}
int32_t xchunkshape[] = {49};
int32_t xblockshape[] = {20};
iarray_storage_t xstorage;
xstorage.contiguous = false;
xstorage.urlpath = NULL;
for (int i = 0; i < ndim; ++i) {
xstorage.chunkshape[i] = xchunkshape[i];
xstorage.blockshape[i] = xblockshape[i];
}
iarray_container_t *x;
IARRAY_RETURN_IF_FAILED(iarray_linspace(ctx, &dtshape, -10, 10, &xstorage, &x));
iarray_container_remove("example_copy.iarr");
IARRAY_RETURN_IF_FAILED(iarray_container_save(ctx, x, "example_copy.iarr"));
iarray_container_free(ctx, &x);
IARRAY_RETURN_IF_FAILED(iarray_container_open(ctx, "example_copy.iarr", &x));
int64_t buflen = nelem * itemsize;
uint8_t *buf = malloc(buflen);
printf("TO buffer\n");
IARRAY_RETURN_IF_FAILED(iarray_to_buffer(ctx, x, buf, buflen));
free(buf);
iarray_container_free(ctx, &x);
iarray_context_free(&ctx);
iarray_container_remove("example_copy.iarr");
return 0;
}