-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiarray_constructor_eye.c
More file actions
112 lines (102 loc) · 3.73 KB
/
Copy pathiarray_constructor_eye.c
File metadata and controls
112 lines (102 loc) · 3.73 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
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
/*
* 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 "iarray_private.h"
#include <libiarray/iarray.h>
typedef struct {
iarray_dtshape_t *dtshape;
} iarray_constructor_eye_params;
ina_rc_t iarray_constructor_eye_fn(iarray_constructor_array_info_t *array_info,
iarray_constructor_chunk_info_t *chunk_info,
iarray_constructor_block_info_t *block_info,
iarray_constructor_item_info_t *item_info,
void *custom_info,
void *custom_chunk_info,
void *custom_block_info,
uint8_t *item) {
INA_UNUSED(array_info);
INA_UNUSED(chunk_info);
INA_UNUSED(block_info);
INA_UNUSED(custom_info);
INA_UNUSED(custom_chunk_info);
INA_UNUSED(custom_block_info);
iarray_dtshape_t *dtshape = array_info->a->dtshape;
// Eye operation
double val = item_info->index[0] == item_info->index[1] ? 1. : 0.;
switch (dtshape->dtype) {
case IARRAY_DATA_TYPE_DOUBLE: {
double value = (double) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_FLOAT: {
float value = (float) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_INT64: {
int64_t value = (int64_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_INT32: {
int32_t value = (int32_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_INT16: {
int16_t value = (int16_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_INT8: {
int8_t value = (int8_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_UINT64: {
uint64_t value = (uint64_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_UINT32: {
uint32_t value = (uint32_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_UINT16: {
uint16_t value = (uint16_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
case IARRAY_DATA_TYPE_UINT8: {
uint8_t value = (uint8_t) val;
memcpy(item, &value, dtshape->dtype_size);
break;
}
default:
INA_TRACE1(iarray.error, "The data type is invalid");
return INA_ERROR(IARRAY_ERR_INVALID_DTYPE);
}
return INA_SUCCESS;
}
INA_API(ina_rc_t) iarray_eye(iarray_context_t *ctx,
iarray_dtshape_t *dtshape,
iarray_storage_t *storage,
iarray_container_t **container)
{
if (dtshape->ndim != 2) {
IARRAY_TRACE1(iarray.error, "The array dimension must be 2");
return INA_ERROR(INA_ERR_INVALID_ARGUMENT);
}
iarray_constructor_element_params_t elem_params = IARRAY_CONSTRUCTOR_ELEMENT_PARAMS_DEFAULT;
elem_params.item_fn = iarray_constructor_eye_fn;
return iarray_constructor_element(ctx, dtshape, &elem_params, storage, container);
}