|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# concat1d |
| 22 | + |
| 23 | +> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating the provided input arguments. |
| 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 concat1d = require( '@stdlib/ndarray/concat1d' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### concat1d( ...arrays ) |
| 44 | + |
| 45 | +Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating the provided input arguments. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var array = require( '@stdlib/ndarray/array' ); |
| 49 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 50 | + |
| 51 | +var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); |
| 52 | +var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] ); |
| 53 | + |
| 54 | +var out = concat1d( x, y ); |
| 55 | +// returns <ndarray> |
| 56 | + |
| 57 | +var arr = ndarray2array( out ); |
| 58 | +// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] |
| 59 | +``` |
| 60 | + |
| 61 | +The function accepts the following arguments: |
| 62 | + |
| 63 | +- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. Where each argument must either be a one-dimensional [ndarray][@stdlib/ndarray/ctor], a zero-dimensional[ndarray][@stdlib/ndarray/ctor] or a scalar value. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules]. If provided scalar inputs or [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. |
| 64 | + |
| 65 | +The following example demonstrates each invocation style returning equivalent results. |
| 66 | + |
| 67 | +```javascript |
| 68 | +var array = require( '@stdlib/ndarray/array' ); |
| 69 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 70 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 71 | + |
| 72 | +var x = array( [ -1.0, 2.0 ] ); |
| 73 | +var y = scalar2ndarray( -3.0 ); |
| 74 | + |
| 75 | +// 1. Using separate arguments: |
| 76 | +var out = concat1d( x, y, 4.0 ); |
| 77 | +// returns <ndarray> |
| 78 | + |
| 79 | +var arr = ndarray2array( out ); |
| 80 | +// returns [ -1.0, 2.0, -3.0, 4.0 ] |
| 81 | + |
| 82 | +x = array( [ -5.0, 6.0 ] ); |
| 83 | +y = scalar2ndarray( -7.0 ); |
| 84 | + |
| 85 | +// 2. Using an array of arguments: |
| 86 | +out = concat1d( [ x, y, 8.0 ] ); |
| 87 | +// returns <ndarray> |
| 88 | + |
| 89 | +arr = ndarray2array( out ); |
| 90 | +// returns [ -5.0, 6.0, -7.0, 8.0 ] |
| 91 | +``` |
| 92 | + |
| 93 | +#### concat1d.assign( ...arrays, out ) |
| 94 | + |
| 95 | +Concatenates provided input arguments and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor]. |
| 96 | + |
| 97 | +```javascript |
| 98 | +var array = require( '@stdlib/ndarray/array' ); |
| 99 | +var zeros = require( '@stdlib/ndarray/zeros' ); |
| 100 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 101 | + |
| 102 | +var x = array( [ -1.0, 2.0, 3.0, 4.0 ] ); |
| 103 | +var y = array( [ -5.0, 6.0, -7.0, -8.0 ] ); |
| 104 | +var z = zeros( [ 8 ] ); |
| 105 | + |
| 106 | +var out = concat1d.assign( x, y, z ); |
| 107 | +// returns <ndarray> |
| 108 | + |
| 109 | +var bool = ( out === z ); |
| 110 | +// returns true |
| 111 | + |
| 112 | +var arr = ndarray2array( z ); |
| 113 | +// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0 ] |
| 114 | +``` |
| 115 | + |
| 116 | +The function accepts the following arguments: |
| 117 | + |
| 118 | +- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. Where each argument must either be a one-dimensional [ndarray][@stdlib/ndarray/ctor], a zero-dimensional[ndarray][@stdlib/ndarray/ctor] or a scalar value. The data type of the output [ndarray][@stdlib/ndarray/ctor] is determined by applying [type promotion rules][@stdlib/ndarray/promotion-rules]. If provided scalar inputs or [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders], the output [ndarray][@stdlib/ndarray/ctor] has the [default order][@stdlib/ndarray/defaults]. |
| 119 | +- **out**: output [ndarray][@stdlib/ndarray/ctor]. |
| 120 | + |
| 121 | +The following example demonstrates each invocation style returning equivalent results. |
| 122 | + |
| 123 | +```javascript |
| 124 | +var array = require( '@stdlib/ndarray/array' ); |
| 125 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 126 | +var zeros = require( '@stdlib/ndarray/zeros' ); |
| 127 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 128 | + |
| 129 | +var x = array( [ -1.0, 2.0 ] ); |
| 130 | +var y = scalar2ndarray( -3.0 ); |
| 131 | +var z = zeros( [ 4 ] ); |
| 132 | + |
| 133 | +// 1. Using separate arguments: |
| 134 | +var out = concat1d.assign( x, y, 4.0, z ); |
| 135 | +// returns <ndarray> |
| 136 | + |
| 137 | +var bool = ( out === z ); |
| 138 | +// returns true |
| 139 | + |
| 140 | +var arr = ndarray2array( z ); |
| 141 | +// returns [ -1.0, 2.0, -3.0, 4.0 ] |
| 142 | + |
| 143 | +x = array( [ -5.0, 6.0 ] ); |
| 144 | +y = scalar2ndarray( -7.0 ); |
| 145 | +z = zeros( [ 4 ] ); |
| 146 | + |
| 147 | +// 2. Using an array of arguments: |
| 148 | +out = concat1d.assign( [ x, y, 8.0 ], z ); |
| 149 | +// returns <ndarray> |
| 150 | + |
| 151 | +bool = ( out === z ); |
| 152 | +// returns true |
| 153 | + |
| 154 | +arr = ndarray2array( out ); |
| 155 | +// returns [ -5.0, 6.0, -7.0, 8.0 ] |
| 156 | +``` |
| 157 | + |
| 158 | +</section> |
| 159 | + |
| 160 | +<!-- /.usage --> |
| 161 | + |
| 162 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 163 | + |
| 164 | +<section class="notes"> |
| 165 | + |
| 166 | +</section> |
| 167 | + |
| 168 | +<!-- /.notes --> |
| 169 | + |
| 170 | +<!-- Package usage examples. --> |
| 171 | + |
| 172 | +<section class="examples"> |
| 173 | + |
| 174 | +## Examples |
| 175 | + |
| 176 | +```javascript |
| 177 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 178 | +var ndarray = require( '@stdlib/ndarray/ctor' ); |
| 179 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 180 | +var concat1d = require( '@stdlib/ndarray/concat1d' ); |
| 181 | + |
| 182 | +var xbuf = discreteUniform( 6, 0, 10, { |
| 183 | + 'dtype': 'generic' |
| 184 | +}); |
| 185 | +var x = new ndarray( 'generic', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); |
| 186 | +console.log( ndarray2array( x ) ); |
| 187 | + |
| 188 | +var ybuf = discreteUniform( 8, 0, 10, { |
| 189 | + 'dtype': 'generic' |
| 190 | +}); |
| 191 | +var y = new ndarray( 'generic', ybuf, [ 8 ], [ 1 ], 0, 'row-major' ); |
| 192 | +console.log( ndarray2array( y ) ); |
| 193 | + |
| 194 | +var out = concat1d( x, y ); |
| 195 | +console.log( ndarray2array( out ) ); |
| 196 | +``` |
| 197 | + |
| 198 | +</section> |
| 199 | + |
| 200 | +<!-- /.examples --> |
| 201 | + |
| 202 | +<!-- 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. --> |
| 203 | + |
| 204 | +<section class="references"> |
| 205 | + |
| 206 | +</section> |
| 207 | + |
| 208 | +<!-- /.references --> |
| 209 | + |
| 210 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 211 | + |
| 212 | +<section class="related"> |
| 213 | + |
| 214 | +</section> |
| 215 | + |
| 216 | +<!-- /.related --> |
| 217 | + |
| 218 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 219 | + |
| 220 | +<section class="links"> |
| 221 | + |
| 222 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor |
| 223 | + |
| 224 | +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders |
| 225 | + |
| 226 | +[@stdlib/ndarray/defaults]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/defaults |
| 227 | + |
| 228 | +[@stdlib/ndarray/promotion-rules]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/promotion-rules |
| 229 | + |
| 230 | +</section> |
| 231 | + |
| 232 | +<!-- /.links --> |
0 commit comments