Skip to content

Commit

Permalink
refactor: use more concise type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Nov 9, 2023
1 parent 2d6b2bc commit 467995e
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ import { Shape1D, Shape2D } from '@stdlib/types/ndarray';
*/
type Binary<T, U, V> = ( v1: T, v2: U ) => V;

/**
* Input array.
*/
type InputArray<T> = Array1D<T> | Array2D<T>;

/**
* Input array shape.
*/
type InputArrayShape = Shape1D | Shape2D;

/**
* Output array.
*/
type OutputArray<T> = Array2D<T>;

/**
* Output array shape.
*/
type OutputArrayShape = Shape2D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V> = [
InputArray<T>,
InputArray<U>,
OutputArray<V>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a two-dimensional nested output array.
*
Expand Down Expand Up @@ -62,7 +100,7 @@ type Binary<T, U, V> = ( v1: T, v2: U ) => V;
* console.log( z );
* // => [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ]
*/
declare function bbinary2d<T = unknown, U = unknown, V = unknown>( arrays: [ Array1D<T> | Array2D<T>, Array1D<U> | Array2D<U>, Array2D<V> ], shapes: [ Shape1D | Shape2D, Shape1D | Shape2D, Shape2D ], fcn: Binary<T, U, V> ): void;
declare function bbinary2d<T = unknown, U = unknown, V = unknown>( arrays: InOutArrays<T, U, V>, shapes: InOutShapes, fcn: Binary<T, U, V> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ type OutputArray<T> = Array3D<T>;
*/
type OutputArrayShape = Shape3D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V> = [
InputArray<T>,
InputArray<U>,
OutputArray<V>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a three-dimensional nested output array.
*
Expand Down Expand Up @@ -82,7 +100,7 @@ type OutputArrayShape = Shape3D;
* console.log( z );
* // => [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ]
*/
declare function bbinary3d<T = unknown, U = unknown, V = unknown>( arrays: [ InputArray<T>, InputArray<U>, OutputArray<V> ], shapes: [ InputArrayShape, InputArrayShape, OutputArrayShape ], fcn: Binary<T, U, V> ): void;
declare function bbinary3d<T = unknown, U = unknown, V = unknown>( arrays: InOutArrays<T, U, V>, shapes: InOutShapes, fcn: Binary<T, U, V> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ type OutputArray<T> = Array4D<T>;
*/
type OutputArrayShape = Shape4D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V> = [
InputArray<T>,
InputArray<U>,
OutputArray<V>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a four-dimensional nested output array.
*
Expand Down Expand Up @@ -82,7 +100,7 @@ type OutputArrayShape = Shape4D;
* console.log( z );
* // => [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ]
*/
declare function bbinary4d<T = unknown, U = unknown, V = unknown>( arrays: [ InputArray<T>, InputArray<U>, OutputArray<V> ], shapes: [ InputArrayShape, InputArrayShape, OutputArrayShape ], fcn: Binary<T, U, V> ): void;
declare function bbinary4d<T = unknown, U = unknown, V = unknown>( arrays: InOutArrays<T, U, V>, shapes: InOutShapes, fcn: Binary<T, U, V> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ type OutputArray<T> = Array5D<T>;
*/
type OutputArrayShape = Shape5D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V> = [
InputArray<T>,
InputArray<U>,
OutputArray<V>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a five-dimensional nested output array.
*
Expand Down Expand Up @@ -82,7 +100,7 @@ type OutputArrayShape = Shape5D;
* console.log( z );
* // => [ [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] ]
*/
declare function bbinary5d<T = unknown, U = unknown, V = unknown>( arrays: [ InputArray<T>, InputArray<U>, OutputArray<V> ], shapes: [ InputArrayShape, InputArrayShape, OutputArrayShape ], fcn: Binary<T, U, V> ): void;
declare function bbinary5d<T = unknown, U = unknown, V = unknown>( arrays: InOutArrays<T, U, V>, shapes: InOutShapes, fcn: Binary<T, U, V> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,48 @@ import { Shape1D, Shape2D } from '@stdlib/types/ndarray';
*/
type Quaternary<T, U, V, W, X> = ( v1: T, v2: U, v3: V, v4: W ) => X;

/**
* Input array.
*/
type InputArray<T> = Array1D<T> | Array2D<T>;

/**
* Input array shape.
*/
type InputArrayShape = Shape1D | Shape2D;

/**
* Output array.
*/
type OutputArray<T> = Array2D<T>;

/**
* Output array shape.
*/
type OutputArrayShape = Shape2D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V, W, X> = [
InputArray<T>,
InputArray<U>,
InputArray<V>,
InputArray<W>,
OutputArray<X>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a quaternary callback to elements in four broadcasted input arrays and assigns results to elements in a two-dimensional nested output array.
*
Expand Down Expand Up @@ -69,7 +111,7 @@ type Quaternary<T, U, V, W, X> = ( v1: T, v2: U, v3: V, v4: W ) => X;
* console.log( out );
* // => [ [ 4.0, 8.0 ], [ 12.0, 16.0 ] ]
*/
declare function bquaternary2d<T = unknown, U = unknown, V = unknown, W = unknown, X = unknown>( arrays: [ Array1D<T> | Array2D<T>, Array1D<U> | Array2D<U>, Array1D<V> | Array2D<V>, Array1D<W> | Array2D<W>, Array2D<X> ], shapes: [ Shape1D | Shape2D, Shape1D | Shape2D, Shape1D | Shape2D, Shape1D | Shape2D, Shape2D ], fcn: Quaternary<T, U, V, W, X> ): void;
declare function bquaternary2d<T = unknown, U = unknown, V = unknown, W = unknown, X = unknown>( arrays: InOutArrays<T, U, V, W, X>, shapes: InOutShapes, fcn: Quaternary<T, U, V, W, X> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,47 @@ import { Shape1D, Shape2D } from '@stdlib/types/ndarray';
type Quinary<T, U, V, W, X, Y> = ( v1: T, v2: U, v3: V, v4: W, v5: X ) => Y;

/**
* List of input and output arrays.
* Input array.
*/
type InputArray<T> = Array1D<T> | Array2D<T>;

/**
* Input array shape.
*/
type InputArrayShape = Shape1D | Shape2D;

/**
* Output array.
*/
type OutputArray<T> = Array2D<T>;

/**
* Output array shape.
*/
type OutputArrayShape = Shape2D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V, W, X, Y> = [
Array1D<T> | Array2D<T>,
Array1D<U> | Array2D<U>,
Array1D<V> | Array2D<V>,
Array1D<W> | Array2D<W>,
Array1D<X> | Array2D<X>,
Array2D<Y>
InputArray<T>,
InputArray<U>,
InputArray<V>,
InputArray<W>,
InputArray<X>,
OutputArray<Y>
];

/**
* List of input and output array shapes.
* Input and output array shapes.
*/
type InOutShapes = [
Shape1D | Shape2D,
Shape1D | Shape2D,
Shape1D | Shape2D,
Shape1D | Shape2D,
Shape1D | Shape2D,
Shape2D
InputArrayShape,
InputArrayShape,
InputArrayShape,
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ import { Shape1D, Shape2D } from '@stdlib/types/ndarray';
*/
type Ternary<T, U, V, W> = ( v1: T, v2: U, v3: V ) => W;

/**
* Input array.
*/
type InputArray<T> = Array1D<T> | Array2D<T>;

/**
* Input array shape.
*/
type InputArrayShape = Shape1D | Shape2D;

/**
* Output array.
*/
type OutputArray<T> = Array2D<T>;

/**
* Output array shape.
*/
type OutputArrayShape = Shape2D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U, V, W> = [
InputArray<T>,
InputArray<U>,
InputArray<V>,
OutputArray<W>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
InputArrayShape,
InputArrayShape,
OutputArrayShape
];

/**
* Applies a ternary callback to elements in three broadcasted input arrays and assigns results to elements in a two-dimensional nested output array.
*
Expand Down Expand Up @@ -67,7 +107,7 @@ type Ternary<T, U, V, W> = ( v1: T, v2: U, v3: V ) => W;
* console.log( out );
* // => [ [ 3.0, 6.0 ], [ 9.0, 12.0 ] ]
*/
declare function bternary2d<T = unknown, U = unknown, V = unknown, W = unknown>( arrays: [ Array1D<T> | Array2D<T>, Array1D<U> | Array2D<U>, Array1D<V> | Array2D<V>, Array2D<W> ], shapes: [ Shape1D | Shape2D, Shape1D | Shape2D, Shape1D | Shape2D, Shape2D ], fcn: Ternary<T, U, V, W> ): void;
declare function bternary2d<T = unknown, U = unknown, V = unknown, W = unknown>( arrays: InOutArrays<T, U, V, W>, shapes: InOutShapes, fcn: Ternary<T, U, V, W> ): void;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ import { Shape1D, Shape2D } from '@stdlib/types/ndarray';
*/
type Unary<T, U> = ( value: T ) => U;

/**
* Input array.
*/
type InputArray<T> = Array1D<T> | Array2D<T>;

/**
* Input array shape.
*/
type InputArrayShape = Shape1D | Shape2D;

/**
* Output array.
*/
type OutputArray<T> = Array2D<T>;

/**
* Output array shape.
*/
type OutputArrayShape = Shape2D;

/**
* Input and output arrays.
*/
type InOutArrays<T, U> = [
InputArray<T>,
OutputArray<U>
];

/**
* Input and output array shapes.
*/
type InOutShapes = [
InputArrayShape,
OutputArrayShape
];

/**
* Applies a unary callback to elements in a broadcasted nested input array and assigns results to elements in a two-dimensional nested output array.
*
Expand Down Expand Up @@ -63,7 +99,7 @@ type Unary<T, U> = ( value: T ) => U;
* console.log( y );
* // => [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ]
*/
declare function bunary2d<T = unknown, U = unknown>( arrays: [ Array1D<T> | Array2D<T>, Array2D<U> ], shapes: [ Shape1D | Shape2D, Shape2D ], fcn: Unary<T, U> ): void;
declare function bunary2d<T = unknown, U = unknown>( arrays: InOutArrays<T, U>, shapes: InOutShapes, fcn: Unary<T, U> ): void;


// EXPORTS //
Expand Down
Loading

0 comments on commit 467995e

Please sign in to comment.