|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# array2dtype |
| 22 | + |
| 23 | +> Return the WebAssembly data type for a provided array. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var array2dtype = require( '@stdlib/wasm/base/array2dtype' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### array2dtype( array ) |
| 44 | + |
| 45 | +Returns the WebAssembly data type for a provided `array`. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 49 | +var arr = new Float64Array( 10 ); |
| 50 | + |
| 51 | +var dt = array2dtype( arr ); |
| 52 | +// returns 'float64' |
| 53 | +``` |
| 54 | + |
| 55 | +If provided an argument having "generic" or an unknown/unsupported [data type][@stdlib/array/dtypes], the function assumes that array values can be stored as double-precision floating-point numbers and returns `'float64'`. |
| 56 | + |
| 57 | +```javascript |
| 58 | +var dt = array2dtype( [] ); |
| 59 | +// returns 'float64' |
| 60 | +``` |
| 61 | + |
| 62 | +</section> |
| 63 | + |
| 64 | +<!-- /.usage --> |
| 65 | + |
| 66 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +</section> |
| 71 | + |
| 72 | +<!-- /.notes --> |
| 73 | + |
| 74 | +<!-- Package usage examples. --> |
| 75 | + |
| 76 | +<section class="examples"> |
| 77 | + |
| 78 | +## Examples |
| 79 | + |
| 80 | +<!-- eslint no-undef: "error" --> |
| 81 | + |
| 82 | +```javascript |
| 83 | +var dtypes = require( '@stdlib/array/dtypes' ); |
| 84 | +var empty = require( '@stdlib/array/empty' ); |
| 85 | +var array2dtype = require( '@stdlib/wasm/base/array2dtype' ); |
| 86 | + |
| 87 | +// Get a list of supported array data types: |
| 88 | +var dt = dtypes(); |
| 89 | + |
| 90 | +// For each supported data type, create an array and return its WebAssembly data type... |
| 91 | +var v; |
| 92 | +var i; |
| 93 | +for ( i = 0; i < dt.length; i++ ) { |
| 94 | + v = array2dtype( empty( 10, dt[ i ] ) ); |
| 95 | + console.log( '%s => %s', dt, v ); |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +</section> |
| 100 | + |
| 101 | +<!-- /.examples --> |
| 102 | + |
| 103 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 104 | + |
| 105 | +<section class="references"> |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.references --> |
| 110 | + |
| 111 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 112 | + |
| 113 | +<section class="related"> |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.related --> |
| 118 | + |
| 119 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 120 | + |
| 121 | +<section class="links"> |
| 122 | + |
| 123 | +[@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dtypes |
| 124 | + |
| 125 | +</section> |
| 126 | + |
| 127 | +<!-- /.links --> |
0 commit comments