Skip to content

Commit 2e435d6

Browse files
committed
Release v0.2.0
1 parent 6fad775 commit 2e435d6

File tree

4 files changed

+163
-14
lines changed

4 files changed

+163
-14
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ For more information on the project, filing bug reports and feature requests, an
200200

201201
---
202202

203-
## License
204-
205-
See [LICENSE][stdlib-license].
206-
207-
208203
## Copyright
209204

210205
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
@@ -220,8 +215,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
220215
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-fancy-slice.svg
221216
[npm-url]: https://npmjs.org/package/@stdlib/array-base-fancy-slice
222217

223-
[test-image]: https://github.com/stdlib-js/array-base-fancy-slice/actions/workflows/test.yml/badge.svg?branch=v0.1.0
224-
[test-url]: https://github.com/stdlib-js/array-base-fancy-slice/actions/workflows/test.yml?query=branch:v0.1.0
218+
[test-image]: https://github.com/stdlib-js/array-base-fancy-slice/actions/workflows/test.yml/badge.svg?branch=v0.2.0
219+
[test-url]: https://github.com/stdlib-js/array-base-fancy-slice/actions/workflows/test.yml?query=branch:v0.2.0
225220

226221
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-fancy-slice/main.svg
227222
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-fancy-slice?branch=main
@@ -251,8 +246,6 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
251246
[esm-readme]: https://github.com/stdlib-js/array-base-fancy-slice/blob/esm/README.md
252247
[branches-url]: https://github.com/stdlib-js/array-base-fancy-slice/blob/main/branches.md
253248

254-
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-fancy-slice/main/LICENSE
255-
256249
[@stdlib/slice/ctor]: https://github.com/stdlib-js/slice-ctor
257250

258251
[@stdlib/array/dtype]: https://github.com/stdlib-js/array-dtype

dist/index.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
1-
"use strict";var v=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var c=v(function(w,o){
2-
var s=require('@stdlib/slice-base-normalize-slice/dist'),d=require('@stdlib/slice-base-length/dist'),g=require('@stdlib/array-base-zeros/dist'),q=require('@stdlib/array-dtype/dist'),f=require('@stdlib/blas-base-gcopy/dist').ndarray,p=require('@stdlib/error-tools-fmtprodmsg/dist');function y(e,r,l){var t,i,a,u,n;if(i=e.length,a=s(r,i,!0),a.code){if(l)throw new RangeError(p("invalid argument. Slice exceeds array bounds. Array length: %d.",i));a=s(r,i,!1)}return n=d(a),u=q(e),u==="generic"||u===null?t=g(n):t=new e.constructor(n),f(n,e,a.step,a.start,t,1,0),t}o.exports=y
3-
});var h=c();module.exports=h;
41
/** @license Apache-2.0 */
5-
//# sourceMappingURL=index.js.map
2+
3+
'use strict';
4+
5+
/**
6+
* Return a shallow copy of a portion of an array.
7+
*
8+
* @module @stdlib/array-base-fancy-slice
9+
*
10+
* @example
11+
* var Slice = require( '@stdlib/slice-ctor' );
12+
* var slice = require( '@stdlib/array-base-fancy-slice' );
13+
*
14+
* var x = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
15+
*
16+
* var s = new Slice( null, null, -2 );
17+
* // returns <Slice>
18+
*
19+
* var y = slice( x, s, false );
20+
* // returns [ 8, 6, 4, 2 ]
21+
*
22+
* var out = ( y === x );
23+
* // returns false
24+
*
25+
* @example
26+
* var Int32Array = require( '@stdlib/array-int32' );
27+
* var Slice = require( '@stdlib/slice-ctor' );
28+
* var slice = require( '@stdlib/array-base-fancy-slice' );
29+
*
30+
* var x = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
31+
*
32+
* var s = new Slice( null, null, -2 );
33+
* // returns <Slice>
34+
*
35+
* var y = slice( x, s, false );
36+
* // returns <Int32Array>[ 8, 6, 4, 2 ]
37+
*
38+
* var out = ( y === x );
39+
* // returns false
40+
*/
41+
42+
// MODULES //
43+
44+
var main = require( './main.js' );
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = main;

dist/main.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 normalizeSlice = require( '@stdlib/slice-base-normalize-slice' );
24+
var sliceLength = require( '@stdlib/slice-base-length' );
25+
var zeros = require( '@stdlib/array-base-zeros' );
26+
var dtype = require( '@stdlib/array-dtype' );
27+
var gcopy = require( '@stdlib/blas-base-gcopy' ).ndarray;
28+
var format = require( '@stdlib/string-format' );
29+
30+
31+
// MODULES //
32+
33+
/**
34+
* Returns a shallow copy of a portion of an array.
35+
*
36+
* @param {Collection} x - input array
37+
* @param {Slice} s - slice object
38+
* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking
39+
* @throws {RangeError} slice exceeds array bounds
40+
* @returns {Collection} output array
41+
*
42+
* @example
43+
* var Slice = require( '@stdlib/slice-ctor' );
44+
*
45+
* var x = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
46+
*
47+
* var s = new Slice( null, null, -2 );
48+
* // returns <Slice>
49+
*
50+
* var y = slice( x, s, false );
51+
* // returns [ 8, 6, 4, 2 ]
52+
*
53+
* var out = ( y === x );
54+
* // returns false
55+
*
56+
* @example
57+
* var Int32Array = require( '@stdlib/array-int32' );
58+
* var Slice = require( '@stdlib/slice-ctor' );
59+
*
60+
* var x = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
61+
*
62+
* var s = new Slice( null, null, -2 );
63+
* // returns <Slice>
64+
*
65+
* var y = slice( x, s, false );
66+
* // returns <Int32Array>[ 8, 6, 4, 2 ]
67+
*
68+
* var out = ( y === x );
69+
* // returns false
70+
*/
71+
function slice( x, s, strict ) {
72+
var out;
73+
var len;
74+
var ns;
75+
var dt;
76+
var N;
77+
78+
len = x.length;
79+
80+
// Normalize the slice object base on the array length:
81+
ns = normalizeSlice( s, len, true );
82+
83+
// Check whether the slice exceeds the array bounds...
84+
if ( ns.code ) {
85+
if ( strict ) {
86+
throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array length: %d.', len ) );
87+
}
88+
// Normalize again, this time allowing for out-of-bounds indices:
89+
ns = normalizeSlice( s, len, false );
90+
}
91+
// Compute the slice length:
92+
N = sliceLength( ns );
93+
94+
// Resolve the input array data type:
95+
dt = dtype( x );
96+
97+
// Allocate an output array:
98+
if ( dt === 'generic' || dt === null ) { // note: if we were provided an "exotic" array object, fallback to always returning a "generic" array
99+
out = zeros( N );
100+
} else {
101+
out = new x.constructor( N ); // note: this should accommodate array species which inherit from built-in/known constructors and we assume that all constructors support providing a length argument
102+
}
103+
// Copy elements to the output array:
104+
gcopy( N, x, ns.step, ns.start, out, 1, 0 );
105+
106+
return out;
107+
}
108+
109+
110+
// EXPORTS //
111+
112+
module.exports = slice;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stdlib/array-base-fancy-slice",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Return a shallow copy of a portion of an array.",
55
"license": "Apache-2.0",
66
"author": {

0 commit comments

Comments
 (0)