|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# vconcat |
| 22 | + |
| 23 | +> Concatenate a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-last dimension. |
| 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 vconcat = require( '@stdlib/ndarray/vconcat' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### vconcat( arrays ) |
| 44 | + |
| 45 | +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-last dimension. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var array = require( '@stdlib/ndarray/array' ); |
| 49 | + |
| 50 | +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); |
| 51 | +// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] |
| 52 | + |
| 53 | +var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] ); |
| 54 | +// returns <ndarray>[ [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] |
| 55 | + |
| 56 | +var out = vconcat( [ x, y ] ); |
| 57 | +// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] |
| 58 | +``` |
| 59 | + |
| 60 | +The function accepts the following arguments: |
| 61 | + |
| 62 | +- **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules] to the list of input [ndarrays][@stdlib/ndarray/ctor]. If provided [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. |
| 63 | + |
| 64 | +#### vconcat.assign( arrays, out ) |
| 65 | + |
| 66 | +Concatenates a list of [ndarrays][@stdlib/ndarray/ctor] along the second-to-last dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. |
| 67 | + |
| 68 | +```javascript |
| 69 | +var array = require( '@stdlib/ndarray/array' ); |
| 70 | +var zeros = require( '@stdlib/ndarray/zeros' ); |
| 71 | + |
| 72 | +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); |
| 73 | +// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] |
| 74 | + |
| 75 | +var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] ); |
| 76 | +// returns <ndarray>[ [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] |
| 77 | + |
| 78 | +var z = zeros( [ 5, 2 ] ); |
| 79 | +// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] |
| 80 | + |
| 81 | +var out = vconcat.assign( [ x, y ], z ); |
| 82 | +// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ], [ 7.0, 8.0 ], [ 9.0, 10.0 ] ] |
| 83 | + |
| 84 | +var bool = ( out === z ); |
| 85 | +// returns true |
| 86 | +``` |
| 87 | + |
| 88 | +The function accepts the following arguments: |
| 89 | + |
| 90 | +- **arrays**: a list of input [ndarrays][@stdlib/ndarray/ctor]. Must [promote][@stdlib/ndarray/promotion-rules] to a [data type][@stdlib/ndarray/dtypes] which can be (mostly) [safely cast][@stdlib/ndarray/mostly-safe-casts] to the [data type][@stdlib/ndarray/dtypes] of the output [ndarray][@stdlib/ndarray/ctor]. |
| 91 | +- **out**: output [ndarray][@stdlib/ndarray/ctor]. |
| 92 | + |
| 93 | +</section> |
| 94 | + |
| 95 | +<!-- /.usage --> |
| 96 | + |
| 97 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 98 | + |
| 99 | +<section class="notes"> |
| 100 | + |
| 101 | +- Input [ndarrays][@stdlib/ndarray/ctor] must have more than one dimension. |
| 102 | + |
| 103 | +</section> |
| 104 | + |
| 105 | +<!-- /.notes --> |
| 106 | + |
| 107 | +<!-- Package usage examples. --> |
| 108 | + |
| 109 | +<section class="examples"> |
| 110 | + |
| 111 | +## Examples |
| 112 | + |
| 113 | +<!-- eslint no-undef: "error" --> |
| 114 | + |
| 115 | +```javascript |
| 116 | +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); |
| 117 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 118 | +var vconcat = require( '@stdlib/ndarray/vconcat' ); |
| 119 | + |
| 120 | +var x = discreteUniform( [ 2, 3 ], 0, 10, { |
| 121 | + 'dtype': 'generic' |
| 122 | +}); |
| 123 | +console.log( ndarray2array( x ) ); |
| 124 | + |
| 125 | +var y = discreteUniform( [ 3, 3 ], 0, 10, { |
| 126 | + 'dtype': 'generic' |
| 127 | +}); |
| 128 | +console.log( ndarray2array( y ) ); |
| 129 | + |
| 130 | +var out = vconcat( [ x, y ] ); |
| 131 | +console.log( ndarray2array( out ) ); |
| 132 | +``` |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.examples --> |
| 137 | + |
| 138 | +<!-- 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. --> |
| 139 | + |
| 140 | +<section class="references"> |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.references --> |
| 145 | + |
| 146 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 147 | + |
| 148 | +<section class="related"> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.related --> |
| 153 | + |
| 154 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 155 | + |
| 156 | +<section class="links"> |
| 157 | + |
| 158 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor |
| 159 | + |
| 160 | +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes |
| 161 | + |
| 162 | +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders |
| 163 | + |
| 164 | +[@stdlib/ndarray/defaults]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/defaults |
| 165 | + |
| 166 | +[@stdlib/ndarray/promotion-rules]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/promotion-rules |
| 167 | + |
| 168 | +[@stdlib/ndarray/mostly-safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/mostly-safe-casts |
| 169 | + |
| 170 | +</section> |
| 171 | + |
| 172 | +<!-- /.links --> |
0 commit comments