@@ -62,10 +62,68 @@ interface LinearOptions extends BaseOptions {
62
62
kind : 'linear' ;
63
63
}
64
64
65
+ /**
66
+ * Interface defining common methods for constructors and functions which create `ndindex` objects.
67
+ */
68
+ interface BaseConstructor {
69
+ /**
70
+ * Frees the `ndindex` associated with a provided identifier.
71
+ *
72
+ * @param id - identifier
73
+ * @returns boolean indicating whether an `ndindex` was successfully freed
74
+ *
75
+ * @example
76
+ * var Uint8Array = require( '@stdlib/array/uint8' );
77
+ * var array = require( '@stdlib/ndarray/array' );
78
+ *
79
+ * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), {
80
+ * 'persist': true
81
+ * });
82
+ * // returns <ndindex>
83
+ *
84
+ * // ...
85
+ *
86
+ * var out = ndindex.free( idx.id );
87
+ * // returns true
88
+ */
89
+ free ( id : string ) : boolean ;
90
+
91
+ /**
92
+ * Returns ndarray index data associated with a provided identifier.
93
+ *
94
+ * @param id - identifier
95
+ * @returns object containing ndarray index data
96
+ *
97
+ * @example
98
+ * var Uint8Array = require( '@stdlib/array/uint8' );
99
+ * var array = require( '@stdlib/ndarray/array' );
100
+ *
101
+ * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), {
102
+ * 'persist': true
103
+ * });
104
+ * // returns <ndindex>
105
+ *
106
+ * // ...
107
+ *
108
+ * var o = ndindex.get( idx.id );
109
+ * // returns {...}
110
+ *
111
+ * var d = o.data;
112
+ * // returns <ndarray>
113
+ *
114
+ * var t = o.type;
115
+ * // returns 'mask'
116
+ *
117
+ * var dt = o.dtype;
118
+ * // returns 'uint8'
119
+ */
120
+ get < T extends BaseIndexArrayObject = ndindexObject > ( id : string ) : T | null ;
121
+ }
122
+
65
123
/**
66
124
* Interface defining an `ndindex` constructor which is both "newable" and "callable".
67
125
*/
68
- interface Constructor {
126
+ interface Constructor extends BaseConstructor {
69
127
/**
70
128
* ndarray index constructor.
71
129
*
@@ -490,57 +548,130 @@ interface Constructor {
490
548
name : 'ndindex' ;
491
549
492
550
/**
493
- * Frees the `ndindex` associated with a provided identifier .
551
+ * Returns an ndarray index containing Cartesian indices .
494
552
*
495
- * @param id - identifier
496
- * @returns boolean indicating whether an `ndindex` was successfully freed
553
+ * @param x - input ndarray
554
+ * @param options - function options
555
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
556
+ * @returns ndindex instance
497
557
*
498
558
* @example
499
- * var Uint8Array = require( '@stdlib/array/uint8 ' );
559
+ * var Int32Array = require( '@stdlib/array/int32 ' );
500
560
* var array = require( '@stdlib/ndarray/array' );
501
561
*
502
- * var idx = new ndindex( array( new Uint8Array ( [ 1, 0, 1, 0 ] ) ), {
503
- * 'persist': true
504
- * } );
562
+ * var x = array( new Int32Array ( [ 1, 0, 1, 0 ] ) );
563
+ *
564
+ * var idx = ndindex.cartesianIndex( x );
505
565
* // returns <ndindex>
566
+ */
567
+ cartesianIndex : CartesianIndexFactory ;
568
+
569
+ /**
570
+ * Returns an ndarray index containing indices representing locations in linear memory.
506
571
*
507
- * // ...
572
+ * @param x - input ndarray
573
+ * @param options - function options
574
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
575
+ * @returns ndindex instance
508
576
*
509
- * var out = ndindex.free( idx.id );
510
- * // returns true
577
+ * @example
578
+ * var Int32Array = require( '@stdlib/array/int32' );
579
+ * var array = require( '@stdlib/ndarray/array' );
580
+ *
581
+ * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
582
+ *
583
+ * var idx = ndindex.linearIndex( x );
584
+ * // returns <ndindex>
511
585
*/
512
- free ( id : string ) : boolean ;
586
+ linearIndex : LinearIndexFactory ;
587
+ }
513
588
589
+ /**
590
+ * Interface for creating index objects for ndarrays containing Cartesian indices.
591
+ */
592
+ interface CartesianIndexFactory extends BaseConstructor {
514
593
/**
515
- * Returns ndarray index data associated with a provided identifier .
594
+ * Returns an ndarray index containing Cartesian indices .
516
595
*
517
- * @param id - identifier
518
- * @returns object containing ndarray index data
596
+ * @param x - input ndarray
597
+ * @param options - function options
598
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
599
+ * @returns ndindex instance
519
600
*
520
601
* @example
521
- * var Uint8Array = require( '@stdlib/array/uint8 ' );
602
+ * var Int32Array = require( '@stdlib/array/int32 ' );
522
603
* var array = require( '@stdlib/ndarray/array' );
523
604
*
524
- * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), {
525
- * 'persist': true
605
+ * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
606
+ *
607
+ * var idx = ndindex.cartesianIndex( x );
608
+ * // returns <ndindex>
609
+ */
610
+ ( x : int32ndarray , options ?: BaseOptions ) : CartesianInt32ArrayIndex ;
611
+
612
+ /**
613
+ * Returns an ndarray index containing Cartesian indices.
614
+ *
615
+ * @param x - input ndarray
616
+ * @param options - function options
617
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
618
+ * @returns ndindex instance
619
+ *
620
+ * @example
621
+ * var array = require( '@stdlib/ndarray/array' );
622
+ *
623
+ * var x = array( [ 1, 2, 3, 4 ], {
624
+ * 'dtype': 'generic'
526
625
* });
626
+ *
627
+ * var idx = ndindex.cartesianIndex( x );
527
628
* // returns <ndindex>
629
+ */
630
+ ( x : GenericIntegerIndexArray , options ?: BaseOptions ) : CartesianGenericArrayIndex ;
631
+ }
632
+
633
+ /**
634
+ * Interface for creating index objects for ndarrays containing linear indices.
635
+ */
636
+ interface LinearIndexFactory extends BaseConstructor {
637
+ /**
638
+ * Returns an ndarray index containing indices representing locations in linear memory.
528
639
*
529
- * // ...
640
+ * @param x - input ndarray
641
+ * @param options - function options
642
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
643
+ * @returns ndindex instance
530
644
*
531
- * var o = ndindex.get( idx.id );
532
- * // returns {...}
645
+ * @example
646
+ * var Int32Array = require( '@stdlib/array/int32' );
647
+ * var array = require( '@stdlib/ndarray/array' );
533
648
*
534
- * var d = o.data;
535
- * // returns <ndarray>
649
+ * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
536
650
*
537
- * var t = o.type;
538
- * // returns 'mask'
651
+ * var idx = ndindex.linearIndex( x );
652
+ * // returns <ndindex>
653
+ */
654
+ ( x : int32ndarray , options ?: BaseOptions ) : LinearInt32ArrayIndex ;
655
+
656
+ /**
657
+ * Returns an ndarray index containing indices representing locations in linear memory.
539
658
*
540
- * var dt = o.dtype;
541
- * // returns 'uint8'
659
+ * @param x - input ndarray
660
+ * @param options - function options
661
+ * @param options.persist - boolean indicating whether to continue persisting an index object after first usage
662
+ * @returns ndindex instance
663
+ *
664
+ * @example
665
+ * var array = require( '@stdlib/ndarray/array' );
666
+ *
667
+ * var x = array( [ 1, 2, 3, 4 ], {
668
+ * 'dtype': 'generic'
669
+ * });
670
+ *
671
+ * var idx = ndindex.linearIndex( x );
672
+ * // returns <ndindex>
542
673
*/
543
- get < T extends BaseIndexArrayObject = ndindexObject > ( id : string ) : T | null ;
674
+ ( x : GenericIntegerIndexArray , options ?: BaseOptions ) : LinearGenericArrayIndex ;
544
675
}
545
676
546
677
/**
@@ -560,6 +691,24 @@ interface Constructor {
560
691
*
561
692
* var idx = new ndindex( x );
562
693
* // returns <ndindex>
694
+ *
695
+ * @example
696
+ * var Int32Array = require( '@stdlib/array/int32' );
697
+ * var array = require( '@stdlib/ndarray/array' );
698
+ *
699
+ * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
700
+ *
701
+ * var idx = ndindex.cartesianIndex( x );
702
+ * // returns <ndindex>
703
+ *
704
+ * @example
705
+ * var Int32Array = require( '@stdlib/array/int32' );
706
+ * var array = require( '@stdlib/ndarray/array' );
707
+ *
708
+ * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
709
+ *
710
+ * var idx = ndindex.linearIndex( x );
711
+ * // returns <ndindex>
563
712
*/
564
713
declare var ctor : Constructor ;
565
714
0 commit comments