time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

iget.c (12882B)


      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/ndarray/ctor/iget.h"
     20 #include "stdlib/ndarray/ctor/iget_ptr.h"
     21 #include "stdlib/ndarray/ctor/get_ptr.h"
     22 #include "stdlib/ndarray/ctor/ndarray.h"
     23 #include <stdlib.h>
     24 #include <stdint.h>
     25 #include <stdbool.h>
     26 #include <complex.h>
     27 
     28 /**
     29 * Returns an ndarray data element located at a specified linear index.
     30 *
     31 * ## Notes
     32 *
     33 * -   The function returns `-1` if unable to get an element and `0` otherwise.
     34 * -   The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types.
     35 * -   The function places the burden on the user to ensure that the output address is compatible with the data type of input ndarray data elements.
     36 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
     37 *
     38 * @param arr  input ndarray
     39 * @param idx  linear view index
     40 * @param out  output address
     41 * @return     status code
     42 */
     43 int8_t stdlib_ndarray_iget( const struct ndarray *arr, const int64_t idx, void *out ) {
     44 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
     45 	if ( ptr == NULL ) {
     46 		return -1;
     47 	}
     48 	return stdlib_ndarray_get_ptr_value( arr, ptr, out );
     49 }
     50 
     51 /**
     52 * Returns a double-precision floating-point ndarray data element located at a specified linear index.
     53 *
     54 * ## Notes
     55 *
     56 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
     57 * -   The function returns `-1` if unable to get an element and `0` otherwise.
     58 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
     59 *
     60 * @param arr  input ndarray
     61 * @param idx  linear view index
     62 * @param out  output address
     63 * @return     status code
     64 */
     65 int8_t stdlib_ndarray_iget_float64( const struct ndarray *arr, const int64_t idx, double *out ) {
     66 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
     67 	if ( ptr == NULL ) {
     68 		return -1;
     69 	}
     70 	return stdlib_ndarray_get_ptr_float64( ptr, out );
     71 }
     72 
     73 /**
     74 * Returns a single-precision floating-point ndarray data element located at a specified linear index.
     75 *
     76 * ## Notes
     77 *
     78 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
     79 * -   The function returns `-1` if unable to get an element and `0` otherwise.
     80 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
     81 *
     82 * @param arr  input ndarray
     83 * @param idx  linear view index
     84 * @param out  output address
     85 * @return     status code
     86 */
     87 int8_t stdlib_ndarray_iget_float32( const struct ndarray *arr, const int64_t idx, float *out ) {
     88 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
     89 	if ( ptr == NULL ) {
     90 		return -1;
     91 	}
     92 	return stdlib_ndarray_get_ptr_float32( ptr, out );
     93 }
     94 
     95 /**
     96 * Returns an unsigned 64-bit integer ndarray data element located at a specified linear index.
     97 *
     98 * ## Notes
     99 *
    100 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    101 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    102 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    103 *
    104 * @param arr  input ndarray
    105 * @param idx  linear view index
    106 * @param out  output address
    107 * @return     status code
    108 */
    109 int8_t stdlib_ndarray_iget_uint64( const struct ndarray *arr, const int64_t idx, uint64_t *out ) {
    110 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    111 	if ( ptr == NULL ) {
    112 		return -1;
    113 	}
    114 	return stdlib_ndarray_get_ptr_uint64( ptr, out );
    115 }
    116 
    117 /**
    118 * Returns a signed 64-bit integer ndarray data element located at a specified linear index.
    119 *
    120 * ## Notes
    121 *
    122 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    123 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    124 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    125 *
    126 * @param arr  input ndarray
    127 * @param idx  linear view index
    128 * @param out  output address
    129 * @return     status code
    130 */
    131 int8_t stdlib_ndarray_iget_int64( const struct ndarray *arr, const int64_t idx, int64_t *out ) {
    132 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    133 	if ( ptr == NULL ) {
    134 		return -1;
    135 	}
    136 	return stdlib_ndarray_get_ptr_int64( ptr, out );
    137 }
    138 
    139 /**
    140 * Returns an unsigned 32-bit integer ndarray data element located at a specified linear index.
    141 *
    142 * ## Notes
    143 *
    144 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    145 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    146 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    147 *
    148 * @param arr  input ndarray
    149 * @param idx  linear view index
    150 * @param out  output address
    151 * @return     status code
    152 */
    153 int8_t stdlib_ndarray_iget_uint32( const struct ndarray *arr, const int64_t idx, uint32_t *out ) {
    154 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    155 	if ( ptr == NULL ) {
    156 		return -1;
    157 	}
    158 	return stdlib_ndarray_get_ptr_uint32( ptr, out );
    159 }
    160 
    161 /**
    162 * Returns a signed 32-bit integer ndarray data element located at a specified linear index.
    163 *
    164 * ## Notes
    165 *
    166 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    167 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    168 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    169 *
    170 * @param arr  input ndarray
    171 * @param idx  linear view index
    172 * @param out  output address
    173 * @return     status code
    174 */
    175 int8_t stdlib_ndarray_iget_int32( const struct ndarray *arr, const int64_t idx, int32_t *out ) {
    176 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    177 	if ( ptr == NULL ) {
    178 		return -1;
    179 	}
    180 	return stdlib_ndarray_get_ptr_int32( ptr, out );
    181 }
    182 
    183 /**
    184 * Returns an unsigned 16-bit integer ndarray data element located at a specified linear index.
    185 *
    186 * ## Notes
    187 *
    188 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    189 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    190 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    191 *
    192 * @param arr  input ndarray
    193 * @param idx  linear view index
    194 * @param out  output address
    195 * @return     status code
    196 */
    197 int8_t stdlib_ndarray_iget_uint16( const struct ndarray *arr, const int64_t idx, uint16_t *out ) {
    198 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    199 	if ( ptr == NULL ) {
    200 		return -1;
    201 	}
    202 	return stdlib_ndarray_get_ptr_uint16( ptr, out );
    203 }
    204 
    205 /**
    206 * Returns a signed 16-bit integer ndarray data element located at a specified linear index.
    207 *
    208 * ## Notes
    209 *
    210 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    211 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    212 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    213 *
    214 * @param arr  input ndarray
    215 * @param idx  linear view index
    216 * @param out  output address
    217 * @return     status code
    218 */
    219 int8_t stdlib_ndarray_iget_int16( const struct ndarray *arr, const int64_t idx, int16_t *out ) {
    220 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    221 	if ( ptr == NULL ) {
    222 		return -1;
    223 	}
    224 	return stdlib_ndarray_get_ptr_int16( ptr, out );
    225 }
    226 
    227 /**
    228 * Returns an unsigned 8-bit integer ndarray data element located at a specified linear index.
    229 *
    230 * ## Notes
    231 *
    232 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    233 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    234 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    235 *
    236 * @param arr  input ndarray
    237 * @param idx  linear view index
    238 * @param out  output address
    239 * @return     status code
    240 */
    241 int8_t stdlib_ndarray_iget_uint8( const struct ndarray *arr, const int64_t idx, uint8_t *out ) {
    242 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    243 	if ( ptr == NULL ) {
    244 		return -1;
    245 	}
    246 	return stdlib_ndarray_get_ptr_uint8( ptr, out );
    247 }
    248 
    249 /**
    250 * Returns a signed 8-bit integer ndarray data element located at a specified linear index.
    251 *
    252 * ## Notes
    253 *
    254 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    255 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    256 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    257 *
    258 * @param arr  input ndarray
    259 * @param idx  linear view index
    260 * @param out  output address
    261 * @return     status code
    262 */
    263 int8_t stdlib_ndarray_iget_int8( const struct ndarray *arr, const int64_t idx, int8_t *out ) {
    264 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    265 	if ( ptr == NULL ) {
    266 		return -1;
    267 	}
    268 	return stdlib_ndarray_get_ptr_int8( ptr, out );
    269 }
    270 
    271 /**
    272 * Returns a double-precision complex floating-point ndarray data element located at a specified linear index.
    273 *
    274 * ## Notes
    275 *
    276 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    277 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    278 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    279 *
    280 * @param arr  input ndarray
    281 * @param idx  linear view index
    282 * @param out  output address
    283 * @return     status code
    284 */
    285 int8_t stdlib_ndarray_iget_complex128( const struct ndarray *arr, const int64_t idx, double complex *out ) {
    286 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    287 	if ( ptr == NULL ) {
    288 		return -1;
    289 	}
    290 	return stdlib_ndarray_get_ptr_complex128( ptr, out );
    291 }
    292 
    293 /**
    294 * Returns a single-precision complex floating-point ndarray data element located at a specified linear index.
    295 *
    296 * ## Notes
    297 *
    298 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    299 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    300 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    301 *
    302 * @param arr  input ndarray
    303 * @param idx  linear view index
    304 * @param out  output address
    305 * @return     status code
    306 */
    307 int8_t stdlib_ndarray_iget_complex64( const struct ndarray *arr, const int64_t idx, float complex *out ) {
    308 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    309 	if ( ptr == NULL ) {
    310 		return -1;
    311 	}
    312 	return stdlib_ndarray_get_ptr_complex64( ptr, out );
    313 }
    314 
    315 /**
    316 * Returns a boolean ndarray data element located at a specified linear index.
    317 *
    318 * ## Notes
    319 *
    320 * -   The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing.
    321 * -   The function returns `-1` if unable to get an element and `0` otherwise.
    322 * -   For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`.
    323 *
    324 * @param arr  input ndarray
    325 * @param idx  linear view index
    326 * @param out  output address
    327 * @return     status code
    328 */
    329 int8_t stdlib_ndarray_iget_bool( const struct ndarray *arr, const int64_t idx, bool *out ) {
    330 	uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx );
    331 	if ( ptr == NULL ) {
    332 		return -1;
    333 	}
    334 	return stdlib_ndarray_get_ptr_bool( ptr, out );
    335 }