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 12 commits
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
172 changes: 2 additions & 170 deletions lib/node_modules/@stdlib/array/convert/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,175 +20,7 @@

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

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

/**
* Converts an array to a `Float64Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'float64' );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convert( x: Collection, dtype: 'float64' ): Float64Array;

/**
* Converts an array to a `Float32Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'float32' );
* // returns <Float32Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convert( x: Collection, dtype: 'float32' ): Float32Array;

/**
* Converts an array to an `Int32Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'int32' );
* // returns <Int32Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'int32' ): Int32Array;

/**
* Converts an array to an `Int16Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'int16' );
* // returns <Int16Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'int16' ): Int16Array;

/**
* Converts an array to an `Int8Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'int8' );
* // returns <Int8Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'int8' ): Int8Array;

/**
* Converts an array to a `Uint32Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'uint32' );
* // returns <Uint32Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'uint32' ): Uint32Array;

/**
* Converts an array to a `Uint16Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'uint16' );
* // returns <Uint16Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'uint16' ): Uint16Array;

/**
* Converts an array to a `Uint8Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'uint8' );
* // returns <Uint8Array>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'uint8' ): Uint8Array;

/**
* Converts an array to a `Uint8ClampedArray`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'uint8c' );
* // returns <Uint8ClampedArray>[ 1, 2, 3, 4 ]
*/
declare function convert( x: Collection, dtype: 'uint8c' ): Uint8ClampedArray;

/**
* Converts an array to a `Complex128Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'complex128' );
* // returns <Complex128>
*/
declare function convert( x: Collection, dtype: 'complex128' ): Complex128Array;

/**
* Converts an array to a `Complex64Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'complex64' );
* // returns <Complex64>
*/
declare function convert( x: Collection, dtype: 'complex64' ): Complex64Array;

/**
* Converts an array to an `Array`.
*
* @param x - array to convert
* @param dtype - output data type
* @returns output array
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0 ];
* var out = convert( arr, 'generic' );
* // returns [ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convert( x: Collection, dtype: 'generic' ): Array<any>;
import { Collection, ArrayDataTypeMap } from '@stdlib/types/array';

/**
* Converts an array to an array of a different data type.
Expand All @@ -202,7 +34,7 @@ declare function convert( x: Collection, dtype: 'generic' ): Array<any>;
* var out = convert( arr, 'float64' );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convert( x: Collection, dtype: DataType ): AnyArray;
declare function convert<T, U extends keyof ArrayDataTypeMap<T>>( x: Collection<T>, dtype: U ): ArrayDataTypeMap<T>[U];


// EXPORTS //
Expand Down
2 changes: 2 additions & 0 deletions lib/node_modules/@stdlib/array/convert/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import convert = require( './index' );
convert( [ 1.0, 2.0, 3.0, 4.0 ], 'uint8c' ); // $ExpectType Uint8ClampedArray
convert( [ 1.0, 2.0, 3.0, 4.0 ], 'complex128' ); // $ExpectType Complex128Array
convert( [ 1.0, 2.0, 3.0, 4.0 ], 'complex64' ); // $ExpectType Complex64Array
convert( [ 1.0, 2.0, 3.0, 4.0 ], 'generic' ); // $ExpectType number[]
convert( [ 'a', 'b', 'c', 'd' ], 'generic' ); // $ExpectType string[]
}

// The compiler throws an error if the function is provided a first argument which is not array-like...
Expand Down
Loading
Loading