@stdlib/strided
Version:
Strided.
129 lines (113 loc) • 3.43 kB
TypeScript
/*
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TypeScript Version: 4.1
/// <reference types="@stdlib/types"/>
import { ArrayLike } from '@stdlib/types/array';
import { Complex64, Complex128, ComplexLike } from '@stdlib/types/complex';
/**
* Default callback.
*
* @param x - input value
* @returns result
*/
type DefaultCallback = ( x: number ) => number;
/**
* Callback for single-precision complex floating-point numbers.
*
* @param x - input value
* @returns result
*/
type Complex64Callback = ( x: Complex64 ) => Complex64;
/**
* Callback for double-precision complex floating-point numbers.
*
* @param x - input value
* @returns result
*/
type Complex128Callback = ( x: Complex128 ) => Complex128;
/**
* Real or complex number.
*/
type RealOrComplex = number | ComplexLike;
/**
* Callback.
*/
type Callback = ( x: RealOrComplex ) => RealOrComplex;
/**
* Interface describing a callback table.
*/
interface Table {
/**
* Default callback.
*/
default: DefaultCallback;
/**
* Callback for single-precision complex floating-point numbers.
*/
complex64: Complex64Callback;
/**
* Callback for double-precision complex floating-point numbers.
*/
complex128: Complex128Callback;
}
/**
* Assigns callbacks to unary interfaces according to type promotion rules.
*
* ## Notes
*
* - The function assumes that the provided signature array has the following properties:
*
* - a strided array having a stride length of `2` (i.e., every `2` elements define a unary interface signature).
* - for each signature (i.e., set of two consecutive non-overlapping strided array elements), the first element is the input data type and the second element is the return data type.
* - all signatures follow type promotion rules.
*
* @param table - callback table
* @param table.default - default callback
* @param table.complex64 - callback for single-precision complex floating-point numbers
* @param table.complex128 - callback for double-precision complex floating-point numbers
* @param signatures - strided array containing unary interface signatures
* @returns list of callbacks
*
* @example
* var signatures = require( '@stdlib/strided/base/unary-dtype-signatures' );
* var identity = require( '@stdlib/math/base/special/identity' );
* var cidentity = require( '@stdlib/math/base/special/cidentity' );
* var cidentityf = require( '@stdlib/math/base/special/cidentityf' );
*
* var dtypes = [
* 'float64',
* 'float32',
* 'int32',
* 'uint8'
* ];
*
* var sigs = signatures( dtypes, dtypes );
* // returns [...]
*
* var table = {
* 'default': identity,
* 'complex64': cidentityf,
* 'complex128': cidentity
* };
*
* var list = callbacks( table, sigs );
* // returns [...]
*/
declare function callbacks( table: Table, signatures: ArrayLike<any> ): ArrayLike<Callback>;
// EXPORTS //
export = callbacks;