Skip to content

Commit ad1a529

Browse files
committed
Move functions to separate file
1 parent f127fe1 commit ad1a529

File tree

3 files changed

+252
-230
lines changed

3 files changed

+252
-230
lines changed

lib/node_modules/@stdlib/ndarray/ctor/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"src": [
2828
"./src/get.c",
2929
"./src/iget.c",
30+
"./src/iset.c",
3031
"./src/main.c",
3132
"./src/set.c"
3233
],
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <stdlib.h>
20+
#include <stdint.h>
21+
#include "stdlib/ndarray/ctor.h"
22+
23+
/**
24+
* Sets an ndarray data element located at a specified linear index.
25+
*
26+
* ## Notes
27+
*
28+
* - The function returns `-1` if unable to set an element and `0` otherwise.
29+
* - The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types.
30+
* - The function has no way of determining whether `v` actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing.
31+
*
32+
* @param arr input ndarray
33+
* @param idx linear view index
34+
* @param v value to set
35+
* @return status code
36+
*/
37+
int8_t stdlib_ndarray_iset( const struct ndarray *arr, const int64_t idx, const void *v ) {
38+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
39+
if ( ind == NULL ) {
40+
return -1;
41+
}
42+
return stdlib_ndarray_set_ptr_value( arr, ind, v );
43+
}
44+
45+
/**
46+
* Sets a double-precision floating-point ndarray data element located at a specified linear index.
47+
*
48+
* ## Notes
49+
*
50+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
51+
* - The function returns `-1` if unable to set an element and `0` otherwise.
52+
*
53+
* @param arr input ndarray
54+
* @param idx linear view index
55+
* @param v value to set
56+
* @return status code
57+
*/
58+
int8_t stdlib_ndarray_iset_float64( const struct ndarray *arr, const int64_t idx, const double v ) {
59+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
60+
if ( ind == NULL ) {
61+
return -1;
62+
}
63+
return stdlib_ndarray_set_ptr_float64( ind, v );
64+
}
65+
66+
/**
67+
* Sets a single-precision floating-point ndarray data element located at a specified linear index.
68+
*
69+
* ## Notes
70+
*
71+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
72+
* - The function returns `-1` if unable to set an element and `0` otherwise.
73+
*
74+
* @param arr input ndarray
75+
* @param idx linear view index
76+
* @param v value to set
77+
* @return status code
78+
*/
79+
int8_t stdlib_ndarray_iset_float32( const struct ndarray *arr, const int64_t idx, const float v ) {
80+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
81+
if ( ind == NULL ) {
82+
return -1;
83+
}
84+
return stdlib_ndarray_set_ptr_float32( ind, v );
85+
}
86+
87+
/**
88+
* Sets an unsigned 64-bit integer ndarray data element located at a specified linear index.
89+
*
90+
* ## Notes
91+
*
92+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
93+
* - The function returns `-1` if unable to set an element and `0` otherwise.
94+
*
95+
* @param arr input ndarray
96+
* @param idx linear view index
97+
* @param v value to set
98+
* @return status code
99+
*/
100+
int8_t stdlib_ndarray_iset_uint64( const struct ndarray *arr, const int64_t idx, const uint64_t v ) {
101+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
102+
if ( ind == NULL ) {
103+
return -1;
104+
}
105+
return stdlib_ndarray_set_ptr_uint64( ind, v );
106+
}
107+
108+
/**
109+
* Sets a signed 64-bit integer ndarray data element located at a specified linear index.
110+
*
111+
* ## Notes
112+
*
113+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
114+
* - The function returns `-1` if unable to set an element and `0` otherwise.
115+
*
116+
* @param arr input ndarray
117+
* @param idx linear view index
118+
* @param v value to set
119+
* @return status code
120+
*/
121+
int8_t stdlib_ndarray_iset_int64( const struct ndarray *arr, const int64_t idx, const int64_t v ) {
122+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
123+
if ( ind == NULL ) {
124+
return -1;
125+
}
126+
return stdlib_ndarray_set_ptr_int64( ind, v );
127+
}
128+
129+
/**
130+
* Sets an unsigned 32-bit integer ndarray data element located at a specified linear index.
131+
*
132+
* ## Notes
133+
*
134+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
135+
* - The function returns `-1` if unable to set an element and `0` otherwise.
136+
*
137+
* @param arr input ndarray
138+
* @param idx linear view index
139+
* @param v value to set
140+
* @return status code
141+
*/
142+
int8_t stdlib_ndarray_iset_uint32( const struct ndarray *arr, const int64_t idx, const uint32_t v ) {
143+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
144+
if ( ind == NULL ) {
145+
return -1;
146+
}
147+
return stdlib_ndarray_set_ptr_uint32( ind, v );
148+
}
149+
150+
/**
151+
* Sets a signed 32-bit integer ndarray data element located at a specified linear index.
152+
*
153+
* ## Notes
154+
*
155+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
156+
* - The function returns `-1` if unable to set an element and `0` otherwise.
157+
*
158+
* @param arr input ndarray
159+
* @param idx linear view index
160+
* @param v value to set
161+
* @return status code
162+
*/
163+
int8_t stdlib_ndarray_iset_int32( const struct ndarray *arr, const int64_t idx, const int32_t v ) {
164+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
165+
if ( ind == NULL ) {
166+
return -1;
167+
}
168+
return stdlib_ndarray_set_ptr_int32( ind, v );
169+
}
170+
171+
/**
172+
* Sets an unsigned 16-bit integer ndarray data element located at a specified linear index.
173+
*
174+
* ## Notes
175+
*
176+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
177+
* - The function returns `-1` if unable to set an element and `0` otherwise.
178+
*
179+
* @param arr input ndarray
180+
* @param idx linear view index
181+
* @param v value to set
182+
* @return status code
183+
*/
184+
int8_t stdlib_ndarray_iset_uint16( const struct ndarray *arr, const int64_t idx, const uint16_t v ) {
185+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
186+
if ( ind == NULL ) {
187+
return -1;
188+
}
189+
return stdlib_ndarray_set_ptr_uint16( ind, v );
190+
}
191+
192+
/**
193+
* Sets a signed 16-bit integer ndarray data element located at a specified linear index.
194+
*
195+
* ## Notes
196+
*
197+
* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing.
198+
* - The function returns `-1` if unable to set an element and `0` otherwise.
199+
*
200+
* @param arr input ndarray
201+
* @param idx linear view index
202+
* @param v value to set
203+
* @return status code
204+
*/
205+
int8_t stdlib_ndarray_iset_int16( const struct ndarray *arr, const int64_t idx, const int16_t v ) {
206+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
207+
if ( ind == NULL ) {
208+
return -1;
209+
}
210+
return stdlib_ndarray_set_ptr_int16( ind, v );
211+
}
212+
213+
/**
214+
* Sets an unsigned 8-bit integer ndarray data element located at a specified linear index.
215+
*
216+
* ## Notes
217+
*
218+
* - The function returns `-1` if unable to set an element and `0` otherwise.
219+
*
220+
* @param arr input ndarray
221+
* @param idx linear view index
222+
* @param v value to set
223+
* @return status code
224+
*/
225+
int8_t stdlib_ndarray_iset_uint8( const struct ndarray *arr, const int64_t idx, const uint8_t v ) {
226+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
227+
if ( ind == NULL ) {
228+
return -1;
229+
}
230+
return stdlib_ndarray_set_ptr_uint8( ind, v );
231+
}
232+
233+
/**
234+
* Sets a signed 8-bit integer ndarray data element located at a specified linear index.
235+
*
236+
* ## Notes
237+
*
238+
* - The function returns `-1` if unable to set an element and `0` otherwise.
239+
*
240+
* @param arr input ndarray
241+
* @param idx linear view index
242+
* @param v value to set
243+
* @return status code
244+
*/
245+
int8_t stdlib_ndarray_iset_int8( const struct ndarray *arr, const int64_t idx, const int8_t v ) {
246+
uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx );
247+
if ( ind == NULL ) {
248+
return -1;
249+
}
250+
return stdlib_ndarray_set_ptr_int8( ind, v );
251+
}

0 commit comments

Comments
 (0)