Skip to content

Commit 06bd3e1

Browse files
committed
Auto-generated commit
1 parent fe26db4 commit 06bd3e1

File tree

11 files changed

+973
-0
lines changed

11 files changed

+973
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`f375981`](https://github.com/stdlib-js/stdlib/commit/f375981dd59f1ce6aa575e48bafa0e7998a7efdd) - add `ndarray/base/to-flippedud` [(#8849)](https://github.com/stdlib-js/stdlib/pull/8849)
1314
- [`1080085`](https://github.com/stdlib-js/stdlib/commit/1080085cbf97a2d217339594fda596759a49386b) - add `ndarray/base/to-flippedlr` [(#8848)](https://github.com/stdlib-js/stdlib/pull/8848)
1415
- [`c034ac5`](https://github.com/stdlib-js/stdlib/commit/c034ac5a8b15ac837619c50efa8db3266c897f8e) - add `ndarray/concat1d` [(#8584)](https://github.com/stdlib-js/stdlib/pull/8584)
1516
- [`493f0c2`](https://github.com/stdlib-js/stdlib/commit/493f0c2fe4ce47b5ea8e5fedd81ef68d028b83f9) - update `ndarray` TypeScript declarations
@@ -648,6 +649,7 @@ A total of 36 issues were closed in this release:
648649

649650
<details>
650651

652+
- [`f375981`](https://github.com/stdlib-js/stdlib/commit/f375981dd59f1ce6aa575e48bafa0e7998a7efdd) - **feat:** add `ndarray/base/to-flippedud` [(#8849)](https://github.com/stdlib-js/stdlib/pull/8849) _(by Muhammad Haris, Athan Reines)_
651653
- [`1080085`](https://github.com/stdlib-js/stdlib/commit/1080085cbf97a2d217339594fda596759a49386b) - **feat:** add `ndarray/base/to-flippedlr` [(#8848)](https://github.com/stdlib-js/stdlib/pull/8848) _(by Muhammad Haris, Athan Reines)_
652654
- [`2772189`](https://github.com/stdlib-js/stdlib/commit/2772189443aedf358ee73b3232feadd2a0acc581) - **docs:** improve doctests for complex number instances in `ndarray/base/broadcast-scalar` [(#8869)](https://github.com/stdlib-js/stdlib/pull/8869) _(by ashutoshsao, Athan Reines)_
653655
- [`ae93d82`](https://github.com/stdlib-js/stdlib/commit/ae93d8247174e8ba0a0bdcb20a14dfa6569b1542) - **docs:** add missing space _(by Philipp Burckhardt)_

base/to-flippedud/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
# toFlippedud
22+
23+
> Return a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed.
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 toFlippedud = require( '@stdlib/ndarray/base/to-flippedud' );
41+
```
42+
43+
#### toFlippedud( x )
44+
45+
Returns a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed.
46+
47+
```javascript
48+
var ndarray = require( '@stdlib/ndarray/ctor' );
49+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
50+
51+
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
52+
var shape = [ 3, 2 ];
53+
var strides = [ 2, 1 ];
54+
var offset = 0;
55+
56+
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
57+
// returns <ndarray>
58+
59+
var sh = x.shape;
60+
// returns [ 3, 2 ]
61+
62+
var arr = ndarray2array( x );
63+
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
64+
65+
var y = toFlippedud( x );
66+
// returns <ndarray>
67+
68+
sh = y.shape;
69+
// returns [ 3, 2 ]
70+
71+
arr = ndarray2array( y );
72+
// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]
73+
```
74+
75+
The function accepts the following arguments:
76+
77+
- **x**: input ndarray.
78+
79+
</section>
80+
81+
<!-- /.usage -->
82+
83+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
84+
85+
<section class="notes">
86+
87+
## Notes
88+
89+
- If provided a zero-dimensional ndarray, as the ndarray has no dimensions to reverse, the function simply returns a copy the input ndarray. Similarly, if provided a one-dimensional ndarray, as the ndarray has only one dimension, the function simply returns a copy of the input ndarray.
90+
91+
</section>
92+
93+
<!-- /.notes -->
94+
95+
<!-- Package usage examples. -->
96+
97+
<section class="examples">
98+
99+
## Examples
100+
101+
```javascript
102+
var array = require( '@stdlib/ndarray/array' );
103+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
104+
var zeroTo = require( '@stdlib/array/base/zero-to' );
105+
var toFlippedud = require( '@stdlib/ndarray/base/to-flippedud' );
106+
107+
// Create a linear ndarray buffer:
108+
var buf = zeroTo( 16 );
109+
110+
// Create a three-dimensional ndarray:
111+
var x = array( buf, {
112+
'shape': [ 2, 4, 2 ]
113+
});
114+
115+
// Reverse the order of second-to-last dimension:
116+
var y = toFlippedud( x );
117+
// returns <ndarray>
118+
119+
var a = ndarray2array( y );
120+
console.log( a );
121+
// => [ [ [ 6, 7 ], [ 4, 5 ], [ 2, 3 ], [ 0, 1 ] ], [ [ 14, 15 ], [ 12, 13 ], [ 10, 11 ], [ 8, 9 ] ] ]
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- 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. -->
129+
130+
<section class="references">
131+
132+
</section>
133+
134+
<!-- /.references -->
135+
136+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137+
138+
<section class="related">
139+
140+
</section>
141+
142+
<!-- /.related -->
143+
144+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145+
146+
<section class="links">
147+
148+
</section>
149+
150+
<!-- /.links -->
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
25+
var baseEmpty = require( './../../../base/empty' );
26+
var empty = require( './../../../empty' );
27+
var pkg = require( './../package.json' ).name;
28+
var toFlippedud = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+'::1d,base', function benchmark( b ) {
34+
var values;
35+
var out;
36+
var i;
37+
38+
values = [
39+
baseEmpty( 'float64', [ 2 ], 'row-major' ),
40+
baseEmpty( 'float32', [ 2 ], 'row-major' ),
41+
baseEmpty( 'int32', [ 2 ], 'row-major' ),
42+
baseEmpty( 'complex128', [ 2 ], 'row-major' ),
43+
baseEmpty( 'generic', [ 2 ], 'row-major' )
44+
];
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
out = toFlippedud( values[ i%values.length ] );
49+
if ( typeof out !== 'object' ) {
50+
b.fail( 'should return an ndarray' );
51+
}
52+
}
53+
b.toc();
54+
if ( !isndarrayLike( out ) ) {
55+
b.fail( 'should return an ndarray' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});
60+
61+
bench( pkg+'::1d,non-base', function benchmark( b ) {
62+
var values;
63+
var out;
64+
var i;
65+
66+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
67+
68+
values = [
69+
empty( [ 2 ], { 'dtype': 'float64' } ),
70+
empty( [ 2 ], { 'dtype': 'float32' } ),
71+
empty( [ 2 ], { 'dtype': 'int32' } ),
72+
empty( [ 2 ], { 'dtype': 'complex128' } ),
73+
empty( [ 2 ], { 'dtype': 'generic' } )
74+
];
75+
76+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
77+
78+
b.tic();
79+
for ( i = 0; i < b.iterations; i++ ) {
80+
out = toFlippedud( values[ i%values.length ] );
81+
if ( typeof out !== 'object' ) {
82+
b.fail( 'should return an ndarray' );
83+
}
84+
}
85+
b.toc();
86+
if ( !isndarrayLike( out ) ) {
87+
b.fail( 'should return an ndarray' );
88+
}
89+
b.pass( 'benchmark finished' );
90+
b.end();
91+
});
92+
93+
bench( pkg+'::2d,base', function benchmark( b ) {
94+
var values;
95+
var out;
96+
var i;
97+
98+
values = [
99+
baseEmpty( 'float64', [ 2, 2 ], 'row-major' ),
100+
baseEmpty( 'float32', [ 2, 2 ], 'row-major' ),
101+
baseEmpty( 'int32', [ 2, 2 ], 'row-major' ),
102+
baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ),
103+
baseEmpty( 'generic', [ 2, 2 ], 'row-major' )
104+
];
105+
106+
b.tic();
107+
for ( i = 0; i < b.iterations; i++ ) {
108+
out = toFlippedud( values[ i%values.length ] );
109+
if ( typeof out !== 'object' ) {
110+
b.fail( 'should return an ndarray' );
111+
}
112+
}
113+
b.toc();
114+
if ( !isndarrayLike( out ) ) {
115+
b.fail( 'should return an ndarray' );
116+
}
117+
b.pass( 'benchmark finished' );
118+
b.end();
119+
});
120+
121+
bench( pkg+'::2d,non-base', function benchmark( b ) {
122+
var values;
123+
var out;
124+
var i;
125+
126+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
127+
128+
values = [
129+
empty( [ 2, 2 ], { 'dtype': 'float64' } ),
130+
empty( [ 2, 2 ], { 'dtype': 'float32' } ),
131+
empty( [ 2, 2 ], { 'dtype': 'int32' } ),
132+
empty( [ 2, 2 ], { 'dtype': 'complex128' } ),
133+
empty( [ 2, 2 ], { 'dtype': 'generic' } )
134+
];
135+
136+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
137+
138+
b.tic();
139+
for ( i = 0; i < b.iterations; i++ ) {
140+
out = toFlippedud( values[ i%values.length ] );
141+
if ( typeof out !== 'object' ) {
142+
b.fail( 'should return an ndarray' );
143+
}
144+
}
145+
b.toc();
146+
if ( !isndarrayLike( out ) ) {
147+
b.fail( 'should return an ndarray' );
148+
}
149+
b.pass( 'benchmark finished' );
150+
b.end();
151+
});
152+
153+
bench( pkg+'::3d,base', function benchmark( b ) {
154+
var values;
155+
var out;
156+
var i;
157+
158+
values = [
159+
baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ),
160+
baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ),
161+
baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ),
162+
baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ),
163+
baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' )
164+
];
165+
166+
b.tic();
167+
for ( i = 0; i < b.iterations; i++ ) {
168+
out = toFlippedud( values[ i%values.length ] );
169+
if ( typeof out !== 'object' ) {
170+
b.fail( 'should return an ndarray' );
171+
}
172+
}
173+
b.toc();
174+
if ( !isndarrayLike( out ) ) {
175+
b.fail( 'should return an ndarray' );
176+
}
177+
b.pass( 'benchmark finished' );
178+
b.end();
179+
});
180+
181+
bench( pkg+'::3d,non-base', function benchmark( b ) {
182+
var values;
183+
var out;
184+
var i;
185+
186+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
187+
188+
values = [
189+
empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ),
190+
empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ),
191+
empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ),
192+
empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ),
193+
empty( [ 2, 2, 2 ], { 'dtype': 'generic' } )
194+
];
195+
196+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
197+
198+
b.tic();
199+
for ( i = 0; i < b.iterations; i++ ) {
200+
out = toFlippedud( values[ i%values.length ] );
201+
if ( typeof out !== 'object' ) {
202+
b.fail( 'should return an ndarray' );
203+
}
204+
}
205+
b.toc();
206+
if ( !isndarrayLike( out ) ) {
207+
b.fail( 'should return an ndarray' );
208+
}
209+
b.pass( 'benchmark finished' );
210+
b.end();
211+
});

0 commit comments

Comments
 (0)