Skip to content

Commit 4d1bbcd

Browse files
committed
feat: add types for static methods
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c82dc90 commit 4d1bbcd

File tree

2 files changed

+265
-28
lines changed

2 files changed

+265
-28
lines changed

lib/node_modules/@stdlib/ndarray/index/docs/types/index.d.ts

Lines changed: 177 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,68 @@ interface LinearOptions extends BaseOptions {
6262
kind: 'linear';
6363
}
6464

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+
65123
/**
66124
* Interface defining an `ndindex` constructor which is both "newable" and "callable".
67125
*/
68-
interface Constructor {
126+
interface Constructor extends BaseConstructor {
69127
/**
70128
* ndarray index constructor.
71129
*
@@ -490,57 +548,130 @@ interface Constructor {
490548
name: 'ndindex';
491549

492550
/**
493-
* Frees the `ndindex` associated with a provided identifier.
551+
* Returns an ndarray index containing Cartesian indices.
494552
*
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
497557
*
498558
* @example
499-
* var Uint8Array = require( '@stdlib/array/uint8' );
559+
* var Int32Array = require( '@stdlib/array/int32' );
500560
* var array = require( '@stdlib/ndarray/array' );
501561
*
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 );
505565
* // returns <ndindex>
566+
*/
567+
cartesianIndex: CartesianIndexFactory;
568+
569+
/**
570+
* Returns an ndarray index containing indices representing locations in linear memory.
506571
*
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
508576
*
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>
511585
*/
512-
free( id: string ): boolean;
586+
linearIndex: LinearIndexFactory;
587+
}
513588

589+
/**
590+
* Interface for creating index objects for ndarrays containing Cartesian indices.
591+
*/
592+
interface CartesianIndexFactory extends BaseConstructor {
514593
/**
515-
* Returns ndarray index data associated with a provided identifier.
594+
* Returns an ndarray index containing Cartesian indices.
516595
*
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
519600
*
520601
* @example
521-
* var Uint8Array = require( '@stdlib/array/uint8' );
602+
* var Int32Array = require( '@stdlib/array/int32' );
522603
* var array = require( '@stdlib/ndarray/array' );
523604
*
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'
526625
* });
626+
*
627+
* var idx = ndindex.cartesianIndex( x );
527628
* // 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.
528639
*
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
530644
*
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' );
533648
*
534-
* var d = o.data;
535-
* // returns <ndarray>
649+
* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) );
536650
*
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.
539658
*
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>
542673
*/
543-
get<T extends BaseIndexArrayObject = ndindexObject>( id: string ): T | null;
674+
( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex;
544675
}
545676

546677
/**
@@ -560,6 +691,24 @@ interface Constructor {
560691
*
561692
* var idx = new ndindex( x );
562693
* // 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>
563712
*/
564713
declare var ctor: Constructor;
565714

lib/node_modules/@stdlib/ndarray/index/docs/types/test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,91 @@ import ndindex = require( './index' );
213213

214214
x.isCached; // $ExpectType boolean
215215
}
216+
217+
// Attached to the main export is a `cartesianIndex` function which returns an array index...
218+
{
219+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
220+
const w = empty( [ 2 ], { 'dtype': 'int32' } );
221+
222+
ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex
223+
ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex
224+
225+
ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex
226+
ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex
227+
}
228+
229+
// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray...
230+
{
231+
ndindex.cartesianIndex( 1 ); // $ExpectError
232+
ndindex.cartesianIndex( null ); // $ExpectError
233+
ndindex.cartesianIndex( void 0 ); // $ExpectError
234+
ndindex.cartesianIndex( true ); // $ExpectError
235+
ndindex.cartesianIndex( false ); // $ExpectError
236+
ndindex.cartesianIndex( {} ); // $ExpectError
237+
ndindex.cartesianIndex( [] ); // $ExpectError
238+
ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError
239+
}
240+
241+
// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean...
242+
{
243+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
244+
245+
ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError
246+
ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError
247+
ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError
248+
ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError
249+
ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError
250+
ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError
251+
}
252+
253+
// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments...
254+
{
255+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
256+
257+
ndindex.cartesianIndex(); // $ExpectError
258+
ndindex.cartesianIndex( x, {}, {} ); // $ExpectError
259+
}
260+
261+
// Attached to the main export is a `linearIndex` function which returns an array index...
262+
{
263+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
264+
const w = empty( [ 2 ], { 'dtype': 'int32' } );
265+
266+
ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex
267+
ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex
268+
269+
ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex
270+
ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex
271+
}
272+
273+
// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray...
274+
{
275+
ndindex.linearIndex( 1 ); // $ExpectError
276+
ndindex.linearIndex( null ); // $ExpectError
277+
ndindex.linearIndex( void 0 ); // $ExpectError
278+
ndindex.linearIndex( true ); // $ExpectError
279+
ndindex.linearIndex( false ); // $ExpectError
280+
ndindex.linearIndex( {} ); // $ExpectError
281+
ndindex.linearIndex( [] ); // $ExpectError
282+
ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError
283+
}
284+
285+
// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean...
286+
{
287+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
288+
289+
ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError
290+
ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError
291+
ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError
292+
ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError
293+
ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError
294+
ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError
295+
}
296+
297+
// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments...
298+
{
299+
const x = empty( [ 2 ], { 'dtype': 'generic' } );
300+
301+
ndindex.linearIndex(); // $ExpectError
302+
ndindex.linearIndex( x, {}, {} ); // $ExpectError
303+
}

0 commit comments

Comments
 (0)