Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use data type map instead of overloads #1317

Merged
merged 21 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a713ec2
refactor: use data type map instead of overloads
Planeshifter Feb 16, 2024
b9ead5e
refactor: use data type map instead of overloads
Planeshifter Feb 17, 2024
e3ba422
fix: use data type map instead of overloads and improve types
Planeshifter Feb 17, 2024
11eb9ad
fix: use data type map to improve return types
Planeshifter Feb 17, 2024
f969e7b
fix: use data type map instead of overloads and improve types
Planeshifter Feb 17, 2024
cddaee8
refactor: avoid duplication
Planeshifter Feb 17, 2024
2827f4e
feat: add additional fine-grained array type maps
Planeshifter Feb 17, 2024
0eed947
fix: use data type map to improve return types
Planeshifter Feb 17, 2024
d6f59b0
fix: use data type map to improve return types
Planeshifter Feb 17, 2024
534b236
refactor: use data type map and generic parameter to simplify
Planeshifter Feb 17, 2024
d43d99f
chore: remove extra space
Planeshifter Feb 17, 2024
94edd4c
refactor: remove unneeded generic parameter
Planeshifter Feb 17, 2024
b74bdbc
feat: rename and add additional type map types
Planeshifter Feb 22, 2024
44f5c26
feat: add and use remap utility type
Planeshifter Feb 22, 2024
efb404c
fix: ensure generic arrays yield numeric arrays as return type
Planeshifter Feb 22, 2024
ffc69be
Merge branch 'develop' into philipp/use-data-type-map
Planeshifter Feb 22, 2024
838a1d2
chore: fix indentation
Planeshifter Feb 22, 2024
90b3657
Apply suggestions from code review
kgryte Feb 22, 2024
855b5ac
fix: update import of complex type map and alias it
Planeshifter Feb 22, 2024
0aa9a99
refactor: use NumericAndGenericDataTypeMap due to numeric nature of f…
Planeshifter Feb 22, 2024
f5a6332
refactor: use DataTypeMap to convey empty array not necessarily being…
Planeshifter Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 8 additions & 219 deletions lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,228 +20,11 @@

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

import { Complex128Array, Complex64Array, DataType } from '@stdlib/types/array';
import { ArrayDataTypeMap } from '@stdlib/types/array';

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'float64' );
* // returns <Float64Array>
*/
declare function empty( length: number, dtype: 'float64' ): Float64Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'float32' );
* // returns <Float32Array>
*/
declare function empty( length: number, dtype: 'float32' ): Float32Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'complex128' );
* // returns <Complex128Array>
*/
declare function empty( length: number, dtype: 'complex128' ): Complex128Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'complex64' );
* // returns <Complex64Array>
*/
declare function empty( length: number, dtype: 'complex64' ): Complex64Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'int32' );
* // returns <Int32Array>
*/
declare function empty( length: number, dtype: 'int32' ): Int32Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'int16' );
* // returns <Int16Array>
*/
declare function empty( length: number, dtype: 'int16' ): Int16Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'int8' );
* // returns <Int8Array>
*/
declare function empty( length: number, dtype: 'int8' ): Int8Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'uint32' );
* // returns <Uint32Array>
*/
declare function empty( length: number, dtype: 'uint32' ): Uint32Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'uint16' );
* // returns <Uint16Array>
*/
declare function empty( length: number, dtype: 'uint16' ): Uint16Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'uint8' );
* // returns <Uint8Array>
*/
declare function empty( length: number, dtype: 'uint8' ): Uint8Array;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type
* @returns empty array
*
* @example
* var arr = empty( 2, 'uint8c' );
* // returns <Uint8ClampedArray>
*/
declare function empty( length: number, dtype: 'uint8c' ): Uint8ClampedArray;

/**
* Creates a zero-filled array having a specified length.
*
* @param length - array length
* @param dtype - data type
* @returns zero-filled array
*
* @example
* var arr = empty( 2, 'generic' );
* // returns
*/
declare function empty( length: number, dtype: 'generic' ): Array<number>;

/**
* Creates an uninitialized array having a specified length.
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - If `dtype` is `'generic'`, the function always returns a zero-filled array.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* The function recognizes the following data types:
*
* - `float64`: double-precision floating-point numbers (IEEE 754)
Expand All @@ -257,6 +40,12 @@ declare function empty( length: number, dtype: 'generic' ): Array<number>;
* - `uint8c`: 8-bit unsigned integers clamped to `0-255`
* - `generic`: generic JavaScript values
*
* ## Notes
*
* - In browser environments, the function always returns zero-filled arrays.
* - If `dtype` is `'generic'`, the function always returns a zero-filled array.
* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.
*
* @param length - array length
* @param dtype - data type (default: 'float64')
* @returns empty array
Expand All @@ -269,7 +58,7 @@ declare function empty( length: number, dtype: 'generic' ): Array<number>;
* var arr = empty( 2, 'float32' );
* // returns <Float32Array>
*/
declare function empty( length: number, dtype?: DataType ): Float64Array;
declare function empty<T extends keyof ArrayDataTypeMap<number> = 'float64'>( length: number, dtype?: T ): ArrayDataTypeMap<number>[T];


// EXPORTS //
Expand Down
31 changes: 31 additions & 0 deletions lib/node_modules/@stdlib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,37 @@
* const x: Collection<number> = [ 1, 2, 3 ];
*/
type Collection<T = any> = Array<T> | TypedArray | ArrayLike<T>; // eslint-disable-line @typescript-eslint/no-explicit-any

/**
* Type mapping for the following array data types:
*
* - `float64`: double-precision floating-point numbers (IEEE 754)
* - `float32`: single-precision floating-point numbers (IEEE 754)
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
* - `complex128`: double-precision complex floating-point numbers
* - `complex64`: single-precision complex floating-point numbers
* - `int32`: 32-bit two's complement signed integers
* - `uint32`: 32-bit unsigned integers
* - `int16`: 16-bit two's complement signed integers
* - `uint16`: 16-bit unsigned integers
* - `int8`: 8-bit two's complement signed integers
* - `uint8`: 8-bit unsigned integers
* - `uint8c`: 8-bit unsigned integers clamped to `0-255`
* - `generic`: generic JavaScript values
*/
type ArrayDataTypeMap<T> = { // eslint-disable-line @typescript-eslint/consistent-type-definitions
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
'float64': Float64Array;
'float32': Float32Array;
'complex128': Complex128Array;
'complex64': Complex64Array;
'int32': Int32Array;
'uint32': Uint32Array;
'int16': Int16Array;
'uint16': Uint16Array;
'int8': Int8Array;
'uint8': Uint8Array;
'uint8c': Uint8ClampedArray;
'generic': Array<T>;
};
}

/**
Expand Down Expand Up @@ -2728,7 +2759,7 @@
/**
* Value associated with a property (default: `undefined`).
*/
value?: any;

Check warning on line 2762 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -2762,7 +2793,7 @@
* - When the property is accessed, the function is called without arguments and with `this` set to the object through which the property is accessed (note: this may **not** be the object on which the property is defined due to inheritance).
* - The return value will be used as the value of the property.
*/
get?(): any;

Check warning on line 2796 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* A function which serves as a setter for the property.
Expand All @@ -2772,7 +2803,7 @@
* - If omitted from a descriptor, a property value cannot be assigned.
* - When the property is assigned to, the function is called with one argument (the value being assigned to the property) and with `this` set to the object through which the property is assigned.
*/
set?( x: any ): void;

Check warning on line 2806 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -2901,7 +2932,7 @@
* @example
* const rand: PRNG = () => 3.14;
*/
type PRNG = ( ...args: Array<any> ) => number;

Check warning on line 2935 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* A pseudorandom number generator (PRNG) seed for the 32-bit Mersenne Twister (MT19937) PRNG.
Expand Down
Loading