|
| 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 | +# at4d |
| 22 | + |
| 23 | +> Return an element from a four-dimensional nested 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 at4d = require( '@stdlib/array/base/at4d' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### at4d( x, i0, i1, i2, i3 ) |
| 44 | + |
| 45 | +Return an element from a four-dimensional nested array. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var x = [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ]; |
| 49 | + |
| 50 | +var out = at4d( x, 0, 0, 0, 1 ); |
| 51 | +// returns 2 |
| 52 | + |
| 53 | +out = at4d( x, 0, 0, 1, 0 ); |
| 54 | +// returns 3 |
| 55 | +``` |
| 56 | + |
| 57 | +The function accepts the following arguments: |
| 58 | + |
| 59 | +- **x**: four-dimensional nested input array. |
| 60 | +- **i0**: first dimension index. |
| 61 | +- **i1**: second dimension index. |
| 62 | +- **i2**: third dimension index. |
| 63 | +- **i3**: fourth dimension index. |
| 64 | + |
| 65 | +</section> |
| 66 | + |
| 67 | +<!-- /.usage --> |
| 68 | + |
| 69 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 70 | + |
| 71 | +<section class="notes"> |
| 72 | + |
| 73 | +## Notes |
| 74 | + |
| 75 | +- Negative indices are resolved relative to the last element along the respective dimension, with the last element corresponding to `-1`. |
| 76 | +- If provided out-of-bounds indices, the function always returns `undefined`. |
| 77 | + |
| 78 | +</section> |
| 79 | + |
| 80 | +<!-- /.notes --> |
| 81 | + |
| 82 | +<!-- Package usage examples. --> |
| 83 | + |
| 84 | +<section class="examples"> |
| 85 | + |
| 86 | +## Examples |
| 87 | + |
| 88 | +<!-- eslint no-undef: "error" --> |
| 89 | + |
| 90 | +```javascript |
| 91 | +var papply = require( '@stdlib/utils/papply' ); |
| 92 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; |
| 93 | +var filled4dBy = require( '@stdlib/array/base/filled4d-by' ); |
| 94 | +var quaternary4d = require( '@stdlib/array/base/quaternary4d' ); |
| 95 | +var zeros4d = require( '@stdlib/array/base/zeros4d' ); |
| 96 | +var at4d = require( '@stdlib/array/base/at4d' ); |
| 97 | + |
| 98 | +var shape = [ 2, 2, 4, 4 ]; |
| 99 | + |
| 100 | +// Define a nested input array: |
| 101 | +var x = filled4dBy( shape, discreteUniform( -100, 100 ) ); |
| 102 | +console.log( x ); |
| 103 | + |
| 104 | +// Define arrays containing random index values: |
| 105 | +var i0 = filled4dBy( shape, discreteUniform( -shape[0], shape[0]-1 ) ); |
| 106 | +console.log( i0 ); |
| 107 | + |
| 108 | +var i1 = filled4dBy( shape, discreteUniform( -shape[1], shape[1]-1 ) ); |
| 109 | +console.log( i1 ); |
| 110 | + |
| 111 | +var i2 = filled4dBy( shape, discreteUniform( -shape[2], shape[2]-1 ) ); |
| 112 | +console.log( i2 ); |
| 113 | + |
| 114 | +var i3 = filled4dBy( shape, discreteUniform( -shape[3], shape[3]-1 ) ); |
| 115 | +console.log( i3 ); |
| 116 | + |
| 117 | +// Define an output array: |
| 118 | +var out = zeros4d( shape ); |
| 119 | +console.log( out ); |
| 120 | + |
| 121 | +// Fill the output array with randomly selected values from the input array: |
| 122 | +quaternary4d( [ i0, i1, i2, i3, out ], shape, papply( at4d, x ) ); |
| 123 | +console.log( out ); |
| 124 | +``` |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.examples --> |
| 129 | + |
| 130 | +<!-- 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. --> |
| 131 | + |
| 132 | +<section class="references"> |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.references --> |
| 137 | + |
| 138 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 139 | + |
| 140 | +<section class="related"> |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.related --> |
| 145 | + |
| 146 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 147 | + |
| 148 | +<section class="links"> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.links --> |
0 commit comments