@stdlib/ndarray-base-bind2vind 0.0.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -175,307 +175,3 @@
175
175
  of your accepting any such warranty or additional liability.
176
176
 
177
177
  END OF TERMS AND CONDITIONS
178
-
179
-
180
-
181
- Boost Software License - Version 1.0 - August 17th, 2003
182
-
183
- Permission is hereby granted, free of charge, to any person or organization
184
- obtaining a copy of the software and accompanying documentation covered by this
185
- license (the "Software") to use, reproduce, display, distribute, execute, and
186
- transmit the Software, and to prepare derivative works of the Software, and to
187
- permit third-parties to whom the Software is furnished to do so, all subject to
188
- the following:
189
-
190
- The copyright notices in the Software and this entire statement, including the
191
- above license grant, this restriction and the following disclaimer, must be
192
- included in all copies of the Software, in whole or in part, and all derivative
193
- works of the Software, unless such copies or derivative works are solely in the
194
- form of machine-executable object code generated by a source language processor.
195
-
196
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
198
- FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
199
- COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES
200
- OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
201
- OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
202
-
203
-
204
-
205
-
206
- DEPENDENCIES
207
-
208
- The library links against the following external libraries, which have their own
209
- licenses:
210
-
211
- * OpenBLAS <https://raw.githubusercontent.com/xianyi/OpenBLAS/
212
- def146efed8d5908ea04e22668feeab7099599a0/LICENSE>
213
-
214
- Copyright (c) 2011-2014, The OpenBLAS Project
215
- All rights reserved.
216
-
217
- Redistribution and use in source and binary forms, with or without
218
- modification, are permitted provided that the following conditions are
219
- met:
220
-
221
- 1. Redistributions of source code must retain the above copyright
222
- notice, this list of conditions and the following disclaimer.
223
-
224
- 2. Redistributions in binary form must reproduce the above copyright
225
- notice, this list of conditions and the following disclaimer in
226
- the documentation and/or other materials provided with the
227
- distribution.
228
-
229
- 3. Neither the name of the OpenBLAS project nor the names of
230
- its contributors may be used to endorse or promote products
231
- derived from this software without specific prior written
232
- permission.
233
-
234
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
235
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
237
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
238
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
239
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
240
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
243
- THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244
-
245
-
246
- * Electron <https://raw.githubusercontent.com/electron/electron/
247
- c4cfb3e7110266b9d7ad80e1ae097c4db564501c/LICENSE>
248
-
249
- Copyright (c) 2013-2017 GitHub Inc.
250
-
251
- Permission is hereby granted, free of charge, to any person obtaining
252
- a copy of this software and associated documentation files (the
253
- "Software"), to deal in the Software without restriction, including
254
- without limitation the rights to use, copy, modify, merge, publish,
255
- distribute, sublicense, and/or sell copies of the Software, and to
256
- permit persons to whom the Software is furnished to do so, subject to
257
- the following conditions:
258
-
259
- The above copyright notice and this permission notice shall be
260
- included in all copies or substantial portions of the Software.
261
-
262
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
263
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
264
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
265
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
266
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
267
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
268
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
269
-
270
-
271
- * Boost <http://www.boost.org/LICENSE_1_0.txt>
272
-
273
- Boost Software License - Version 1.0 - August 17th, 2003
274
-
275
- Permission is hereby granted, free of charge, to any person or organization
276
- obtaining a copy of the software and accompanying documentation covered by
277
- this license (the "Software") to use, reproduce, display, distribute,
278
- execute, and transmit the Software, and to prepare derivative works of the
279
- Software, and to permit third-parties to whom the Software is furnished to
280
- do so, all subject to the following:
281
-
282
- The copyright notices in the Software and this entire statement, including
283
- the above license grant, this restriction and the following disclaimer,
284
- must be included in all copies of the Software, in whole or in part, and
285
- all derivative works of the Software, unless such copies or derivative
286
- works are solely in the form of machine-executable object code generated by
287
- a source language processor.
288
-
289
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
290
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
291
- FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
292
- SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
293
- FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
294
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
295
- DEALINGS IN THE SOFTWARE.
296
-
297
-
298
- * Cephes <http://www.netlib.org/cephes/readme>
299
-
300
- Copyright (c) 1984-2000 Stephen L. Moshier
301
-
302
- Some software in this archive may be from the book _Methods and Programs for
303
- Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989)
304
- or from the Cephes Mathematical Library, a commercial product. In either event,
305
- it is copyrighted by the author. What you see here may be used freely but it
306
- comes with no support or guarantee.
307
-
308
- Stephen L. Moshier
309
- moshier@na-net.ornl.gov
310
-
311
-
312
-
313
- ATTRIBUTION
314
-
315
- The library contains implementations from the following external libraries,
316
- which have their own licenses:
317
-
318
- * FreeBSD <https://svnweb.freebsd.org/>
319
-
320
- Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
321
-
322
- Developed at SunPro, a Sun Microsystems, Inc. business.
323
- Permission to use, copy, modify, and distribute this
324
- software is freely granted, provided that this notice
325
- is preserved.
326
-
327
-
328
- * FDLIBM <http://www.netlib.org/fdlibm/>
329
-
330
- Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
331
-
332
- Developed at SunPro, a Sun Microsystems, Inc. business.
333
- Permission to use, copy, modify, and distribute this
334
- software is freely granted, provided that this notice
335
- is preserved.
336
-
337
-
338
- * Go <https://raw.githubusercontent.com/golang/go/master/LICENSE>
339
-
340
- Copyright (c) 2009 The Go Authors. All rights reserved.
341
-
342
- Redistribution and use in source and binary forms, with or without
343
- modification, are permitted provided that the following conditions are
344
- met:
345
-
346
- * Redistributions of source code must retain the above copyright
347
- notice, this list of conditions and the following disclaimer.
348
- * Redistributions in binary form must reproduce the above
349
- copyright notice, this list of conditions and the following disclaimer
350
- in the documentation and/or other materials provided with the
351
- distribution.
352
- * Neither the name of Google Inc. nor the names of its
353
- contributors may be used to endorse or promote products derived from
354
- this software without specific prior written permission.
355
-
356
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
357
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
358
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
359
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
360
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
361
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
362
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
363
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
365
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
366
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367
-
368
-
369
- * SLATEC Common Mathematical Library <http://www.netlib.no/netlib/slatec/>
370
-
371
- Public domain.
372
-
373
-
374
- * ESLint <https://raw.githubusercontent.com/eslint/eslint/master/LICENSE>
375
-
376
- Copyright JS Foundation and other contributors, https://js.foundation
377
-
378
- Permission is hereby granted, free of charge, to any person obtaining a copy
379
- of this software and associated documentation files (the "Software"), to deal
380
- in the Software without restriction, including without limitation the rights
381
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
382
- copies of the Software, and to permit persons to whom the Software is
383
- furnished to do so, subject to the following conditions:
384
-
385
- The above copyright notice and this permission notice shall be included in
386
- all copies or substantial portions of the Software.
387
-
388
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
389
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
390
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
391
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
392
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
393
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
394
- THE SOFTWARE.
395
-
396
-
397
- * StatsFuns.jl <https://raw.githubusercontent.com/JuliaStats/StatsFuns.jl/
398
- e66dd973650c375bc1739c820e5b96bb5bd000a8/LICENSE.md>
399
-
400
- Copyright (c) 2015: Dahua Lin.
401
-
402
- Permission is hereby granted, free of charge, to any person obtaining
403
- a copy of this software and associated documentation files (the
404
- "Software"), to deal in the Software without restriction, including
405
- without limitation the rights to use, copy, modify, merge, publish,
406
- distribute, sublicense, and/or sell copies of the Software, and to
407
- permit persons to whom the Software is furnished to do so, subject to
408
- the following conditions:
409
-
410
- The above copyright notice and this permission notice shall be
411
- included in all copies or substantial portions of the Software.
412
-
413
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
414
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
415
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
416
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
417
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
418
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
419
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
420
-
421
-
422
- * SpecialFunctions.jl <https://raw.githubusercontent.com/JuliaMath/
423
- SpecialFunctions.jl/02a173fbe24a61c4b392aec17a9764ac5727feb1/LICENSE>
424
-
425
- The MIT License (MIT)
426
-
427
- Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others:
428
-
429
- https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors
430
-
431
- Permission is hereby granted, free of charge, to any person obtaining a copy
432
- of this software and associated documentation files (the "Software"), to deal
433
- in the Software without restriction, including without limitation the rights
434
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
435
- copies of the Software, and to permit persons to whom the Software is
436
- furnished to do so, subject to the following conditions:
437
-
438
- The above copyright notice and this permission notice shall be included in all
439
- copies or substantial portions of the Software.
440
-
441
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
442
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
443
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
444
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
445
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
446
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
447
- SOFTWARE.
448
-
449
-
450
- * MT19937 <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/
451
- mt19937ar.c>
452
-
453
- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
454
- All rights reserved.
455
-
456
- Redistribution and use in source and binary forms, with or without
457
- modification, are permitted provided that the following conditions
458
- are met:
459
-
460
- 1. Redistributions of source code must retain the above copyright
461
- notice, this list of conditions and the following disclaimer.
462
-
463
- 2. Redistributions in binary form must reproduce the above copyright
464
- notice, this list of conditions and the following disclaimer in the
465
- documentation and/or other materials provided with the distribution.
466
-
467
- 3. The names of its contributors may not be used to endorse or promote
468
- products derived from this software without specific prior written
469
- permission.
470
-
471
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
472
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
473
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
474
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
475
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
476
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
477
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
478
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
479
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
480
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
481
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2022 The Stdlib Authors.
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -18,6 +18,17 @@ limitations under the License.
18
18
 
19
19
  -->
20
20
 
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
21
32
  # bind2vind
22
33
 
23
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
@@ -66,11 +77,12 @@ var idx = bind2vind( shape, strides, offset, order, 7, 'throw' );
66
77
  // returns 1
67
78
  ```
68
79
 
69
- The function supports the following `modes`:
80
+ The function supports the following modes:
70
81
 
71
- - `throw`: specifies that the function should throw an error when a linear index exceeds array dimensions.
72
- - `wrap`: specifies that the function should wrap around a linear index exceeding array dimensions using modulo arithmetic.
73
- - `clamp`: specifies that the function should set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index.
82
+ - **throw**: specifies that the function should throw an error when a linear index exceeds array dimensions.
83
+ - **normalize**: specifies that the function should normalize negative indices and should throw an error when a linear index exceeds array dimensions.
84
+ - **wrap**: specifies that the function should wrap around a linear index exceeding array dimensions using modulo arithmetic.
85
+ - **clamp**: specifies that the function should set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index.
74
86
 
75
87
  ```javascript
76
88
  var shape = [ 2, 2 ];
@@ -202,7 +214,7 @@ See [LICENSE][stdlib-license].
202
214
 
203
215
  ## Copyright
204
216
 
205
- Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
217
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
206
218
 
207
219
  </section>
208
220
 
@@ -215,8 +227,8 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
215
227
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-bind2vind.svg
216
228
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-bind2vind
217
229
 
218
- [test-image]: https://github.com/stdlib-js/ndarray-base-bind2vind/actions/workflows/test.yml/badge.svg
219
- [test-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/actions/workflows/test.yml
230
+ [test-image]: https://github.com/stdlib-js/ndarray-base-bind2vind/actions/workflows/test.yml/badge.svg?branch=v0.2.0
231
+ [test-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/actions/workflows/test.yml?query=branch:v0.2.0
220
232
 
221
233
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-bind2vind/main.svg
222
234
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-bind2vind?branch=main
@@ -228,19 +240,23 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
228
240
 
229
241
  -->
230
242
 
243
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
244
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
245
+
246
+ [stdlib]: https://github.com/stdlib-js/stdlib
247
+
248
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
249
+
231
250
  [umd]: https://github.com/umdjs/umd
232
251
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
233
252
 
234
253
  [deno-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/deno
254
+ [deno-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/deno/README.md
235
255
  [umd-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/umd
256
+ [umd-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/umd/README.md
236
257
  [esm-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/tree/esm
237
-
238
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
239
- [chat-url]: https://gitter.im/stdlib-js/stdlib/
240
-
241
- [stdlib]: https://github.com/stdlib-js/stdlib
242
-
243
- [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
258
+ [esm-readme]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/esm/README.md
259
+ [branches-url]: https://github.com/stdlib-js/ndarray-base-bind2vind/blob/main/branches.md
244
260
 
245
261
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-bind2vind/main/LICENSE
246
262
 
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import bind2vind from '../docs/types/index';
3
+ export = bind2vind;
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var q=function(u,t){return function(){return t||u((t={exports:{}}).exports,t),t.exports}};var c=q(function(p,i){
2
+ var g=require('@stdlib/error-tools-fmtprodmsg/dist'),o=require('@stdlib/math-base-special-trunc/dist'),m=require('@stdlib/math-base-special-abs/dist');function w(u,t,j,b,r,v){var l,e,s,f,n,a;for(l=u.length,e=1,a=0;a<l;a++)e*=u[a];if(v==="clamp")r<0?r=0:r>=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(v==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(g('0i35E',e,r));if(s=0,b==="column-major"){for(a=l-1;a>=0;a--)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}for(a=0;a<l;a++)n=t[a],n<0?(f=o(r/n),r-=f*n,f+=u[a]-1):(f=o(r/n),r-=f*n),s+=f*m(n);return s}i.exports=w
3
+ });var y=c();module.exports=y;
4
+ /** @license Apache-2.0 */
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string-format' );\nvar trunc = require( '@stdlib/math-base-special-trunc' );\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Converts a linear index in an underlying data buffer to a linear index in an array view.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @param {integer} idx - linear index in an underlying data buffer\n* @param {string} mode - specifies how to handle a linear index which exceeds array dimensions\n* @throws {RangeError} linear index must not exceed array dimensions\n* @returns {NonNegativeInteger} linear index in an array view\n*\n* @example\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\nfunction bind2vind( shape, strides, offset, order, idx, mode ) {\n\tvar ndims;\n\tvar len;\n\tvar ind;\n\tvar k;\n\tvar s;\n\tvar i;\n\n\tndims = shape.length;\n\tlen = 1;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tlen *= shape[ i ];\n\t}\n\tif ( mode === 'clamp' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx = 0;\n\t\t} else if ( idx >= len ) {\n\t\t\tidx = len - 1;\n\t\t}\n\t} else if ( mode === 'wrap' ) {\n\t\tif ( idx < 0 ) {\n\t\t\tidx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len\n\t\t\tif ( idx < 0 ) {\n\t\t\t\tidx %= len;\n\t\t\t\tif ( idx !== 0 ) {\n\t\t\t\t\tidx += len;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( idx >= len ) {\n\t\t\tidx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len\n\t\t\tif ( idx >= len ) {\n\t\t\t\tidx %= len;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ( mode === 'normalize' && idx < 0 ) {\n\t\t\tidx += len;\n\t\t}\n\t\tif ( idx < 0 || idx >= len ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );\n\t\t}\n\t}\n\t// The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...\n\tind = 0;\n\tif ( order === 'column-major' ) {\n\t\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\t\ts = strides[ i ];\n\t\t\tif ( s < 0 ) {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t\tk += shape[ i ] - 1;\n\t\t\t} else {\n\t\t\t\tk = trunc( idx/s );\n\t\t\t\tidx -= k * s;\n\t\t\t}\n\t\t\tind += k * abs( s );\n\t\t}\n\t\treturn ind;\n\t}\n\t// Case: row-major\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\ts = strides[ i ];\n\t\tif ( s < 0 ) {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t\tk += shape[ i ] - 1;\n\t\t} else {\n\t\t\tk = trunc( idx/s );\n\t\t\tidx -= k * s;\n\t\t}\n\t\tind += k * abs( s );\n\t}\n\treturn ind;\n}\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Convert a linear index in an underlying data buffer to a linear index in an array view.\n*\n* @module @stdlib/ndarray-base-bind2vind\n*\n* @example\n* var bind2vind = require( '@stdlib/ndarray-base-bind2vind' );\n*\n* var shape = [ 3, 3 ];\n* var strides = [ -3, 1 ];\n* var offset = 6;\n* var order = 'row-major';\n* var mode = 'throw';\n*\n* var ind = bind2vind( shape, strides, offset, order, 7, mode );\n* // returns 1\n*/\n\n// MODULES //\n\nvar bind2vind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = bind2vind;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA2BnD,SAASC,EAAWC,EAAOC,EAASC,EAAQC,EAAOC,EAAKC,EAAO,CAC9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,IAFAL,EAAQN,EAAM,OACdO,EAAM,EACAI,EAAI,EAAGA,EAAIL,EAAOK,IACvBJ,GAAOP,EAAOW,CAAE,EAEjB,GAAKN,IAAS,QACRD,EAAM,EACVA,EAAM,EACKA,GAAOG,IAClBH,EAAMG,EAAM,WAEFF,IAAS,OACfD,EAAM,GACVA,GAAOG,EACFH,EAAM,IACVA,GAAOG,EACFH,IAAQ,IACZA,GAAOG,KAGEH,GAAOG,IAClBH,GAAOG,EACFH,GAAOG,IACXH,GAAOG,YAIJF,IAAS,aAAeD,EAAM,IAClCA,GAAOG,GAEHH,EAAM,GAAKA,GAAOG,EACtB,MAAM,IAAI,WAAYX,EAAQ,gHAAiHW,EAAKH,CAAI,CAAE,EAK5J,GADAI,EAAM,EACDL,IAAU,eAAiB,CAC/B,IAAMQ,EAAIL,EAAM,EAAGK,GAAK,EAAGA,IAC1BD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAEA,IAAMG,EAAI,EAAGA,EAAIL,EAAOK,IACvBD,EAAIT,EAASU,CAAE,EACVD,EAAI,GACRD,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,EACXD,GAAKT,EAAOW,CAAE,EAAI,IAElBF,EAAIZ,EAAOO,EAAIM,CAAE,EACjBN,GAAOK,EAAIC,GAEZF,GAAOC,EAAIX,EAAKY,CAAE,EAEnB,OAAOF,CACR,CAKAb,EAAO,QAAUI,ICzFjB,IAAIa,EAAY,IAKhB,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "format", "trunc", "abs", "bind2vind", "shape", "strides", "offset", "order", "idx", "mode", "ndims", "len", "ind", "k", "s", "i", "bind2vind"]
7
+ }
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
  /// <reference types="node"/>
@@ -46,7 +46,7 @@ import { Mode, Order } from '@stdlib/types/ndarray';
46
46
  * var ind = bind2vind( shape, strides, offset, order, 7, mode );
47
47
  * // returns 1
48
48
  */
49
- declare function bind2vind( shape: ArrayLike<number>, strides: ArrayLike<number>, offset: number, order: Order, idx: number, mode: Mode ): number; // tslint-disable-line max-line-length
49
+ declare function bind2vind( shape: ArrayLike<number>, strides: ArrayLike<number>, offset: number, order: Order, idx: number, mode: Mode ): number;
50
50
 
51
51
 
52
52
  // EXPORTS //
@@ -33,7 +33,7 @@ extern "C" {
33
33
  /**
34
34
  * Converts a linear index in an underlying data buffer to a linear index in an array view.
35
35
  */
36
- int64_t stdlib_ndarray_bind2vind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode );
36
+ int64_t stdlib_ndarray_bind2vind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode );
37
37
 
38
38
  #ifdef __cplusplus
39
39
  }
package/lib/main.js CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
+ var format = require( '@stdlib/string-format' );
23
24
  var trunc = require( '@stdlib/math-base-special-trunc' );
24
25
  var abs = require( '@stdlib/math-base-special-abs' );
25
26
 
@@ -82,8 +83,13 @@ function bind2vind( shape, strides, offset, order, idx, mode ) {
82
83
  idx %= len;
83
84
  }
84
85
  }
85
- } else if ( idx < 0 || idx >= len ) {
86
- throw new RangeError( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: ' + len + '. Value: `' + idx + '`.' );
86
+ } else {
87
+ if ( mode === 'normalize' && idx < 0 ) {
88
+ idx += len;
89
+ }
90
+ if ( idx < 0 || idx >= len ) {
91
+ throw new RangeError( format( 'invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.', len, idx ) );
92
+ }
87
93
  }
88
94
  // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...
89
95
  ind = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-bind2vind",
3
- "version": "0.0.6",
3
+ "version": "0.2.0",
4
4
  "description": "Convert a linear index in an underlying data buffer to a linear index in an array view.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -39,24 +39,27 @@
39
39
  "url": "https://github.com/stdlib-js/stdlib/issues"
40
40
  },
41
41
  "dependencies": {
42
- "@stdlib/math-base-special-abs": "^0.0.x",
43
- "@stdlib/math-base-special-trunc": "^0.0.x",
44
- "@stdlib/ndarray-index-modes": "^0.0.x",
45
- "@stdlib/ndarray-orders": "^0.0.x",
46
- "@stdlib/types": "^0.0.x",
47
- "@stdlib/utils-library-manifest": "^0.0.x"
42
+ "@stdlib/math-base-special-abs": "^0.2.0",
43
+ "@stdlib/math-base-special-trunc": "^0.2.0",
44
+ "@stdlib/ndarray-index-modes": "^0.2.0",
45
+ "@stdlib/ndarray-orders": "^0.2.0",
46
+ "@stdlib/string-format": "^0.2.0",
47
+ "@stdlib/types": "^0.3.1",
48
+ "@stdlib/utils-library-manifest": "^0.2.0",
49
+ "@stdlib/error-tools-fmtprodmsg": "^0.1.1"
48
50
  },
49
51
  "devDependencies": {
50
- "@stdlib/assert-is-integer": "^0.0.x",
51
- "@stdlib/bench": "^0.0.x",
52
- "@stdlib/math-base-special-floor": "^0.0.x",
53
- "@stdlib/ndarray-base-numel": "^0.0.x",
54
- "@stdlib/ndarray-base-shape2strides": "^0.0.x",
55
- "@stdlib/ndarray-base-strides2offset": "^0.0.x",
56
- "@stdlib/random-base-randu": "^0.0.x",
52
+ "@stdlib/assert-is-integer": "^0.1.0",
53
+ "@stdlib/math-base-special-floor": "^0.1.1",
54
+ "@stdlib/ndarray-base-numel": "^0.1.1",
55
+ "@stdlib/ndarray-base-shape2strides": "^0.1.1",
56
+ "@stdlib/ndarray-base-strides2offset": "^0.1.1",
57
+ "@stdlib/random-base-randu": "^0.1.0",
57
58
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
58
59
  "istanbul": "^0.4.1",
59
- "tap-spec": "5.x.x"
60
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
61
+ "@stdlib/bench-harness": "^0.2.0",
62
+ "@stdlib/bench": "^0.3.1"
60
63
  },
61
64
  "engines": {
62
65
  "node": ">=0.10.0",
@@ -96,7 +99,7 @@
96
99
  ],
97
100
  "__stdlib__": {},
98
101
  "funding": {
99
- "type": "patreon",
100
- "url": "https://www.patreon.com/athan"
102
+ "type": "opencollective",
103
+ "url": "https://opencollective.com/stdlib"
101
104
  }
102
105
  }
package/src/main.c CHANGED
@@ -27,7 +27,7 @@
27
27
  *
28
28
  * ## Notes
29
29
  *
30
- * - In "error" mode, the function returns `-1` if an index is out-of-bounds.
30
+ * - In "error" and "normalize" modes, the function returns `-1` if an index is out-of-bounds.
31
31
  *
32
32
  * @param ndims number of dimensions
33
33
  * @param shape array shape (dimensions)
@@ -51,40 +51,47 @@
51
51
  * int64_t idx = stdlib_ndarray_bind2vind( ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, 7, STDLIB_NDARRAY_INDEX_ERROR );
52
52
  * // returns 1
53
53
  */
54
- int64_t stdlib_ndarray_bind2vind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, enum STDLIB_NDARRAY_ORDER order, int64_t idx, enum STDLIB_NDARRAY_INDEX_MODE mode ) {
54
+ int64_t stdlib_ndarray_bind2vind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const enum STDLIB_NDARRAY_ORDER order, const int64_t idx, const enum STDLIB_NDARRAY_INDEX_MODE mode ) {
55
+ int64_t index;
55
56
  int64_t len;
56
57
  int64_t ind;
57
58
  int64_t s;
58
59
  int64_t k;
59
60
  int64_t i;
60
61
 
62
+ index = idx;
61
63
  len = 1;
62
64
  for ( i = 0; i < ndims; i++ ) {
63
65
  len *= shape[ i ];
64
66
  }
65
67
  if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) {
66
- if ( idx < 0 ) {
67
- idx = 0;
68
- } else if ( idx >= len ) {
69
- idx = len - 1;
68
+ if ( index < 0 ) {
69
+ index = 0;
70
+ } else if ( index >= len ) {
71
+ index = len - 1;
70
72
  }
71
73
  } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) {
72
- if ( idx < 0 ) {
73
- idx += len; // slight optimization to avoid modulo arithmetic when |idx| <= len
74
- if ( idx < 0 ) {
75
- idx -= len*( (int64_t)( idx/len ) ); // this is equivalent to `idx mod len`, where the result has same sign as dividend (i.e., `idx`); cannot use `%` as the sign of the result is implementation defined in C
76
- if ( idx != 0 ) {
77
- idx += len;
74
+ if ( index < 0 ) {
75
+ index += len; // slight optimization to avoid modulo arithmetic when |index| <= len
76
+ if ( index < 0 ) {
77
+ index -= len*( (int64_t)( index/len ) ); // this is equivalent to `index mod len`, where the result has same sign as dividend (i.e., `index`); cannot use `%` as the sign of the result is implementation defined in C
78
+ if ( index != 0 ) {
79
+ index += len;
78
80
  }
79
81
  }
80
- } else if ( idx >= len ) {
81
- idx -= len; // slight optimization to avoid modulo arithmetic when len < idx <= 2*len
82
- if ( idx >= len ) {
83
- idx %= len;
82
+ } else if ( index >= len ) {
83
+ index -= len; // slight optimization to avoid modulo arithmetic when len < index <= 2*len
84
+ if ( index >= len ) {
85
+ index %= len;
84
86
  }
85
87
  }
86
- } else if ( idx < 0 || idx >= len ) {
87
- return -1;
88
+ } else {
89
+ if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && index < 0 ) {
90
+ index += len;
91
+ }
92
+ if ( index < 0 || index >= len ) {
93
+ return -1;
94
+ }
88
95
  }
89
96
  // The approach which follows is to resolve a buffer index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the array view (i.e., where all strides are positive and offset is 0)...
90
97
  ind = 0;
@@ -92,12 +99,12 @@ int64_t stdlib_ndarray_bind2vind( int64_t ndims, int64_t *shape, int64_t *stride
92
99
  for ( i = ndims-1; i >= 0; i-- ) {
93
100
  s = strides[ i ];
94
101
  if ( s < 0 ) {
95
- k = idx / s; // truncates
96
- idx -= k * s;
102
+ k = index / s; // truncates
103
+ index -= k * s;
97
104
  k += shape[ i ] - 1;
98
105
  } else {
99
- k = idx / s; // cppcheck-suppress zerodivcond // truncates
100
- idx -= k * s;
106
+ k = index / s; // cppcheck-suppress zerodivcond // truncates
107
+ index -= k * s;
101
108
  }
102
109
  ind += k * llabs( s );
103
110
  }
@@ -107,12 +114,12 @@ int64_t stdlib_ndarray_bind2vind( int64_t ndims, int64_t *shape, int64_t *stride
107
114
  for ( i = 0; i < ndims; i++ ) {
108
115
  s = strides[ i ];
109
116
  if ( s < 0 ) {
110
- k = idx / s; // truncates
111
- idx -= k * s;
117
+ k = index / s; // truncates
118
+ index -= k * s;
112
119
  k += shape[ i ] - 1;
113
120
  } else {
114
- k = idx / s; // cppcheck-suppress zerodivcond // truncates
115
- idx -= k * s;
121
+ k = index / s; // cppcheck-suppress zerodivcond // truncates
122
+ index -= k * s;
116
123
  }
117
124
  ind += k * llabs( s );
118
125
  }
package/docs/repl.txt DELETED
@@ -1,48 +0,0 @@
1
-
2
- {{alias}}( shape, strides, offset, order, idx, mode )
3
- Converts a linear index in an underlying data buffer to a linear index in an
4
- array view.
5
-
6
- Parameters
7
- ----------
8
- shape: ArrayLike
9
- Array shape.
10
-
11
- strides: ArrayLike
12
- Stride array.
13
-
14
- offset: integer
15
- Location of the first indexed value based on the stride array.
16
-
17
- order: string
18
- Specifies whether an array is row-major (C-style) or column-major
19
- (Fortran-style).
20
-
21
- idx: integer
22
- Linear index in an underlying data buffer.
23
-
24
- mode: string
25
- Specifies how to handle a linear index which exceeds array dimensions.
26
- If equal to 'throw', the function throws an error when a linear index
27
- exceeds array dimensions. If equal to 'wrap', the function wraps around
28
- a linear index exceeding array dimensions using modulo arithmetic. If
29
- equal to 'clamp', the function sets a linear index exceeding array
30
- dimensions to either `0` (minimum linear index) or the maximum linear
31
- index. Default: 'throw'.
32
-
33
- Returns
34
- -------
35
- idx: integer
36
- Linear index in an array view.
37
-
38
- Examples
39
- --------
40
- > var d = [ 3, 3, 3 ];
41
- > var s = [ 9, -3, 1 ];
42
- > var o = 6;
43
- > var idx = {{alias}}( d, s, o, 'row-major', 7, 'throw' )
44
- 1
45
-
46
- See Also
47
- --------
48
-
@@ -1,150 +0,0 @@
1
- /*
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2021 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
- import bind2vind = require( './index' );
20
-
21
-
22
- // TESTS //
23
-
24
- // The function returns a number...
25
- {
26
- const shape = [ 3, 3, 3 ];
27
- const strides = [ 9, 6, 1 ];
28
- const offset = 0;
29
- const order = 'row-major';
30
- const idx = 17;
31
- const mode = 'throw';
32
- bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number
33
- }
34
-
35
- // The function does not compile if provided a first argument which is not an array-like object containing numbers...
36
- {
37
- const strides = [ 9, 6, 1 ];
38
- const offset = 0;
39
- const order = 'row-major';
40
- const idx = 17;
41
- const mode = 'throw';
42
- bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError
43
- bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError
44
- bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError
45
- bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError
46
- bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError
47
- bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError
48
- bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError
49
- bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError
50
- }
51
-
52
- // The function does not compile if provided a second argument which is not an array-like object containing numbers...
53
- {
54
- const shape = [ 3, 3, 3 ];
55
- const offset = 0;
56
- const order = 'row-major';
57
- const idx = 17;
58
- const mode = 'throw';
59
- bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError
60
- bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError
61
- bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError
62
- bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError
63
- bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError
64
- bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError
65
- bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError
66
- bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError
67
- }
68
-
69
- // The function does not compile if provided a third argument which is not a number...
70
- {
71
- const shape = [ 3, 3, 3 ];
72
- const strides = [ 9, 6, 1 ];
73
- const order = 'row-major';
74
- const idx = 17;
75
- const mode = 'throw';
76
- bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError
77
- bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError
78
- bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError
79
- bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError
80
- bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError
81
- bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError
82
- bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError
83
- bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError
84
- }
85
-
86
- // The function does not compile if provided a fourth argument which is not a known array order...
87
- {
88
- const shape = [ 3, 3, 3 ];
89
- const strides = [ 9, 6, 1 ];
90
- const offset = 0;
91
- const idx = 17;
92
- const mode = 'throw';
93
- bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError
94
- bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError
95
- bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError
96
- bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError
97
- bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError
98
- bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError
99
- bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError
100
- bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError
101
- }
102
-
103
- // The function does not compile if provided a fifth argument which is not a number...
104
- {
105
- const shape = [ 3, 3, 3 ];
106
- const strides = [ 9, 6, 1 ];
107
- const offset = 0;
108
- const order = 'row-major';
109
- const mode = 'throw';
110
- bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError
111
- bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError
112
- bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError
113
- bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError
114
- bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError
115
- bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError
116
- bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError
117
- bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError
118
- }
119
-
120
- // The function does not compile if provided a sixth argument which is not a known mode...
121
- {
122
- const shape = [ 3, 3, 3 ];
123
- const strides = [ 9, 6, 1 ];
124
- const offset = 0;
125
- const order = 'row-major';
126
- const idx = 17;
127
- bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError
128
- bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError
129
- bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError
130
- bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError
131
- bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError
132
- bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError
133
- bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError
134
- bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError
135
- }
136
-
137
- // The function does not compile if provided insufficient arguments...
138
- {
139
- const shape = [ 3, 3, 3 ];
140
- const strides = [ 9, 6, 1 ];
141
- const offset = 0;
142
- const order = 'row-major';
143
- const idx = 17;
144
- bind2vind(); // $ExpectError
145
- bind2vind( shape ); // $ExpectError
146
- bind2vind( shape, strides ); // $ExpectError
147
- bind2vind( shape, strides, offset ); // $ExpectError
148
- bind2vind( shape, strides, offset, order ); // $ExpectError
149
- bind2vind( shape, strides, offset, order, idx ); // $ExpectError
150
- }