Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Feb 18, 2024
1 parent 09ca16a commit 3fac561
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 284 deletions.
256 changes: 3 additions & 253 deletions index/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,7 @@

/// <reference types="@stdlib/types"/>

import { Collection, AccessorArrayLike, DataType } from '@stdlib/types/array';

/**
* Boolean index array.
*/
type BooleanIndexArray = Collection<boolean> | AccessorArrayLike<boolean>;

/**
* Integer index array.
*/
type IntegerIndexArray = Collection<number> | AccessorArrayLike<number>;

/**
* Index array.
*/
type IndexArray = BooleanIndexArray | IntegerIndexArray;
import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array';

/**
* Interface describing function options.
Expand All @@ -47,242 +32,6 @@ interface Options {
persist?: boolean;
}

/**
* Interface describing an object containing array index data.
*/
interface BaseArrayObject {
/**
* The underlying array associated with an array index.
*/
data: IndexArray;

/**
* The type of array index.
*/
type: 'int' | 'bool' | 'mask';

/**
* The data type of the underlying array.
*/
dtype: DataType;
}

/**
* Interface describing an object containing mask array data.
*/
interface MaskArrayObject extends BaseArrayObject {
/**
* The underlying array associated with an array index.
*/
data: Uint8Array;

/**
* The type of array index.
*/
type: 'mask';

/**
* The data type of the underlying array.
*/
dtype: 'uint8';
}

/**
* Interface describing an object containing integer array data.
*/
interface Int32ArrayObject extends BaseArrayObject {
/**
* The underlying array associated with an array index.
*/
data: Int32Array;

/**
* The type of array index.
*/
type: 'int';

/**
* The data type of the underlying array.
*/
dtype: 'int32';
}

/**
* Interface describing an object containing integer array data.
*/
interface IntegerArrayObject extends BaseArrayObject {
/**
* The underlying array associated with an array index.
*/
data: IntegerIndexArray;

/**
* The type of array index.
*/
type: 'int';

/**
* The data type of the underlying array.
*/
dtype: 'generic';
}

/**
* Interface describing an object containing boolean array data.
*/
interface BooleanArrayObject extends BaseArrayObject {
/**
* The underlying array associated with an array index.
*/
data: BooleanIndexArray;

/**
* The type of array index.
*/
type: 'bool';

/**
* The data type of the underlying array.
*/
dtype: 'generic';
}

/**
* Array object data.
*/
type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null;

/**
* Interface describing an array index object.
*/
interface BaseArrayIndex {
/**
* Read-only property returning the data associated with an `ArrayIndex` instance.
*/
data: IndexArray;

/**
* Read-only property returning the underlying array index data type.
*/
dtype: DataType;

/**
* Read-only property returning the unique identifier associated with an `ArrayIndex` instance.
*/
id: string;

/**
* Boolean indicating if an `ArrayIndex` instance is actively cached.
*/
isCached: boolean;

/**
* Read-only property returning the array index type.
*/
type: 'int' | 'bool' | 'mask';

/**
* Serializes an `ArrayIndex` to a string.
*
* @returns serialized string
*
* @example
* var Uint8Array = require( './../../../uint8' );
*
* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );
* // returns <ArrayIndex>
*
* var str = idx.toString();
* // e.g., 'ArrayIndex<0>'
*/
toString(): string;
}

/**
* Interface describing a mask array index object.
*/
interface MaskArrayIndex extends BaseArrayIndex {
/**
* Read-only property returning the array index type.
*/
type: 'mask';

/**
* Read-only property returning the underlying array index data type.
*/
dtype: 'uint8';

/**
* Read-only property returning the underlying array data.
*/
data: Uint8Array;
}

/**
* Interface describing an integer array index object.
*/
interface Int32ArrayIndex extends BaseArrayIndex {
/**
* Read-only property returning the array index type.
*/
type: 'int';

/**
* Read-only property returning the underlying array index data type.
*/
dtype: 'int32';

/**
* Read-only property returning the underlying array data.
*/
data: Int32Array;
}

/**
* Interface describing a boolean array index object.
*/
interface BooleanArrayIndex extends BaseArrayIndex {
/**
* Read-only property returning the array index type.
*/
type: 'bool';

/**
* Read-only property returning the underlying array index data type.
*/
dtype: 'generic';

/**
* Read-only property returning the underlying array data.
*/
data: BooleanIndexArray;
}

/**
* Interface describing an integer array index object.
*/
interface IntegerArrayIndex extends BaseArrayIndex {
/**
* Read-only property returning the array index type.
*/
type: 'int';

/**
* Read-only property returning the underlying array index data type.
*/
dtype: 'generic';

/**
* Read-only property returning the underlying array data.
*/
data: IntegerIndexArray;
}

/**
* Array index object.
*/
type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex;

/**
* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable".
*/
Expand Down Expand Up @@ -372,6 +121,7 @@ interface Constructor {
* // returns <ArrayIndex>
*/
new( x: IndexArray, options?: Options ): ArrayIndex;

/**
* Array index constructor.
*
Expand Down Expand Up @@ -512,7 +262,7 @@ interface Constructor {
* var dt = o.dtype;
* // returns 'uint8'
*/
get<T extends BaseArrayObject = ArrayObject>( id: string ): T;
get<T extends BaseIndexArrayObject = IndexArrayObject>( id: string ): T | null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion index/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import ArrayIndex = require( './index' );

// Attached to the main export is a `get` function which returns array object data...
{
ArrayIndex.get( '0' ); // $ExpectType ArrayObject
ArrayIndex.get( '0' ); // $ExpectType IndexArrayObject | null
}

// The compiler throws an error if the `get` method is provided first argument which is not a string...
Expand Down
26 changes: 19 additions & 7 deletions to-fancy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ var v = y[ 10 ];

The returned function supports the same options as above. When the returned function is provided option values, those values override the factory method defaults.

#### array2fancy.idx( x\[, options] )

Wraps a provided array as an array index object.

```javascript
var x = [ 1, 2, 3, 4 ];

var idx = array2fancy.idx( x );
// returns <ArrayIndex>
```

For documentation and usage, see [`ArrayIndex`][@stdlib/array/index]

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -236,8 +249,6 @@ Accordingly, when `strict` is `false`, one may observe the following behaviors:
<!-- run throws: true -->

```javascript
var idx = require( '@stdlib/array/index' );

var x = array2fancy( [ 1, 2, 3, 4 ], {
'strict': false
});
Expand All @@ -258,7 +269,8 @@ v = x[ '10:' ];
// returns []

// Access one or more out-of-bounds indices:
v = x[ idx( [ 10, 20 ] ) ];
var i = array2fancy.idx( [ 10, 20 ] );
v = x[ i ];
// throws <RangeError>
```

Expand All @@ -267,8 +279,6 @@ When `strict` is `true`, fancy arrays normalize index behavior and consistently
<!-- run throws: true -->

```javascript
var idx = require( '@stdlib/array/index' );

var x = array2fancy( [ 1, 2, 3, 4 ], {
'strict': true
});
Expand All @@ -289,7 +299,8 @@ v = x[ '10:' ];
// throws <RangeError>

// Access one or more out-of-bounds indices:
v = x[ idx( [ 10, 20 ] ) ];
var i = array2fancy.idx( [ 10, 20 ] );
v = x[ i ];
// throws <RangeError>
```

Expand Down Expand Up @@ -445,7 +456,6 @@ im = imag( v );
```javascript
var Uint8Array = require( '@stdlib/array/uint8' );
var Int32Array = require( '@stdlib/array/int32' );
var idx = require( '@stdlib/array/index' );
var array2fancy = require( '@stdlib/array/to-fancy' );

var x = [ 1, 2, 3, 4, 5, 6 ];
Expand All @@ -472,6 +482,8 @@ z = y[ ':' ];
// returns [ 1, 2, -10, -9, -8, 6 ]

// Array index retrieval:
var idx = array2fancy.idx;

var i = idx( [ 1, 3, 4 ] ); // integer index array
z = y[ i ];
// returns [ 2, -9, -8 ]
Expand Down
Loading

0 comments on commit 3fac561

Please sign in to comment.