|
18 | 18 |
|
19 | 19 | #include <stdlib.h>
|
20 | 20 | #include <stdint.h>
|
21 |
| -#include "stdlib/ndarray/dtypes.h" |
22 | 21 | #include "stdlib/ndarray/ctor.h"
|
23 | 22 |
|
24 |
| -/** |
25 |
| -* Sets an ndarray data element specified by a byte array pointer. |
26 |
| -* |
27 |
| -* ## Notes |
28 |
| -* |
29 |
| -* - The function does **not** perform bounds checking, and, thus, the function does **not** prevent you from overwriting **unowned** memory. Accordingly, the function **assumes** you know what you are doing. |
30 |
| -* - The function returns `-1` if unable to set an element and `0` otherwise. |
31 |
| -* - The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. |
32 |
| -* |
33 |
| -* @param arr input ndarray |
34 |
| -* @param idx byte array pointer to an ndarray data element |
35 |
| -* @param v value to set |
36 |
| -* @return status code |
37 |
| -*/ |
38 |
| -int8_t stdlib_ndarray_set_ptr_value( const struct ndarray *arr, uint8_t *idx, const void *v ) { |
39 |
| - switch ( arr->dtype ) { |
40 |
| - case STDLIB_NDARRAY_FLOAT64: |
41 |
| - *(double *)idx = *(double *)v; |
42 |
| - return 0; |
43 |
| - case STDLIB_NDARRAY_FLOAT32: |
44 |
| - *(float *)idx = *(float *)v; |
45 |
| - return 0; |
46 |
| - case STDLIB_NDARRAY_UINT64: |
47 |
| - *(uint64_t *)idx = *(uint64_t *)v; |
48 |
| - return 0; |
49 |
| - case STDLIB_NDARRAY_INT64: |
50 |
| - *(int64_t *)idx = *(int64_t *)v; |
51 |
| - return 0; |
52 |
| - case STDLIB_NDARRAY_UINT32: |
53 |
| - *(uint32_t *)idx = *(uint32_t *)v; |
54 |
| - return 0; |
55 |
| - case STDLIB_NDARRAY_INT32: |
56 |
| - *(int32_t *)idx = *(int32_t *)v; |
57 |
| - return 0; |
58 |
| - case STDLIB_NDARRAY_UINT16: |
59 |
| - *(uint16_t *)idx = *(uint16_t *)v; |
60 |
| - return 0; |
61 |
| - case STDLIB_NDARRAY_INT16: |
62 |
| - *(int16_t *)idx = *(int16_t *)v; |
63 |
| - return 0; |
64 |
| - case STDLIB_NDARRAY_UINT8: |
65 |
| - *(uint8_t *)idx = *(uint8_t *)v; |
66 |
| - return 0; |
67 |
| - case STDLIB_NDARRAY_INT8: |
68 |
| - *(int8_t *)idx = *(int8_t *)v; |
69 |
| - return 0; |
70 |
| - } |
71 |
| - return -1; |
72 |
| -} |
73 |
| - |
74 |
| -/** |
75 |
| -* Sets a double-precision floating-point ndarray data element specified by a byte array pointer. |
76 |
| -* |
77 |
| -* ## Notes |
78 |
| -* |
79 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
80 |
| -* - The function always returns `0`. |
81 |
| -* |
82 |
| -* @param idx byte array pointer to an ndarray data element |
83 |
| -* @param v value to set |
84 |
| -* @return status code |
85 |
| -*/ |
86 |
| -int8_t stdlib_ndarray_set_ptr_float64( uint8_t *idx, const double v ) { |
87 |
| - *(double *)idx = v; |
88 |
| - return 0; |
89 |
| -} |
90 |
| - |
91 |
| -/** |
92 |
| -* Sets a single-precision floating-point ndarray data element specified by a byte array pointer. |
93 |
| -* |
94 |
| -* ## Notes |
95 |
| -* |
96 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
97 |
| -* - The function always returns `0`. |
98 |
| -* |
99 |
| -* @param idx byte array pointer to an ndarray data element |
100 |
| -* @param v value to set |
101 |
| -* @return status code |
102 |
| -*/ |
103 |
| -int8_t stdlib_ndarray_set_ptr_float32( uint8_t *idx, const float v ) { |
104 |
| - *(float *)idx = v; |
105 |
| - return 0; |
106 |
| -} |
107 |
| - |
108 |
| -/** |
109 |
| -* Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer. |
110 |
| -* |
111 |
| -* ## Notes |
112 |
| -* |
113 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
114 |
| -* - The function always returns `0`. |
115 |
| -* |
116 |
| -* @param idx byte array pointer to an ndarray data element |
117 |
| -* @param v value to set |
118 |
| -* @return status code |
119 |
| -*/ |
120 |
| -int8_t stdlib_ndarray_set_ptr_uint64( uint8_t *idx, const uint64_t v ) { |
121 |
| - *(uint64_t *)idx = v; |
122 |
| - return 0; |
123 |
| -} |
124 |
| - |
125 |
| -/** |
126 |
| -* Sets a signed 64-bit integer ndarray data element specified by a byte array pointer. |
127 |
| -* |
128 |
| -* ## Notes |
129 |
| -* |
130 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
131 |
| -* - The function always returns `0`. |
132 |
| -* |
133 |
| -* @param idx byte array pointer to an ndarray data element |
134 |
| -* @param v value to set |
135 |
| -* @return status code |
136 |
| -*/ |
137 |
| -int8_t stdlib_ndarray_set_ptr_int64( uint8_t *idx, const int64_t v ) { |
138 |
| - *(int64_t *)idx = v; |
139 |
| - return 0; |
140 |
| -} |
141 |
| - |
142 |
| -/** |
143 |
| -* Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer. |
144 |
| -* |
145 |
| -* ## Notes |
146 |
| -* |
147 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
148 |
| -* - The function always returns `0`. |
149 |
| -* |
150 |
| -* @param idx byte array pointer to an ndarray data element |
151 |
| -* @param v value to set |
152 |
| -* @return status code |
153 |
| -*/ |
154 |
| -int8_t stdlib_ndarray_set_ptr_uint32( uint8_t *idx, const uint32_t v ) { |
155 |
| - *(uint32_t *)idx = v; |
156 |
| - return 0; |
157 |
| -} |
158 |
| - |
159 |
| -/** |
160 |
| -* Sets a signed 32-bit integer ndarray data element specified by a byte array pointer. |
161 |
| -* |
162 |
| -* ## Notes |
163 |
| -* |
164 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
165 |
| -* - The function always returns `0`. |
166 |
| -* |
167 |
| -* @param idx byte array pointer to an ndarray data element |
168 |
| -* @param v value to set |
169 |
| -* @return status code |
170 |
| -*/ |
171 |
| -int8_t stdlib_ndarray_set_ptr_int32( uint8_t *idx, const int32_t v ) { |
172 |
| - *(int32_t *)idx = v; |
173 |
| - return 0; |
174 |
| -} |
175 |
| - |
176 |
| -/** |
177 |
| -* Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer. |
178 |
| -* |
179 |
| -* ## Notes |
180 |
| -* |
181 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
182 |
| -* - The function always returns `0`. |
183 |
| -* |
184 |
| -* @param idx byte array pointer to an ndarray data element |
185 |
| -* @param v value to set |
186 |
| -* @return status code |
187 |
| -*/ |
188 |
| -int8_t stdlib_ndarray_set_ptr_uint16( uint8_t *idx, const uint16_t v ) { |
189 |
| - *(uint16_t *)idx = v; |
190 |
| - return 0; |
191 |
| -} |
192 |
| - |
193 |
| -/** |
194 |
| -* Sets a signed 16-bit integer ndarray data element specified by a byte array pointer. |
195 |
| -* |
196 |
| -* ## Notes |
197 |
| -* |
198 |
| -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. |
199 |
| -* - The function always returns `0`. |
200 |
| -* |
201 |
| -* @param idx byte array pointer to an ndarray data element |
202 |
| -* @param v value to set |
203 |
| -* @return status code |
204 |
| -*/ |
205 |
| -int8_t stdlib_ndarray_set_ptr_int16( uint8_t *idx, const int16_t v ) { |
206 |
| - *(int16_t *)idx = v; |
207 |
| - return 0; |
208 |
| -} |
209 |
| - |
210 |
| -/** |
211 |
| -* Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer. |
212 |
| -* |
213 |
| -* ## Notes |
214 |
| -* |
215 |
| -* - The function always returns `0`. |
216 |
| -* |
217 |
| -* @param idx byte array pointer to an ndarray data element |
218 |
| -* @param v value to set |
219 |
| -* @return status code |
220 |
| -*/ |
221 |
| -int8_t stdlib_ndarray_set_ptr_uint8( uint8_t *idx, const uint8_t v ) { |
222 |
| - *(uint8_t *)idx = v; |
223 |
| - return 0; |
224 |
| -} |
225 |
| - |
226 |
| -/** |
227 |
| -* Sets a signed 8-bit integer ndarray data element specified by a byte array pointer. |
228 |
| -* |
229 |
| -* ## Notes |
230 |
| -* |
231 |
| -* - The function always returns `0`. |
232 |
| -* |
233 |
| -* @param idx byte array pointer to an ndarray data element |
234 |
| -* @param v value to set |
235 |
| -* @return status code |
236 |
| -*/ |
237 |
| -int8_t stdlib_ndarray_set_ptr_int8( uint8_t *idx, const int8_t v ) { |
238 |
| - *(int8_t *)idx = v; |
239 |
| - return 0; |
240 |
| -} |
241 |
| - |
242 | 23 | /**
|
243 | 24 | * Sets an ndarray data element.
|
244 | 25 | *
|
|
0 commit comments