time-to-botec

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

get.c (10395B)


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