Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions lib/node_modules/@stdlib/ndarray/concat1d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<!--

@license Apache-2.0

Copyright (c) 2025 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# concat1d

> Return a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating provided input arguments.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var concat1d = require( '@stdlib/ndarray/concat1d' );
```

#### concat1d( ...arrays )

Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] formed by concatenating provided input arguments.

```javascript
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );

var x = array( [ -1.0, 2.0, 3.0, 4.0 ] );
var y = array( [ -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ] );

var out = concat1d( x, y );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0, 9.0, -10.0 ]
```

The function accepts the following arguments:

- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. 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 [ndarrays][@stdlib/ndarray/ctor] having different [memory layouts][@stdlib/ndarray/orders] or only scalar inputs, the output [ndarray][@stdlib/ndarray/ctor] has the [default memory layout][@stdlib/ndarray/defaults].

#### concat1d.assign( ...arrays, out )

Concatenates provided input arguments and assigns the result to a provided one-dimensional output [ndarray][@stdlib/ndarray/ctor].

```javascript
var array = require( '@stdlib/ndarray/array' );
var zeros = require( '@stdlib/ndarray/zeros' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );

var x = array( [ -1.0, 2.0, 3.0, 4.0 ] );
var y = array( [ -5.0, 6.0, -7.0, -8.0 ] );
var z = zeros( [ 8 ] );

var out = concat1d.assign( x, y, z );
// returns <ndarray>

var bool = ( out === z );
// returns true

var arr = ndarray2array( z );
// returns [ -1.0, 2.0, 3.0, 4.0, -5.0, 6.0, -7.0, -8.0 ]
```

The function accepts the following arguments:

- **...arrays**: inputs to concatenate. May be passed as separate arguments or an array of arguments. Each argument must either be a one-dimensional [ndarray][@stdlib/ndarray/ctor], a zero-dimensional[ndarray][@stdlib/ndarray/ctor], or a scalar value.
- **out**: output [ndarray][@stdlib/ndarray/ctor].

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var concat1d = require( '@stdlib/ndarray/concat1d' );

var opts = {
'dtype': 'generic'
};
var x = array( discreteUniform( 6, 0, 10, opts ), opts );
console.log( ndarray2array( x ) );

var y = array( discreteUniform( 8, 0, 10, opts ), opts );
console.log( ndarray2array( y ) );

var out = concat1d( x, y );
console.log( ndarray2array( out ) );
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders

[@stdlib/ndarray/defaults]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/defaults

[@stdlib/ndarray/promotion-rules]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/promotion-rules

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var zeros = require( '@stdlib/ndarray/zeros' );
var zeroTo = require( '@stdlib/array/zero-to' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var concat1d = require( './../lib/assign.js' );


// MAIN //

bench( format( '%s::ndarrays', pkg ), function benchmark( b ) {
var values;
var opts;
var out;
var v;
var i;

opts = {
'dtype': 'float64'
};

values = [
zeros( [ 32 ], opts ),
zeros( [ 32 ], opts ),
zeros( [ 32 ], opts ),
zeros( [ 32 ], opts )
];
out = zeros( [ 128 ], opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat1d( values, out );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::ndarrays,casting', pkg ), function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 32 ], { 'dtype': 'float64' }),
zeros( [ 32 ], { 'dtype': 'float32' }),
zeros( [ 32 ], { 'dtype': 'int32' }),
zeros( [ 32 ], { 'dtype': 'generic' })
];
out = zeros( [ 128 ], { 'dtype': 'generic' });

/* eslint-enable object-curly-newline */

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat1d( values, out );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::scalars', pkg ), function benchmark( b ) {
var values;
var out;
var v;
var i;

values = zeroTo( 128 );
out = zeros( [ 128 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat1d( values, out );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::ndarrays+scalars', pkg ), function benchmark( b ) {
var values;
var out;
var v;
var i;

values = zeroTo( 124, 'generic' );
values[ 0 ] = zeros( [ 4 ] );
values[ 3 ] = zeros( [ 2 ] );
out = zeros( [ 128 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat1d( values, out );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading