@stdlib/ndarray-zeros-like 0.0.1 → 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 +0 -304
- package/NOTICE +1 -1
- package/README.md +43 -10
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +129 -45
- package/lib/main.js +41 -24
- package/package.json +41 -34
- package/docs/repl.txt +0 -53
- package/docs/types/test.ts +0 -167
package/docs/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// tslint:disable:max-file-line-count
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
* @license Apache-2.0
|
|
5
3
|
*
|
|
@@ -18,33 +16,50 @@
|
|
|
18
16
|
* limitations under the License.
|
|
19
17
|
*/
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
/* eslint-disable max-lines */
|
|
20
|
+
|
|
21
|
+
// TypeScript Version: 4.1
|
|
22
22
|
|
|
23
23
|
/// <reference types="@stdlib/types"/>
|
|
24
24
|
|
|
25
|
-
import { Shape, Order, ndarray, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType } from '@stdlib/types/ndarray';
|
|
25
|
+
import { Shape, Order, ndarray, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Mode } from '@stdlib/types/ndarray';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Interface describing function options.
|
|
29
29
|
*/
|
|
30
30
|
interface Options {
|
|
31
31
|
/**
|
|
32
|
-
* Array
|
|
32
|
+
* Array shape.
|
|
33
33
|
*
|
|
34
34
|
* ## Notes
|
|
35
35
|
*
|
|
36
|
-
* - If provided, this option overrides the input array's inferred
|
|
36
|
+
* - If provided, this option overrides the input array's inferred shape.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
shape?: Shape | number;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Array
|
|
41
|
+
* Array order (either 'row-major' (C-style) or 'column-major' (Fortran-style)).
|
|
42
42
|
*
|
|
43
43
|
* ## Notes
|
|
44
44
|
*
|
|
45
|
-
* - If provided, this option overrides the input array's inferred
|
|
45
|
+
* - If provided, this option overrides the input array's inferred order.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
order?: Order;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Specifies how to handle a linear index which exceeds array dimensions (default: 'throw').
|
|
51
|
+
*/
|
|
52
|
+
mode?: Mode;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']).
|
|
56
|
+
*/
|
|
57
|
+
submode?: Array<Mode>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Boolean indicating whether an array should be read-only (default: false).
|
|
61
|
+
*/
|
|
62
|
+
readonly?: boolean;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
/**
|
|
@@ -222,10 +237,13 @@ interface OptionsWithDType extends Options {
|
|
|
222
237
|
* @param options - options
|
|
223
238
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
224
239
|
* @param options.shape - output array shape
|
|
240
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
241
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
242
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
225
243
|
* @returns zero-filled array
|
|
226
244
|
*
|
|
227
245
|
* @example
|
|
228
|
-
* var zeros = require(
|
|
246
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
229
247
|
*
|
|
230
248
|
* var x = zeros( [ 2, 2 ], {
|
|
231
249
|
* 'dtype': 'float64'
|
|
@@ -247,7 +265,7 @@ interface OptionsWithDType extends Options {
|
|
|
247
265
|
* dt = y.dtype;
|
|
248
266
|
* // returns 'float64'
|
|
249
267
|
*/
|
|
250
|
-
declare function zerosLike( x: float64ndarray, options?: Options ): float64ndarray;
|
|
268
|
+
declare function zerosLike( x: float64ndarray, options?: Options ): float64ndarray;
|
|
251
269
|
|
|
252
270
|
/**
|
|
253
271
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -256,10 +274,13 @@ declare function zerosLike( x: float64ndarray, options?: Options ): float64ndarr
|
|
|
256
274
|
* @param options - options
|
|
257
275
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
258
276
|
* @param options.shape - output array shape
|
|
277
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
278
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
279
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
259
280
|
* @returns zero-filled array
|
|
260
281
|
*
|
|
261
282
|
* @example
|
|
262
|
-
* var zeros = require(
|
|
283
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
263
284
|
*
|
|
264
285
|
* var x = zeros( [ 2, 2 ], {
|
|
265
286
|
* 'dtype': 'float32'
|
|
@@ -281,7 +302,7 @@ declare function zerosLike( x: float64ndarray, options?: Options ): float64ndarr
|
|
|
281
302
|
* dt = y.dtype;
|
|
282
303
|
* // returns 'float32'
|
|
283
304
|
*/
|
|
284
|
-
declare function zerosLike( x: float32ndarray, options?: Options ): float32ndarray;
|
|
305
|
+
declare function zerosLike( x: float32ndarray, options?: Options ): float32ndarray;
|
|
285
306
|
|
|
286
307
|
/**
|
|
287
308
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -290,10 +311,13 @@ declare function zerosLike( x: float32ndarray, options?: Options ): float32ndarr
|
|
|
290
311
|
* @param options - options
|
|
291
312
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
292
313
|
* @param options.shape - output array shape
|
|
314
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
315
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
316
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
293
317
|
* @returns zero-filled array
|
|
294
318
|
*
|
|
295
319
|
* @example
|
|
296
|
-
* var zeros = require(
|
|
320
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
297
321
|
*
|
|
298
322
|
* var x = zeros( [ 2, 2 ], {
|
|
299
323
|
* 'dtype': 'complex128'
|
|
@@ -315,7 +339,7 @@ declare function zerosLike( x: float32ndarray, options?: Options ): float32ndarr
|
|
|
315
339
|
* dt = y.dtype;
|
|
316
340
|
* // returns 'complex128'
|
|
317
341
|
*/
|
|
318
|
-
declare function zerosLike( x: complex128ndarray, options?: Options ): complex128ndarray;
|
|
342
|
+
declare function zerosLike( x: complex128ndarray, options?: Options ): complex128ndarray;
|
|
319
343
|
|
|
320
344
|
/**
|
|
321
345
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -324,10 +348,13 @@ declare function zerosLike( x: complex128ndarray, options?: Options ): complex12
|
|
|
324
348
|
* @param options - options
|
|
325
349
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
326
350
|
* @param options.shape - output array shape
|
|
351
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
352
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
353
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
327
354
|
* @returns zero-filled array
|
|
328
355
|
*
|
|
329
356
|
* @example
|
|
330
|
-
* var zeros = require(
|
|
357
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
331
358
|
*
|
|
332
359
|
* var x = zeros( [ 2, 2 ], {
|
|
333
360
|
* 'dtype': 'complex64'
|
|
@@ -349,7 +376,7 @@ declare function zerosLike( x: complex128ndarray, options?: Options ): complex12
|
|
|
349
376
|
* dt = y.dtype;
|
|
350
377
|
* // returns 'complex64'
|
|
351
378
|
*/
|
|
352
|
-
declare function zerosLike( x: complex64ndarray, options?: Options ): complex64ndarray;
|
|
379
|
+
declare function zerosLike( x: complex64ndarray, options?: Options ): complex64ndarray;
|
|
353
380
|
|
|
354
381
|
/**
|
|
355
382
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -358,10 +385,13 @@ declare function zerosLike( x: complex64ndarray, options?: Options ): complex64n
|
|
|
358
385
|
* @param options - options
|
|
359
386
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
360
387
|
* @param options.shape - output array shape
|
|
388
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
389
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
390
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
361
391
|
* @returns zero-filled array
|
|
362
392
|
*
|
|
363
393
|
* @example
|
|
364
|
-
* var zeros = require(
|
|
394
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
365
395
|
*
|
|
366
396
|
* var x = zeros( [ 2, 2 ], {
|
|
367
397
|
* 'dtype': 'int32'
|
|
@@ -392,10 +422,13 @@ declare function zerosLike( x: int32ndarray, options?: Options ): int32ndarray;
|
|
|
392
422
|
* @param options - options
|
|
393
423
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
394
424
|
* @param options.shape - output array shape
|
|
425
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
426
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
427
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
395
428
|
* @returns zero-filled array
|
|
396
429
|
*
|
|
397
430
|
* @example
|
|
398
|
-
* var zeros = require(
|
|
431
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
399
432
|
*
|
|
400
433
|
* var x = zeros( [ 2, 2 ], {
|
|
401
434
|
* 'dtype': 'int16'
|
|
@@ -426,10 +459,13 @@ declare function zerosLike( x: int16ndarray, options?: Options ): int16ndarray;
|
|
|
426
459
|
* @param options - options
|
|
427
460
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
428
461
|
* @param options.shape - output array shape
|
|
462
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
463
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
464
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
429
465
|
* @returns zero-filled array
|
|
430
466
|
*
|
|
431
467
|
* @example
|
|
432
|
-
* var zeros = require(
|
|
468
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
433
469
|
*
|
|
434
470
|
* var x = zeros( [ 2, 2 ], {
|
|
435
471
|
* 'dtype': 'int8'
|
|
@@ -460,10 +496,13 @@ declare function zerosLike( x: int8ndarray, options?: Options ): int8ndarray;
|
|
|
460
496
|
* @param options - options
|
|
461
497
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
462
498
|
* @param options.shape - output array shape
|
|
499
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
500
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
501
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
463
502
|
* @returns zero-filled array
|
|
464
503
|
*
|
|
465
504
|
* @example
|
|
466
|
-
* var zeros = require(
|
|
505
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
467
506
|
*
|
|
468
507
|
* var x = zeros( [ 2, 2 ], {
|
|
469
508
|
* 'dtype': 'uint32'
|
|
@@ -485,7 +524,7 @@ declare function zerosLike( x: int8ndarray, options?: Options ): int8ndarray;
|
|
|
485
524
|
* dt = y.dtype;
|
|
486
525
|
* // returns 'uint32'
|
|
487
526
|
*/
|
|
488
|
-
declare function zerosLike( x: uint32ndarray, options?: Options ): uint32ndarray;
|
|
527
|
+
declare function zerosLike( x: uint32ndarray, options?: Options ): uint32ndarray;
|
|
489
528
|
|
|
490
529
|
/**
|
|
491
530
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -494,10 +533,13 @@ declare function zerosLike( x: uint32ndarray, options?: Options ): uint32ndarray
|
|
|
494
533
|
* @param options - options
|
|
495
534
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
496
535
|
* @param options.shape - output array shape
|
|
536
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
537
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
538
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
497
539
|
* @returns zero-filled array
|
|
498
540
|
*
|
|
499
541
|
* @example
|
|
500
|
-
* var zeros = require(
|
|
542
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
501
543
|
*
|
|
502
544
|
* var x = zeros( [ 2, 2 ], {
|
|
503
545
|
* 'dtype': 'uint16'
|
|
@@ -519,7 +561,7 @@ declare function zerosLike( x: uint32ndarray, options?: Options ): uint32ndarray
|
|
|
519
561
|
* dt = y.dtype;
|
|
520
562
|
* // returns 'uint16'
|
|
521
563
|
*/
|
|
522
|
-
declare function zerosLike( x: uint16ndarray, options?: Options ): uint16ndarray;
|
|
564
|
+
declare function zerosLike( x: uint16ndarray, options?: Options ): uint16ndarray;
|
|
523
565
|
|
|
524
566
|
/**
|
|
525
567
|
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
@@ -528,10 +570,13 @@ declare function zerosLike( x: uint16ndarray, options?: Options ): uint16ndarray
|
|
|
528
570
|
* @param options - options
|
|
529
571
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
530
572
|
* @param options.shape - output array shape
|
|
573
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
574
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
575
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
531
576
|
* @returns zero-filled array
|
|
532
577
|
*
|
|
533
578
|
* @example
|
|
534
|
-
* var zeros = require(
|
|
579
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
535
580
|
*
|
|
536
581
|
* var x = zeros( [ 2, 2 ], {
|
|
537
582
|
* 'dtype': 'uint8'
|
|
@@ -562,10 +607,13 @@ declare function zerosLike( x: uint8ndarray, options?: Options ): uint8ndarray;
|
|
|
562
607
|
* @param options - options
|
|
563
608
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
564
609
|
* @param options.shape - output array shape
|
|
610
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
611
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
612
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
565
613
|
* @returns zero-filled array
|
|
566
614
|
*
|
|
567
615
|
* @example
|
|
568
|
-
* var zeros = require(
|
|
616
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
569
617
|
*
|
|
570
618
|
* var x = zeros( [ 2, 2 ], {
|
|
571
619
|
* 'dtype': 'uint8c'
|
|
@@ -587,7 +635,7 @@ declare function zerosLike( x: uint8ndarray, options?: Options ): uint8ndarray;
|
|
|
587
635
|
* dt = y.dtype;
|
|
588
636
|
* // returns 'uint8c'
|
|
589
637
|
*/
|
|
590
|
-
declare function zerosLike( x: uint8cndarray, options?: Options ): uint8cndarray;
|
|
638
|
+
declare function zerosLike( x: uint8cndarray, options?: Options ): uint8cndarray;
|
|
591
639
|
|
|
592
640
|
/**
|
|
593
641
|
* Creates a zero-filled double-precision floating-point array having the same shape as a provided input ndarray.
|
|
@@ -597,10 +645,13 @@ declare function zerosLike( x: uint8cndarray, options?: Options ): uint8cndarray
|
|
|
597
645
|
* @param options.dtype - output array data type
|
|
598
646
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
599
647
|
* @param options.shape - output array shape
|
|
648
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
649
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
650
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
600
651
|
* @returns zero-filled array
|
|
601
652
|
*
|
|
602
653
|
* @example
|
|
603
|
-
* var zeros = require(
|
|
654
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
604
655
|
*
|
|
605
656
|
* var x = zeros( [ 2, 2 ], {
|
|
606
657
|
* 'dtype': 'generic'
|
|
@@ -624,7 +675,7 @@ declare function zerosLike( x: uint8cndarray, options?: Options ): uint8cndarray
|
|
|
624
675
|
* dt = y.dtype;
|
|
625
676
|
* // returns 'float64'
|
|
626
677
|
*/
|
|
627
|
-
declare function zerosLike( x: ndarray, options: Float64Options ): float64ndarray;
|
|
678
|
+
declare function zerosLike( x: ndarray, options: Float64Options ): float64ndarray;
|
|
628
679
|
|
|
629
680
|
/**
|
|
630
681
|
* Creates a zero-filled single-precision floating-point array having the same shape as a provided input ndarray.
|
|
@@ -634,10 +685,13 @@ declare function zerosLike( x: ndarray, options: Float64Options ): float64ndarra
|
|
|
634
685
|
* @param options.dtype - output array data type
|
|
635
686
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
636
687
|
* @param options.shape - output array shape
|
|
688
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
689
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
690
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
637
691
|
* @returns zero-filled array
|
|
638
692
|
*
|
|
639
693
|
* @example
|
|
640
|
-
* var zeros = require(
|
|
694
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
641
695
|
*
|
|
642
696
|
* var x = zeros( [ 2, 2 ], {
|
|
643
697
|
* 'dtype': 'float64'
|
|
@@ -661,7 +715,7 @@ declare function zerosLike( x: ndarray, options: Float64Options ): float64ndarra
|
|
|
661
715
|
* dt = y.dtype;
|
|
662
716
|
* // returns 'float32'
|
|
663
717
|
*/
|
|
664
|
-
declare function zerosLike( x: ndarray, options: Float32Options ): float32ndarray;
|
|
718
|
+
declare function zerosLike( x: ndarray, options: Float32Options ): float32ndarray;
|
|
665
719
|
|
|
666
720
|
/**
|
|
667
721
|
* Creates a zero-filled double-precision complex floating-point array having the same shape as a provided input ndarray.
|
|
@@ -671,10 +725,13 @@ declare function zerosLike( x: ndarray, options: Float32Options ): float32ndarra
|
|
|
671
725
|
* @param options.dtype - output array data type
|
|
672
726
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
673
727
|
* @param options.shape - output array shape
|
|
728
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
729
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
730
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
674
731
|
* @returns zero-filled array
|
|
675
732
|
*
|
|
676
733
|
* @example
|
|
677
|
-
* var zeros = require(
|
|
734
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
678
735
|
*
|
|
679
736
|
* var x = zeros( [ 2, 2 ], {
|
|
680
737
|
* 'dtype': 'float64'
|
|
@@ -698,7 +755,7 @@ declare function zerosLike( x: ndarray, options: Float32Options ): float32ndarra
|
|
|
698
755
|
* dt = y.dtype;
|
|
699
756
|
* // returns 'complex128'
|
|
700
757
|
*/
|
|
701
|
-
declare function zerosLike( x: ndarray, options: Complex128Options ): complex128ndarray;
|
|
758
|
+
declare function zerosLike( x: ndarray, options: Complex128Options ): complex128ndarray;
|
|
702
759
|
|
|
703
760
|
/**
|
|
704
761
|
* Creates a zero-filled single-precision complex floating-point array having the same shape as a provided input ndarray.
|
|
@@ -708,10 +765,13 @@ declare function zerosLike( x: ndarray, options: Complex128Options ): complex128
|
|
|
708
765
|
* @param options.dtype - output array data type
|
|
709
766
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
710
767
|
* @param options.shape - output array shape
|
|
768
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
769
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
770
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
711
771
|
* @returns zero-filled array
|
|
712
772
|
*
|
|
713
773
|
* @example
|
|
714
|
-
* var zeros = require(
|
|
774
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
715
775
|
*
|
|
716
776
|
* var x = zeros( [ 2, 2 ], {
|
|
717
777
|
* 'dtype': 'float64'
|
|
@@ -735,7 +795,7 @@ declare function zerosLike( x: ndarray, options: Complex128Options ): complex128
|
|
|
735
795
|
* dt = y.dtype;
|
|
736
796
|
* // returns 'complex64'
|
|
737
797
|
*/
|
|
738
|
-
declare function zerosLike( x: ndarray, options: Complex64Options ): complex64ndarray;
|
|
798
|
+
declare function zerosLike( x: ndarray, options: Complex64Options ): complex64ndarray;
|
|
739
799
|
|
|
740
800
|
/**
|
|
741
801
|
* Creates a zero-filled 32-bit signed integer array having the same shape as a provided input ndarray.
|
|
@@ -745,10 +805,13 @@ declare function zerosLike( x: ndarray, options: Complex64Options ): complex64nd
|
|
|
745
805
|
* @param options.dtype - output array data type
|
|
746
806
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
747
807
|
* @param options.shape - output array shape
|
|
808
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
809
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
810
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
748
811
|
* @returns zero-filled array
|
|
749
812
|
*
|
|
750
813
|
* @example
|
|
751
|
-
* var zeros = require(
|
|
814
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
752
815
|
*
|
|
753
816
|
* var x = zeros( [ 2, 2 ], {
|
|
754
817
|
* 'dtype': 'float64'
|
|
@@ -782,10 +845,13 @@ declare function zerosLike( x: ndarray, options: Int32Options ): int32ndarray;
|
|
|
782
845
|
* @param options.dtype - output array data type
|
|
783
846
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
784
847
|
* @param options.shape - output array shape
|
|
848
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
849
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
850
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
785
851
|
* @returns zero-filled array
|
|
786
852
|
*
|
|
787
853
|
* @example
|
|
788
|
-
* var zeros = require(
|
|
854
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
789
855
|
*
|
|
790
856
|
* var x = zeros( [ 2, 2 ], {
|
|
791
857
|
* 'dtype': 'float64'
|
|
@@ -819,10 +885,13 @@ declare function zerosLike( x: ndarray, options: Int16Options ): int16ndarray;
|
|
|
819
885
|
* @param options.dtype - output array data type
|
|
820
886
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
821
887
|
* @param options.shape - output array shape
|
|
888
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
889
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
890
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
822
891
|
* @returns zero-filled array
|
|
823
892
|
*
|
|
824
893
|
* @example
|
|
825
|
-
* var zeros = require(
|
|
894
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
826
895
|
*
|
|
827
896
|
* var x = zeros( [ 2, 2 ], {
|
|
828
897
|
* 'dtype': 'float64'
|
|
@@ -856,10 +925,13 @@ declare function zerosLike( x: ndarray, options: Int8Options ): int8ndarray;
|
|
|
856
925
|
* @param options.dtype - output array data type
|
|
857
926
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
858
927
|
* @param options.shape - output array shape
|
|
928
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
929
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
930
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
859
931
|
* @returns zero-filled array
|
|
860
932
|
*
|
|
861
933
|
* @example
|
|
862
|
-
* var zeros = require(
|
|
934
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
863
935
|
*
|
|
864
936
|
* var x = zeros( [ 2, 2 ], {
|
|
865
937
|
* 'dtype': 'float64'
|
|
@@ -893,10 +965,13 @@ declare function zerosLike( x: ndarray, options: Uint32Options ): uint32ndarray;
|
|
|
893
965
|
* @param options.dtype - output array data type
|
|
894
966
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
895
967
|
* @param options.shape - output array shape
|
|
968
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
969
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
970
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
896
971
|
* @returns zero-filled array
|
|
897
972
|
*
|
|
898
973
|
* @example
|
|
899
|
-
* var zeros = require(
|
|
974
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
900
975
|
*
|
|
901
976
|
* var x = zeros( [ 2, 2 ], {
|
|
902
977
|
* 'dtype': 'float64'
|
|
@@ -930,10 +1005,13 @@ declare function zerosLike( x: ndarray, options: Uint16Options ): uint16ndarray;
|
|
|
930
1005
|
* @param options.dtype - output array data type
|
|
931
1006
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
932
1007
|
* @param options.shape - output array shape
|
|
1008
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
1009
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
1010
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
933
1011
|
* @returns zero-filled array
|
|
934
1012
|
*
|
|
935
1013
|
* @example
|
|
936
|
-
* var zeros = require(
|
|
1014
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
937
1015
|
*
|
|
938
1016
|
* var x = zeros( [ 2, 2 ], {
|
|
939
1017
|
* 'dtype': 'float64'
|
|
@@ -967,10 +1045,13 @@ declare function zerosLike( x: ndarray, options: Uint8Options ): uint8ndarray;
|
|
|
967
1045
|
* @param options.dtype - output array data type
|
|
968
1046
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
969
1047
|
* @param options.shape - output array shape
|
|
1048
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
1049
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
1050
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
970
1051
|
* @returns zero-filled array
|
|
971
1052
|
*
|
|
972
1053
|
* @example
|
|
973
|
-
* var zeros = require(
|
|
1054
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
974
1055
|
*
|
|
975
1056
|
* var x = zeros( [ 2, 2 ], {
|
|
976
1057
|
* 'dtype': 'float64'
|
|
@@ -1004,10 +1085,13 @@ declare function zerosLike( x: ndarray, options: Uint8COptions ): uint8cndarray;
|
|
|
1004
1085
|
* @param options.dtype - output array data type
|
|
1005
1086
|
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
1006
1087
|
* @param options.shape - output array shape
|
|
1088
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
1089
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
1090
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
1007
1091
|
* @returns zero-filled array
|
|
1008
1092
|
*
|
|
1009
1093
|
* @example
|
|
1010
|
-
* var zeros = require(
|
|
1094
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1011
1095
|
*
|
|
1012
1096
|
* var x = zeros( [ 2, 2 ], {
|
|
1013
1097
|
* 'dtype': 'float64'
|
|
@@ -1029,7 +1113,7 @@ declare function zerosLike( x: ndarray, options: Uint8COptions ): uint8cndarray;
|
|
|
1029
1113
|
* dt = y.dtype;
|
|
1030
1114
|
* // returns 'generic'
|
|
1031
1115
|
*/
|
|
1032
|
-
declare function zerosLike( x: ndarray, options?: Options | OptionsWithDType ): typedndarray<number>;
|
|
1116
|
+
declare function zerosLike( x: ndarray, options?: Options | OptionsWithDType ): typedndarray<number>;
|
|
1033
1117
|
|
|
1034
1118
|
|
|
1035
1119
|
// EXPORTS //
|
package/lib/main.js
CHANGED
|
@@ -28,7 +28,11 @@ var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
|
28
28
|
var strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
29
29
|
var buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
30
30
|
var numel = require( '@stdlib/ndarray-base-numel' );
|
|
31
|
+
var getDType = require( '@stdlib/ndarray-dtype' );
|
|
32
|
+
var getShape = require( '@stdlib/ndarray-shape' );
|
|
33
|
+
var getOrder = require( '@stdlib/ndarray-order' );
|
|
31
34
|
var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
35
|
+
var format = require( '@stdlib/string-format' );
|
|
32
36
|
|
|
33
37
|
|
|
34
38
|
// MAIN //
|
|
@@ -41,11 +45,15 @@ var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
|
41
45
|
* @param {string} [options.dtype] - output array data type (overrides the input array's inferred data type)
|
|
42
46
|
* @param {string} [options.order] - specifies whether the output array should be 'row-major' (C-style) or 'column-major' (Fortran-style) (overrides the input array's inferred order)
|
|
43
47
|
* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.shape] - output array shape (overrides the input array's inferred shape)
|
|
48
|
+
* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions
|
|
49
|
+
* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
50
|
+
* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only
|
|
44
51
|
* @throws {TypeError} first argument must have a recognized data type
|
|
45
52
|
* @throws {TypeError} options argument must be an object
|
|
46
53
|
* @throws {TypeError} `dtype` option must be a supported ndarray data type
|
|
47
54
|
* @throws {TypeError} `order` option must be a supported order
|
|
48
55
|
* @throws {TypeError} `shape` option must be either a nonnegative integer or an array of nonnegative integers
|
|
56
|
+
* @throws {TypeError} must provide valid options
|
|
49
57
|
* @returns {ndarray} ndarray
|
|
50
58
|
*
|
|
51
59
|
* @example
|
|
@@ -65,64 +73,73 @@ var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
|
65
73
|
*/
|
|
66
74
|
function zerosLike( x ) {
|
|
67
75
|
var options;
|
|
76
|
+
var dtype;
|
|
77
|
+
var order;
|
|
68
78
|
var ndims;
|
|
69
79
|
var opts;
|
|
70
80
|
var buf;
|
|
71
81
|
var len;
|
|
72
82
|
var st;
|
|
83
|
+
var sh;
|
|
73
84
|
|
|
74
85
|
if ( !isndarrayLike( x ) ) {
|
|
75
|
-
throw new TypeError( 'invalid argument. First argument must be an ndarray-like object. Value:
|
|
86
|
+
throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );
|
|
76
87
|
}
|
|
77
88
|
opts = {};
|
|
78
89
|
if ( arguments.length > 1 ) {
|
|
79
90
|
options = arguments[ 1 ];
|
|
80
91
|
if ( !isPlainObject( options ) ) {
|
|
81
|
-
throw new TypeError( 'invalid argument. Options argument must be an object. Value:
|
|
92
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
82
93
|
}
|
|
83
94
|
if ( hasOwnProp( options, 'dtype' ) ) {
|
|
84
|
-
|
|
95
|
+
dtype = options.dtype;
|
|
85
96
|
} else {
|
|
86
|
-
|
|
97
|
+
dtype = getDType( x );
|
|
87
98
|
}
|
|
88
99
|
if ( hasOwnProp( options, 'shape' ) ) {
|
|
89
|
-
|
|
90
|
-
if ( typeof
|
|
91
|
-
|
|
100
|
+
sh = options.shape;
|
|
101
|
+
if ( typeof sh === 'number' ) {
|
|
102
|
+
sh = [ sh ];
|
|
92
103
|
}
|
|
93
|
-
if ( !isNonNegativeIntegerArray(
|
|
94
|
-
throw new TypeError( 'invalid option. `
|
|
104
|
+
if ( !isNonNegativeIntegerArray( sh ) ) {
|
|
105
|
+
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', sh ) );
|
|
95
106
|
}
|
|
96
107
|
} else {
|
|
97
|
-
|
|
108
|
+
sh = getShape( x );
|
|
98
109
|
}
|
|
99
110
|
if ( hasOwnProp( options, 'order' ) ) {
|
|
100
|
-
|
|
111
|
+
order = options.order;
|
|
101
112
|
} else {
|
|
102
|
-
|
|
113
|
+
order = getOrder( x );
|
|
114
|
+
}
|
|
115
|
+
if ( hasOwnProp( options, 'mode' ) ) {
|
|
116
|
+
opts.mode = options.mode;
|
|
117
|
+
}
|
|
118
|
+
if ( hasOwnProp( options, 'submode' ) ) {
|
|
119
|
+
opts.submode = options.submode;
|
|
120
|
+
}
|
|
121
|
+
if ( hasOwnProp( options, 'readonly' ) ) {
|
|
122
|
+
opts.readonly = options.readonly;
|
|
103
123
|
}
|
|
104
124
|
} else {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
dtype = getDType( x );
|
|
126
|
+
sh = getShape( x );
|
|
127
|
+
order = getOrder( x );
|
|
108
128
|
}
|
|
109
|
-
ndims =
|
|
129
|
+
ndims = sh.length;
|
|
110
130
|
if ( ndims > 0 ) {
|
|
111
|
-
len = numel(
|
|
112
|
-
|
|
113
|
-
len = 0; // note: we should only get here if an inferred shape is invalid (i.e., contains negative dimension sizes)
|
|
114
|
-
}
|
|
115
|
-
st = shape2strides( opts.shape, opts.order );
|
|
131
|
+
len = numel( sh );
|
|
132
|
+
st = shape2strides( sh, order );
|
|
116
133
|
} else {
|
|
117
134
|
// For 0-dimensional arrays, the buffer should contain a single element...
|
|
118
135
|
len = 1;
|
|
119
136
|
st = [ 0 ];
|
|
120
137
|
}
|
|
121
|
-
buf = buffer(
|
|
138
|
+
buf = buffer( dtype, len );
|
|
122
139
|
if ( buf === null ) {
|
|
123
|
-
throw new TypeError( 'invalid argument. First argument must have a recognized data type. Value:
|
|
140
|
+
throw new TypeError( format( 'invalid argument. First argument must have a recognized data type. Value: `%s`.', dtype ) );
|
|
124
141
|
}
|
|
125
|
-
return new ndarray(
|
|
142
|
+
return new ndarray( dtype, buf, sh, st, strides2offset( sh, st ), order, opts ); // eslint-disable-line max-len
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
|