/* * @license Apache-2.0 * * Copyright (c) 2023 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 /// import { Collection, Array4D } from '@stdlib/types/array'; import { Shape4D } from '@stdlib/types/ndarray'; /** * Nullary callback function. * * @returns result */ type Nullary = ( this: V ) => U; /** * Unary callback function. * * @param value - array element * @returns result */ type Unary = ( this: V, value: T ) => U; /** * Binary callback function. * * @param value - array element * @param indices - element indices * @returns result */ type Binary = ( this: V, value: T, indices: Array ) => U; /** * Ternary callback function. * * @param value - array element * @param indices - element indices * @param arr - input array * @returns result */ type Ternary = ( this: V, value: T, indices: Array, arr: Array4D ) => U; /** * Callback function. * * @param value - array element * @param indices - element indices * @param arr - input array * @returns result */ type Callback = Nullary | Unary | Binary | Ternary; /** * Interface describing `flatten4dBy`. */ interface Flatten4dBy { /** * Flattens a four-dimensional nested array according to a callback function. * * ## Notes * * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). * * @param x - input array * @param shape - array shape * @param colexicographic - specifies whether to flatten array values in colexicographic order * @param clbk - callback function * @param thisArg - callback execution context * @returns flattened array * * @example * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy( x, [ 2, 1, 1, 2 ], false, scale ); * // returns [ 2, 4, 6, 8 ] * * @example * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy( x, [ 2, 1, 1, 2 ], true, scale ); * // returns [ 2, 6, 4, 8 ] */ ( x: Array4D, shape: Shape4D, colexicographic: boolean, clbk: Callback, thisArg?: ThisParameterType> ): Array; /** * Flattens a four-dimensional nested array according to a callback function and assigns elements to a provided output array. * * ## Notes * * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). * * @param x - input array * @param shape - array shape * @param colexicographic - specifies whether to flatten array values in colexicographic order * @param out - output array * @param stride - output array stride * @param offset - output array index offset * @param clbk - callback function * @param thisArg - callback execution context * @returns output array * * @example * var Float64Array = require( './../../../../float64' ); * * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy.assign( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0, scale ); * // returns [ 2, 4, 6, 8 ] * * @example * var Float64Array = require( './../../../../float64' ); * * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy.assign( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0, scale ); * // returns [ 2, 6, 4, 8 ] */ assign( x: Array4D, shape: Shape4D, colexicographic: boolean, out: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; } /** * Flattens a four-dimensional nested array according to a callback function. * * ## Notes * * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array). * * @param x - input array * @param shape - array shape * @param colexicographic - specifies whether to flatten array values in colexicographic order * @returns flattened array * * @example * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy( x, [ 2, 1, 1, 2 ], false, scale ); * // returns [ 2, 4, 6, 8 ] * * @example * function scale( v ) { * return v * 2; * } * * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ]; * * var out = flatten4dBy( x, [ 2, 1, 1, 2 ], true, scale ); * // returns [ 2, 6, 4, 8 ] */ declare var flatten4dBy: Flatten4dBy; // EXPORTS // export = flatten4dBy;