UNPKG

@stdlib/array

Version:
1,654 lines (1,592 loc) 122 kB
/* * @license Apache-2.0 * * Copyright (c) 2021 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 /* eslint-disable max-lines */ import AccessorArray = require( './../../../base/accessor' ); import accessorGetter = require( './../../../base/accessor-getter' ); import accessorSetter = require( './../../../base/accessor-setter' ); import accessors = require( './../../../base/accessors' ); import any = require( './../../../base/any' ); import anyBy = require( './../../../base/any-by' ); import anyByRight = require( './../../../base/any-by-right' ); import arraylike2object = require( './../../../base/arraylike2object' ); import assert = require( './../../../base/assert' ); import at = require( './../../../base/at' ); import at2d = require( './../../../base/at2d' ); import at3d = require( './../../../base/at3d' ); import at4d = require( './../../../base/at4d' ); import at5d = require( './../../../base/at5d' ); import atnd = require( './../../../base/atnd' ); import bifurcateEntries = require( './../../../base/bifurcate-entries' ); import bifurcateEntriesBy = require( './../../../base/bifurcate-entries-by' ); import bifurcateIndices = require( './../../../base/bifurcate-indices' ); import bifurcateIndicesBy = require( './../../../base/bifurcate-indices-by' ); import bifurcateValues = require( './../../../base/bifurcate-values' ); import bifurcateValuesBy = require( './../../../base/bifurcate-values-by' ); import binary2d = require( './../../../base/binary2d' ); import binary3d = require( './../../../base/binary3d' ); import binary4d = require( './../../../base/binary4d' ); import binary5d = require( './../../../base/binary5d' ); import binarynd = require( './../../../base/binarynd' ); import broadcastArray = require( './../../../base/broadcast-array' ); import bbinary2d = require( './../../../base/broadcasted-binary2d' ); import bbinary3d = require( './../../../base/broadcasted-binary3d' ); import bbinary4d = require( './../../../base/broadcasted-binary4d' ); import bbinary5d = require( './../../../base/broadcasted-binary5d' ); import bquaternary2d = require( './../../../base/broadcasted-quaternary2d' ); import bquinary2d = require( './../../../base/broadcasted-quinary2d' ); import bternary2d = require( './../../../base/broadcasted-ternary2d' ); import bunary2d = require( './../../../base/broadcasted-unary2d' ); import bunary3d = require( './../../../base/broadcasted-unary3d' ); import bunary4d = require( './../../../base/broadcasted-unary4d' ); import bunary5d = require( './../../../base/broadcasted-unary5d' ); import cartesianPower = require( './../../../base/cartesian-power' ); import cartesianProduct = require( './../../../base/cartesian-product' ); import cartesianSquare = require( './../../../base/cartesian-square' ); import copy = require( './../../../base/copy' ); import copyIndexed = require( './../../../base/copy-indexed' ); import countFalsy = require( './../../../base/count-falsy' ); import countIf = require( './../../../base/count-if' ); import countSameValue = require( './../../../base/count-same-value' ); import countSameValueZero = require( './../../../base/count-same-value-zero' ); import countTruthy = require( './../../../base/count-truthy' ); import cuany = require( './../../../base/cuany' ); import cuevery = require( './../../../base/cuevery' ); import dedupe = require( './../../../base/dedupe' ); import every = require( './../../../base/every' ); import everyBy = require( './../../../base/every-by' ); import everyByRight = require( './../../../base/every-by-right' ); import fancySlice = require( './../../../base/fancy-slice' ); import fancySliceAssign = require( './../../../base/fancy-slice-assign' ); import filled = require( './../../../base/filled' ); import filledBy = require( './../../../base/filled-by' ); import filled2d = require( './../../../base/filled2d' ); import filled2dBy = require( './../../../base/filled2d-by' ); import filled3d = require( './../../../base/filled3d' ); import filled3dBy = require( './../../../base/filled3d-by' ); import filled4d = require( './../../../base/filled4d' ); import filled4dBy = require( './../../../base/filled4d-by' ); import filled5d = require( './../../../base/filled5d' ); import filled5dBy = require( './../../../base/filled5d-by' ); import fillednd = require( './../../../base/fillednd' ); import filledndBy = require( './../../../base/fillednd-by' ); import filter = require( './../../../base/filter' ); import first = require( './../../../base/first' ); import flatten = require( './../../../base/flatten' ); import flattenBy = require( './../../../base/flatten-by' ); import flatten2d = require( './../../../base/flatten2d' ); import flatten2dBy = require( './../../../base/flatten2d-by' ); import flatten3d = require( './../../../base/flatten3d' ); import flatten3dBy = require( './../../../base/flatten3d-by' ); import flatten4d = require( './../../../base/flatten4d' ); import flatten4dBy = require( './../../../base/flatten4d-by' ); import flatten5d = require( './../../../base/flatten5d' ); import flatten5dBy = require( './../../../base/flatten5d-by' ); import fliplr2d = require( './../../../base/fliplr2d' ); import fliplr3d = require( './../../../base/fliplr3d' ); import fliplr4d = require( './../../../base/fliplr4d' ); import fliplr5d = require( './../../../base/fliplr5d' ); import flipud2d = require( './../../../base/flipud2d' ); import flipud3d = require( './../../../base/flipud3d' ); import flipud4d = require( './../../../base/flipud4d' ); import flipud5d = require( './../../../base/flipud5d' ); import strided2array = require( './../../../base/from-strided' ); import getter = require( './../../../base/getter' ); import groupEntries = require( './../../../base/group-entries' ); import groupEntriesBy = require( './../../../base/group-entries-by' ); import groupIndices = require( './../../../base/group-indices' ); import groupIndicesBy = require( './../../../base/group-indices-by' ); import groupValues = require( './../../../base/group-values' ); import groupValuesBy = require( './../../../base/group-values-by' ); import incrspace = require( './../../../base/incrspace' ); import indexOf = require( './../../../base/index-of' ); import join = require( './../../../base/join' ); import last = require( './../../../base/last' ); import lastIndexOf = require( './../../../base/last-index-of' ); import linspace = require( './../../../base/linspace' ); import logspace = require( './../../../base/logspace' ); import map2d = require( './../../../base/map2d' ); import map3d = require( './../../../base/map3d' ); import map4d = require( './../../../base/map4d' ); import map5d = require( './../../../base/map5d' ); import minSignedIntegerDataType = require( './../../../base/min-signed-integer-dtype' ); import minUnsignedIntegerDataType = require( './../../../base/min-unsigned-integer-dtype' ); import mskbinary2d = require( './../../../base/mskbinary2d' ); import mskfilter = require( './../../../base/mskfilter' ); import mskput = require( './../../../base/mskput' ); import mskreject = require( './../../../base/mskreject' ); import mskunary2d = require( './../../../base/mskunary2d' ); import mskunary3d = require( './../../../base/mskunary3d' ); import nCartesianProduct = require( './../../../base/n-cartesian-product' ); import none = require( './../../../base/none' ); import noneBy = require( './../../../base/none-by' ); import noneByRight = require( './../../../base/none-by-right' ); import oneTo = require( './../../../base/one-to' ); import ones = require( './../../../base/ones' ); import ones2d = require( './../../../base/ones2d' ); import ones3d = require( './../../../base/ones3d' ); import ones4d = require( './../../../base/ones4d' ); import ones5d = require( './../../../base/ones5d' ); import onesnd = require( './../../../base/onesnd' ); import place = require( './../../../base/place' ); import put = require( './../../../base/put' ); import quaternary2d = require( './../../../base/quaternary2d' ); import quaternary3d = require( './../../../base/quaternary3d' ); import quaternary4d = require( './../../../base/quaternary4d' ); import quaternary5d = require( './../../../base/quaternary5d' ); import quinary2d = require( './../../../base/quinary2d' ); import quinary3d = require( './../../../base/quinary3d' ); import quinary4d = require( './../../../base/quinary4d' ); import quinary5d = require( './../../../base/quinary5d' ); import reject = require( './../../../base/reject' ); import resolveGetter = require( './../../../base/resolve-getter' ); import resolveSetter = require( './../../../base/resolve-setter' ); import reverse = require( './../../../base/reverse' ); import setter = require( './../../../base/setter' ); import slice = require( './../../../base/slice' ); import strided2array2d = require( './../../../base/strided2array2d' ); import strided2array3d = require( './../../../base/strided2array3d' ); import strided2array4d = require( './../../../base/strided2array4d' ); import strided2array5d = require( './../../../base/strided2array5d' ); import take = require( './../../../base/take' ); import takeIndexed = require( './../../../base/take-indexed' ); import take2d = require( './../../../base/take2d' ); import take3d = require( './../../../base/take3d' ); import ternary2d = require( './../../../base/ternary2d' ); import ternary3d = require( './../../../base/ternary3d' ); import ternary4d = require( './../../../base/ternary4d' ); import ternary5d = require( './../../../base/ternary5d' ); import toAccessorArray = require( './../../../base/to-accessor-array' ); import toDeduped = require( './../../../base/to-deduped' ); import toReversed = require( './../../../base/to-reversed' ); import unary2d = require( './../../../base/unary2d' ); import unary2dBy = require( './../../../base/unary2d-by' ); import unary3d = require( './../../../base/unary3d' ); import unary4d = require( './../../../base/unary4d' ); import unary5d = require( './../../../base/unary5d' ); import unarynd = require( './../../../base/unarynd' ); import unitspace = require( './../../../base/unitspace' ); import where = require( './../../../base/where' ); import arrayWith = require( './../../../base/with' ); import zeroTo = require( './../../../base/zero-to' ); import zeros = require( './../../../base/zeros' ); import zeros2d = require( './../../../base/zeros2d' ); import zeros3d = require( './../../../base/zeros3d' ); import zeros4d = require( './../../../base/zeros4d' ); import zeros5d = require( './../../../base/zeros5d' ); import zerosnd = require( './../../../base/zerosnd' ); /** * Interface describing the `base` namespace. */ interface Namespace { /** * Accessor array constructor. * * @param arr - input array * @returns accessor array * * @example * var arr = new ns.AccessorArray( [ 1, 2, 3 ] ); * // returns <ns.AccessorArray> * * var v = arr.get( 0 ); * // returns 1 */ AccessorArray: typeof AccessorArray; /** * Returns an accessor function for retrieving an element from an array-like object supporting the get/set protocol. * * @param dtype - data type * @returns accessor function * * @example * var arr = [ 1, 2, 3, 4 ]; * * function aget( idx ) { * return arr[ idx ]; * } * * function aset( value, idx ) { * arr[ idx ] = value; * } * * arr.get = aget; * arr.set = aset; * * var get = ns.accessorGetter( 'foo' ); * var v = get( arr, 2 ); * // returns 3 */ accessorGetter: typeof accessorGetter; /** * Returns an accessor function for setting an element in an array-like object supporting the get/set protocol. * * @param dtype - data type * @returns accessor function * * @example * var arr = [ 1, 2, 3, 4 ]; * * function aget( idx ) { * return arr[ idx ]; * } * * function aset( value, idx ) { * arr[ idx ] = value; * } * * arr.get = aget; * arr.set = aset; * * var set = ns.accessorSetter( 'foo' ); * set( arr, 2, 10 ); * * var v = arr.get( 2 ); * // returns 3 */ accessorSetter: typeof accessorSetter; /** * Returns element accessors for a provided array-like object. * * ## Notes * * - The intent of this function is to provide a minimal abstraction over how elements are accessed when operating on indexed (i.e., array-like objects supporting element accesss via integer indices using bracket `[]` syntax) and accessor (i.e., array-like objects supporting the get/set protocol in which explicit `get` and `set` methods are used for element access) array-like objects. * * @param x - input array * @returns object containing accessor data * * @example * var x = { * '0': 1, * '1': 2, * '2': 3, * '4': 4, * 'length': 4 * }; * var obj = ns.accessors( x ); * // returns {...} * * var bool = obj.accessorProtocol; * // returns false * * var fcns = obj.ns.accessors; * // returns [ <Function>, <Function> ] * * var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ accessors: typeof accessors; /** * Tests whether at least one element in an array is truthy. * * ## Notes * * - The function immediately returns upon encountering a truthy value. * - If provided an empty collection, the function returns `false`. * * @param x - input array * @returns boolean indicating whether at least one element is truthy * * @example * var x = [ 0, 0, 1, 0 ]; * * var out = ns.any( x ); * // returns true */ any: typeof any; /** * Tests whether at least one element in an array passes a test implemented by a predicate function. * * ## Notes * * - The function immediately returns upon encountering a truthy return value. * - If provided an empty collection, the function returns `false`. * * @param x - input array * @param predicate - predicate function * @param thisArg - predicate function execution context * @returns boolean indicating whether all elements pass a test * * @example * function isPositive( v ) { * return v > 0; * } * * var x = [ 0, 0, 1, 0 ]; * * var out = ns.anyBy( x, isPositive ); * // returns true */ anyBy: typeof anyBy; /** * Tests whether at least one element in an array passes a test implemented by a predicate function, while iterating from right to left. * * ## Notes * * - The function immediately returns upon encountering a truthy return value. * - If provided an empty collection, the function returns `false`. * * @param x - input array * @param predicate - predicate function * @param thisArg - predicate function execution context * @returns boolean indicating whether all elements pass a test * * @example * function isPositive( v ) { * return v > 0; * } * * var x = [ 0, 0, 1, 0 ]; * * var out = ns.anyByRight( x, isPositive ); * // returns true */ anyByRight: typeof anyByRight; /** * Converts a one-dimensional array-like object to an object likely to have the same "shape". * * ## Notes * * - This function is intended as a potential performance optimization. In V8, for example, even if two objects share common properties, if those properties were added in different orders or if one object has additional properties not shared by the other object, then those objects will have different "hidden" classes. If a function is provided many objects having different "shapes", some JavaScript VMs (e.g., V8) will consider the function "megamorphic" and fail to perform various runtime optimizations. Accordingly, the intent of this function is to standardize the "shape" of the object holding array data to ensure that internal functions operating on arrays are provided consistent argument "shapes". * * @param x - input array * @returns object containing array data * * @example * var x = { * '0': 1, * '1': 2, * '2': 3, * '4': 4, * 'length': 4 * }; * var obj = ns.arraylike2object( x ); * // returns {...} * * var bool = obj.accessorProtocol; * // returns false * * var fcns = obj.accessors; * // returns [ <Function>, <Function> ] * * var v = fcns[ 0 ]( x.data, 2 ); * // returns 3 */ arraylike2object: typeof arraylike2object; /** * Base array assertion utilities. */ assert: typeof assert; /** * Returns an element from an array. * * @param x - input array * @param index - element index * @returns array element * * @example * var x = [ 1, 2, 3, 4 ]; * * var v = ns.at( x, 0 ); * // returns 1 * * v = ns.at( x, 1 ); * // returns 2 * * v = ns.at( x, -2 ); * // returns 3 */ at: typeof at; /** * Returns an element from a two-dimensional nested array. * * @param x - input array * @param i0 - first dimension index * @param i1 - second dimension index * @returns nested array element * * @example * var x = [ [ 1, 2 ], [ 3, 4 ] ]; * * var v = ns.at2d( x, 0, 1 ); * // returns 2 * * v = ns.at2d( x, 1, 0 ); * // returns 3 * * v = ns.at2d( x, -2, -2 ); * // returns 1 */ at2d: typeof at2d; /** * Returns an element from a three-dimensional nested array. * * @param x - input array * @param i0 - first dimension index * @param i1 - second dimension index * @param i2 - third dimension index * @returns nested array element * * @example * var x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; * * var v = ns.at3d( x, 0, 0, 1 ); * // returns 2 * * v = ns.at3d( x, 0, 1, 0 ); * // returns 3 * * v = ns.at3d( x, -1, -2, -2 ); * // returns 1 */ at3d: typeof at3d; /** * Returns an element from a four-dimensional nested array. * * @param x - input array * @param i0 - first dimension index * @param i1 - second dimension index * @param i2 - third dimension index * @param i3 - fourth dimension index * @returns nested array element * * @example * var x = [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ]; * * var v = ns.at4d( x, 0, 0, 0, 1 ); * // returns 2 * * v = ns.at4d( x, 0, 0, 1, 0 ); * // returns 3 * * v = ns.at4d( x, -1, -1, -2, -2 ); * // returns 1 */ at4d: typeof at4d; /** * Returns an element from a five-dimensional nested array. * * @param x - input array * @param i0 - first dimension index * @param i1 - second dimension index * @param i2 - third dimension index * @param i3 - fourth dimension index * @param i4 - fifth dimension index * @returns nested array element * * @example * var x = [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ]; * * var v = ns.at5d( x, 0, 0, 0, 0, 1 ); * // returns 2 * * v = ns.at5d( x, 0, 0, 0, 1, 0 ); * // returns 3 * * v = ns.at5d( x, -1, -1, -1, -2, -2 ); * // returns 1 */ at5d: typeof at5d; /** * Returns an element from an n-dimensional nested array. * * @param x - input array * @param i0 - first dimension index * @param indices - dimension indices * @returns nested array element * * @example * var x = [ [ 1, 2 ], [ 3, 4 ] ]; * * var v = ns.atnd( x, 0, 1 ); * // returns 2 * * v = ns.atnd( x, 1, 0 ); * // returns 3 * * v = ns.atnd( x, -2, -2 ); * // returns 1 */ atnd: typeof atnd; /** * Splits array element entries into two groups. * * @param x - input array * @param filter - array indicating which group an element in the input array belongs to * @returns results * * @example * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * var filter = [ true, true, false, true ]; * * var out = ns.bifurcateEntries( arr, filter ); * // returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ] */ bifurcateEntries: typeof bifurcateEntries; /** * Splits element entries into two groups according to a predicate function. * * ## Notes * * - If a predicate function returns a truthy value, an array value is placed in the first group; otherwise, an array value is placed in the second group. * * @param x - input array * @param predicate - predicate function specifying which group an element in the input array belongs to * @param thisArg - predicate function execution context * @returns group results * * @example * function predicate( v ) { * return v[ 0 ] === 'b'; * } * * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * * var out = ns.bifurcateEntriesBy( x, predicate ); * // returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ] */ bifurcateEntriesBy: typeof bifurcateEntriesBy; /** * Splits array element indices into two groups. * * @param x - input array * @param filter - array indicating which group an element in the input array belongs to * @returns results * * @example * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * var filter = [ true, true, false, true ]; * * var out = ns.bifurcateIndices( arr, filter ); * // returns [ [ 0, 1, 3 ], [ 2 ] ] */ bifurcateIndices: typeof bifurcateIndices; /** * Splits element indices into two groups according to a predicate function. * * ## Notes * * - If a predicate function returns a truthy value, an array value is placed in the first group; otherwise, an array value is placed in the second group. * * @param x - input array * @param predicate - predicate function specifying which group an element in the input array belongs to * @param thisArg - predicate function execution context * @returns group results * * @example * function predicate( v ) { * return v[ 0 ] === 'b'; * } * * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * * var out = ns.bifurcateIndicesBy( x, predicate ); * // returns [ [ 0, 1, 3 ], [ 2 ] ] */ bifurcateIndicesBy: typeof bifurcateIndicesBy; /** * Splits array element values into two groups. * * @param x - input array * @param filter - array indicating which group an element in the input array belongs to * @returns results * * @example * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * var filter = [ true, true, false, true ]; * * var out = ns.bifurcateValues( arr, filter ); * // returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] */ bifurcateValues: typeof bifurcateValues; /** * Splits element values into two groups according to a predicate function. * * ## Notes * * - If a predicate function returns a truthy value, an array value is placed in the first group; otherwise, an array value is placed in the second group. * * @param x - input array * @param predicate - predicate function specifying which group an element in the input array belongs to * @param thisArg - predicate function execution context * @returns group results * * @example * function predicate( v ) { * return v[ 0 ] === 'b'; * } * * var x = [ 'beep', 'boop', 'foo', 'bar' ]; * * var out = ns.bifurcateValuesBy( x, predicate ); * // returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] */ bifurcateValuesBy: typeof bifurcateValuesBy; /** * Applies a binary callback to elements in two two-dimensional nested input arrays and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The function assumes that the input and output arrays have the same shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shape - array shape * @param fcn - binary callback * * @example * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shape = [ 2, 2 ]; * * var x = ones2d( shape ); * var y = ones2d( shape ); * var z = zeros2d( shape ); * * ns.binary2d( [ x, y, z ], shape, add ); * * console.log( z ); * // => [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] */ binary2d: typeof binary2d; /** * Applies a binary callback to elements in two three-dimensional nested input arrays and assigns results to elements in a three-dimensional nested output array. * * ## Notes * * - The function assumes that the input and output arrays have the same shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shape - array shape * @param fcn - binary callback * * @example * var ones3d = require( './../../../base/ones3d' ); * var zeros3d = require( './../../../base/zeros3d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shape = [ 2, 2, 2 ]; * * var x = ones3d( shape ); * var y = ones3d( shape ); * var z = zeros3d( shape ); * * ns.binary3d( [ x, y, z ], shape, add ); * * console.log( z ); * // => [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] */ binary3d: typeof binary3d; /** * Applies a binary callback to elements in two four-dimensional nested input arrays and assigns results to elements in a four-dimensional nested output array. * * ## Notes * * - The function assumes that the input and output arrays have the same shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shape - array shape * @param fcn - binary callback * * @example * var ones4d = require( './../../../base/ones4d' ); * var zeros4d = require( './../../../base/zeros4d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shape = [ 1, 2, 2, 2 ]; * * var x = ones4d( shape ); * var y = ones4d( shape ); * var z = zeros4d( shape ); * * ns.binary4d( [ x, y, z ], shape, add ); * * console.log( z ); * // => [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] */ binary4d: typeof binary4d; /** * Applies a binary callback to elements in two five-dimensional nested input arrays and assigns results to elements in a five-dimensional nested output array. * * ## Notes * * - The function assumes that the input and output arrays have the same shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shape - array shape * @param fcn - binary callback * * @example * var ones5d = require( './../../../base/ones5d' ); * var zeros5d = require( './../../../base/zeros5d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shape = [ 1, 1, 2, 2, 2 ]; * * var x = ones5d( shape ); * var y = ones5d( shape ); * var z = zeros5d( shape ); * * ns.binary5d( [ x, y, z ], shape, add ); * * console.log( z ); * // => [ [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] ] */ binary5d: typeof binary5d; /** * Applies a binary callback to elements in two n-dimensional nested input arrays and assigns results to elements in an n-dimensional nested output array. * * ## Notes * * - The function assumes that the input and output arrays have the same shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shape - array shape * @param fcn - binary callback * * @example * var add = require( '@stdlib/math/base/ops/add' ); * var onesnd = require( './../../../base/onesnd' ); * var zerosnd = require( './../../../base/zerosnd' ); * * var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ]; * * var x = onesnd( shape ); * var y = onesnd( shape ); * var z = zerosnd( shape ); * * ns.binarynd( [ x, y, z ], shape, add ); * * console.log( z ); * // => [ [ [ [ [ [ [ [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] ] ] ] ] ] ] ] */ binarynd: typeof binarynd; /** * Broadcasts an array to a specified shape. * * ## Notes * * - The broadcasted array shares the same data as the input array. As more than one element of a broadcasted array may refer to the same memory location, writing to the broadcasted array may affect multiple elements. If you need to write to the broadcasted array, copy the array before performing operations which may mutate elements. * - The function throws an error if a provided input shape is incompatible with a provided output shape. * * @param x - input array * @param inShape - input array shape * @param outShape - output array shape * @throws input array cannot have more dimensions than the desired shape * @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided output shape * @returns broadcast object * * @example * var x = [ 1, 2 ]; * * var out = ns.broadcastArray( x, [ 2 ], [ 2, 2 ] ); * // returns {...} * * var shape = out.shape; * // returns [ 2, 2 ] * * var strides = out.strides; * // returns [ 0, 1 ] * * var ref = out.ref; * // returns [ 1, 2 ] * * var bool = ( x === ref ); * // returns true * * var data = out.data; * // returns [ [ 1, 2 ] ] * * @example * var x = [ 1, 2 ]; * * var out = ns.broadcastArray( x, [ 2 ], [ 2, 1, 2 ] ); * // returns {...} * * var data = out.data; * // returns [ [ [ 1, 2 ] ] ] * * var strides = out.strides; * // returns [ 0, 0, 1 ] * * @example * var x = [ [ 1 ], [ 2 ] ]; * * var out = ns.broadcastArray( x, [ 2, 1 ], [ 3, 2, 2 ] ); * // returns {...} * * var data = out.data; * // returns [ [ [ 1 ], [ 2 ] ] ] * * var strides = out.strides; * // returns [ 0, 1, 0 ] */ broadcastArray: typeof broadcastArray; /** * Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - binary callback * * @example * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shapes = [ * [ 1, 2 ], * [ 2, 1 ], * [ 2, 2 ] * ]; * * var x = ones2d( shapes[ 0 ] ); * var y = ones2d( shapes[ 1 ] ); * var z = zeros2d( shapes[ 2 ] ); * * ns.bbinary2d( [ x, y, z ], shapes, add ); * * console.log( z ); * // => [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] */ bbinary2d: typeof bbinary2d; /** * Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a three-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - binary callback * * @example * var ones3d = require( './../../../base/ones3d' ); * var zeros3d = require( './../../../base/zeros3d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shapes = [ * [ 1, 1, 2 ], * [ 2, 1, 1 ], * [ 2, 2, 2 ] * ]; * * var x = ones3d( shapes[ 0 ] ); * var y = ones3d( shapes[ 1 ] ); * var z = zeros3d( shapes[ 2 ] ); * * ns.bbinary3d( [ x, y, z ], shapes, add ); * * console.log( z ); * // => [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] */ bbinary3d: typeof bbinary3d; /** * Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a four-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - binary callback * * @example * var ones4d = require( './../../../base/ones4d' ); * var zeros4d = require( './../../../base/zeros4d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shapes = [ * [ 1, 1, 1, 2 ], * [ 1, 2, 1, 1 ], * [ 1, 2, 2, 2 ] * ]; * * var x = ones4d( shapes[ 0 ] ); * var y = ones4d( shapes[ 1 ] ); * var z = zeros4d( shapes[ 2 ] ); * * ns.bbinary4d( [ x, y, z ], shapes, add ); * * console.log( z ); * // => [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] */ bbinary4d: typeof bbinary4d; /** * Applies a binary callback to elements in two broadcasted input arrays and assigns results to elements in a five-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing two input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - binary callback * * @example * var ones5d = require( './../../../base/ones5d' ); * var zeros5d = require( './../../../base/zeros5d' ); * var add = require( '@stdlib/math/base/ops/add' ); * * var shapes = [ * [ 1, 1, 1, 1, 2 ], * [ 1, 1, 2, 1, 1 ], * [ 1, 1, 2, 2, 2 ] * ]; * * var x = ones5d( shapes[ 0 ] ); * var y = ones5d( shapes[ 1 ] ); * var z = zeros5d( shapes[ 2 ] ); * * ns.bbinary5d( [ x, y, z ], shapes, add ); * * console.log( z ); * // => [ [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] ] */ bbinary5d: typeof bbinary5d; /** * Applies a quaternary callback to elements in four broadcasted input arrays and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing four input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - quaternary callback * * @example * var add = require( '@stdlib/math/base/ops/add4' ); * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * * var shapes = [ * [ 1, 2 ], * [ 2, 1 ], * [ 1, 1 ], * [ 2, 2 ], * [ 2, 2 ] * ]; * * var x = ones2d( shapes[ 0 ] ); * var y = ones2d( shapes[ 1 ] ); * var z = ones2d( shapes[ 2 ] ); * var w = ones2d( shapes[ 3 ] ); * var out = zeros2d( shapes[ 4 ] ); * * ns.bquaternary2d( [ x, y, z, w, out ], shapes, add ); * * console.log( out ); * // => [ [ 4.0, 8.0 ], [ 12.0, 16.0 ] ] */ bquaternary2d: typeof bquaternary2d; /** * Applies a quinary callback to elements in five broadcasted input arrays and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing five input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - quinary callback * * @example * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * * function add( x, y, z, w, v ) { * return x + y + z + w + v; * } * * var shapes = [ * [ 1, 2 ], * [ 2, 1 ], * [ 1, 1 ], * [ 2, 2 ], * [ 1, 1 ], * [ 2, 2 ] * ]; * * var x = ones2d( shapes[ 0 ] ); * var y = ones2d( shapes[ 1 ] ); * var z = ones2d( shapes[ 2 ] ); * var w = ones2d( shapes[ 3 ] ); * var v = ones2d( shapes[ 4 ] ); * var out = zeros2d( shapes[ 5 ] ); * * ns.bquinary2d( [ x, y, z, w, v, out ], shapes, add ); * * console.log( out ); * // => [ [ 5.0, 5.0 ], [ 5.0, 5.0 ] ] */ bquinary2d: typeof bquinary2d; /** * Applies a ternary callback to elements in three broadcasted input arrays and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The input array shapes must be broadcast compatible with the output array shape. * * @param arrays - array containing three input nested arrays and one output nested array * @param shapes - array shapes * @param fcn - ternary callback * * @example * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * var add = require( '@stdlib/math/base/ops/add3' ); * * var shapes = [ * [ 1, 2 ], * [ 2, 1 ], * [ 1, 1 ], * [ 2, 2 ] * ]; * * var x = ones2d( shapes[ 0 ] ); * var y = ones2d( shapes[ 1 ] ); * var z = ones2d( shapes[ 2 ] ); * var out = zeros2d( shapes[ 3 ] ); * * ns.bternary2d( [ x, y, z, out ], shapes, add ); * * console.log( out ); * // => [ [ 3.0, 6.0 ], [ 9.0, 12.0 ] ] */ bternary2d: typeof bternary2d; /** * Applies a unary callback to elements in a broadcasted nested input array and assigns results to elements in a two-dimensional nested output array. * * ## Notes * * - The input array shape must be broadcast compatible with the output array shape. * * @param arrays - array containing one input nested array and one output nested array * @param shapes - array shapes * @param fcn - unary callback * * @example * var ones2d = require( './../../../base/ones2d' ); * var zeros2d = require( './../../../base/zeros2d' ); * * function scale( x ) { * return x * 10.0; * } * * var shapes = [ * [ 1, 2 ], * [ 2, 2 ] * ]; * * var x = ones2d( shapes[ 0 ] ); * var y = zeros2d( shapes[ 1 ] ); * * ns.bunary2d( [ x, y ], shapes, scale ); * * console.log( y ); * // => [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] */ bunary2d: typeof bunary2d; /** * Applies a unary callback to elements in a broadcasted nested input array and assigns results to elements in a three-dimensional nested output array. * * ## Notes * * - The input array shape must be broadcast compatible with the output array shape. * * @param arrays - array containing one input nested array and one output nested array * @param shapes - array shapes * @param fcn - unary callback * * @example * var ones3d = require( './../../../base/ones3d' ); * var zeros3d = require( './../../../base/zeros3d' ); * * function scale( x ) { * return x * 10.0; * } * * var shapes = [ * [ 1, 1, 2 ], * [ 1, 2, 2 ] * ]; * * var x = ones3d( shapes[ 0 ] ); * var y = zeros3d( shapes[ 1 ] ); * * ns.bunary3d( [ x, y ], shapes, scale ); * * console.log( y ); * // => [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] */ bunary3d: typeof bunary3d; /** * Applies a unary callback to elements in a broadcasted nested input array and assigns results to elements in a four-dimensional nested output array. * * ## Notes * * - The input array shape must be broadcast compatible with the output array shape. * * @param arrays - array containing one input nested array and one output nested array * @param shapes - array shapes * @param fcn - unary callback * * @example * var ones4d = require( './../../../base/ones4d' ); * var zeros4d = require( './../../../base/zeros4d' ); * * function scale( x ) { * return x * 10.0; * } * * var shapes = [ * [ 1, 1, 1, 2 ], * [ 1, 1, 2, 2 ] * ]; * * var x = ones4d( shapes[ 0 ] ); * var y = zeros4d( shapes[ 1 ] ); * * ns.bunary4d( [ x, y ], shapes, scale ); * * console.log( y ); * // => [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] */ bunary4d: typeof bunary4d; /** * Applies a unary callback to elements in a broadcasted nested input array and assigns results to elements in a five-dimensional nested output array. * * ## Notes * * - The input array shape must be broadcast compatible with the output array shape. * * @param arrays - array containing one input nested array and one output nested array * @param shapes - array shapes * @param fcn - unary callback * * @example * var ones5d = require( './../../../base/ones5d' ); * var zeros5d = require( './../../../base/zeros5d' ); * * function scale( x ) { * return x * 10.0; * } * * var shapes = [ * [ 1, 1, 1, 1, 2 ], * [ 1, 1, 1, 2, 2 ] * ]; * * var x = ones5d( shapes[ 0 ] ); * var y = zeros5d( shapes[ 1 ] ); * * ns.bunary5d( [ x, y ], shapes, scale ); * * console.log( y ); * // => [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ] */ bunary5d: typeof bunary5d; /** * Returns the Cartesian power. * * ## Notes * * - If provided an empty array, the function returns an empty array. * - If `n` is less than or equal to zero, the function returns an empty array. * * @param x - input array * @param n - power * @returns Cartesian product * * @example * var x = [ 1, 2 ]; * * var out = ns.cartesianPower( x, 2 ); * // returns [ [ 1, 1 ], [ 1, 2 ], [ 2, 1 ], [ 2, 2 ] ] */ cartesianPower: typeof cartesianPower; /** * Returns the Cartesian product. * * ## Notes * * - If provided one or more empty arrays, the function returns an empty array. * * @param x1 - first input array * @param x2 - second input array * @returns Cartesian product * * @example * var x1 = [ 1, 2, 3 ]; * var x2 = [ 4, 5 ]; * * var out = ns.cartesianProduct( x1, x2 ); * // returns [ [ 1, 4 ], [ 1, 5 ], [ 2, 4 ], [ 2, 5 ], [ 3, 4 ], [ 3, 5 ] ] */ cartesianProduct: typeof cartesianProduct; /** * Returns the Cartesian square. * * ## Notes * * - If provided an empty array, the function returns an empty array. * * @param x - input array * @returns Cartesian product * * @example * var x = [ 1, 2 ]; * * var out = ns.cartesianSquare( x ); * // returns [ [ 1, 1 ], [ 1, 2 ], [ 2, 1 ], [ 2, 2 ] ] */ cartesianSquare: typeof cartesianSquare; /** * Copies the elements of an array-like object to a new "generic" array. * * @param x - input array * @returns output array * * @example * var x = [ 1, 2, 3 ]; * * var out = ns.copy( x ); * // returns [ 1, 2, 3 ] */ copy: typeof copy; /** * Copies the elements of an indexed array-like object to a new "generic" array. * * @param x - input array * @returns output array * * @example * var x = [ 1, 2, 3 ]; * * var out = ns.copyIndexed( x ); * // returns [ 1, 2, 3 ] */ copyIndexed: typeof copyIndexed; /** * Counts the number of falsy values in an array. * * @param x - input array * @returns number of falsy values * * @example * var x = [ 0, 1, 0, 1, 1 ]; * * var out = ns.countFalsy( x ); * // returns 2 */ countFalsy: typeof countFalsy; /** * Counts the number of elements in an array which pass a test implemented by a predicate function. * * @param x - input array * @param predicate - predicate function * @param thisArg - predicate function execution context * @returns result * * @example * function predicate( v ) { * return v > 0; * } * * var x = [ 0, 1, 0, 1, 1 ]; * * var n = ns.countIf( x, predicate ); * // returns 3 */ countIf: typeof countIf; /** * Counts the number of elements in an array that are equal to a specified value. * * ## Notes * * - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. * - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. * * [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 * * @param x - input array * @param value - search value * @returns number of elements that are equal to a specified value * * @example * var x = [ 0, 1, 0, 1, 1 ]; * * var out = ns.countSameValue( x, 1 ); * // returns 3 */ countSameValue: typeof countSameValue; /** * Counts the number of elements in an array that are equal to a specified value. * * ## Notes * * - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value. * * @param x - input array * @param value - search value * @returns number of elements that are equal to a specified value * * @example * var x = [ 0, 1, 0, 1, 1 ]; * * var out = ns.countSameValueZero( x, 1 ); * // returns 3 */ countSameValueZero: typeof countSameValueZero; /** * Counts the number of truthy values in an array. * * @param x - input array * @returns number of truthy values * * @example * var x = [ 0, 1, 0, 1, 1 ]; * * var out = ns.countTruthy( x ); * // returns 3 */ countTruthy: typeof countTruthy; /** * Cumulatively tests whether at least one element in a provided array is truthy. * * @param x - input array * @returns output array * * @example * var x = [ false, false, true, false, false ]; * * var result = ns.cuany( x ); * // returns [ false, false, true, true, true ] * * @example * var x = [ false, false, true, false, false ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * * var arr = ns.cuany.assign( x, y, 2, 0 ); * // returns [ false, null, false, null, true, null, true, null, true, null ] */ cuany: typeof cuany; /** * Cumulatively tests whether every element in a provided array is truthy. * * @param x - input array * @returns output array * * @example * var x = [ true, true, true, false, true ]; * * var result = ns.cuevery( x ); * // returns [ true, true, true, false, false ]; * * @example * var x = [ true, true, true, false, true ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * * var arr = ns.cuevery.assign( x, y, 2, 0 ); * // returns [ true, null, true, null, true, null, false, null, false, null ]; */ cuevery: typeof cuevery; /** * Removes consecutive duplicated values. * * ## Notes * * - The function mutates the input array. * * @param x - input array * @param limit - number of allowed consecutive duplicates * @param equalNaNs - boolean indicating whether NaNs should be considered equal * @returns input array * * @example * var x = [ 1, 1, 2, 3, 3 ]; * * var y = ns.dedupe( x, 1, false ); * // returns [ 1, 2, 3 ] * * var bool = ( x === y ); * // returns true * * @example * var x = [ 1, 1, 1, 2, 1, 1, 3, 3 ]; * * var y = ns.dedupe( x, 2, false ); * // returns [ 1, 1, 2, 1, 1, 3, 3 ] * * var bool = ( x === y ); * // returns true */ dedupe: typeof dedupe; /** * Tests whether all elements in an array are truthy. * * ## Notes * * - The function immediately returns upon encountering a non-truthy value. * - If provided an empty collection, the function returns `true`. * * @param x - input array * @returns boolean indicating whether all elements are truthy * * @example * var x = [ 1, 2, 3, 4 ]; * * var out = ns.every( x ); * // returns true */ every: typeof every; /** * Tests whether all elements in an array pass a test implemented by a predicate function. * * ## Notes * * - The function immediately returns upon encountering a non-truthy return value. * - If provided an empty collection, the function returns `true`. * * @param x - input array * @param predicate - predicate function * @param thisArg - predicate function execution context * @returns boolean indicating whether all elements pass a test * * @example * function isPositive( v ) { * return v > 0; * } * * var x = [ 1, 2, 3, 4 ]; * * var out = ns.everyBy( x, isPositive ); * // returns true */ everyBy: typeof everyBy; /** * Tests whether all elements in an array pass a test implemented by a predicate function, iterating from right to left. * * ## Notes * * - The function immediately returns upon encountering a non-truthy return value. * - If provided an empty collection, the function returns `true`. * * @param x - input array * @param predicate - predicate function * @param thisArg - predicate function execution context * @returns boolean indicating whether all elements pass a test * * @example * function isPositive( v ) { * return v > 0; * } * * var x = [ 1, 2, 3, 4 ]; * * var out = ns.everyByRight( x, isPositive ); * // returns true */ everyByRight: typeof everyByRight; /** * Returns a shallow copy of a portion of an array. * * @param x - input array * @param s - slice object * @param strict - boolean indicating whether to enforce strict bounds checking * @returns output array * * @example * var Slice = require( '@stdlib/ns.fancySlice/ctor' ); * * var x = [ 1, 2, 3, 4, 5, 6 ]; * * var out = ns.fancySlice( x, new Slice( null, null, -1 ), false ); * // returns [ 6, 5, 4, 3, 2, 1 ] */ fancySlice: typeof fancySlice; /** * Assigns element values from a broadcasted input array to corresponding elements in an output array. * * ## Notes * * - The input array must be broadcast compatible with the output array slice to which elements will be assigned (i.e., contain only one element or the same number of elements as in the slice). * - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). * * @param x - input array * @param y - output array * @param s - slice object * @param strict - boolean indicating whether to enforce strict bounds checking * @returns output array * * @example * var Slice = require( '@stdlib/slice/ctor' ); * * var x = [ 1, 2, 3, 4 ]; * var y = [ 0, 0, 0, 0, 0, 0, 0, 0 ]; * * var s = new Slice( null, null, 2 ); * // returns <Slice> * * var out = ns.fancySliceAssign( x, y, s, false ); * // returns [ 1, 0, 2, 0, 3, 0, 4, 0 ] * * var bool = ( out === y ); * // returns true */ fancySliceAssign: typeof fancySliceAssign; /** * Returns a filled "generic" array. * * @param value - fill value * @param len - array length * @returns output array * * @example * var out = ns.filled( 0.0, 3 ); * // returns [ 0.0, 0.0, 0.0 ] * * @example * var out = ns.filled( 'beep', 3 ); * // returns [ 'beep', 'beep', 'beep' ] */ filled: typeof filled; /** * Returns a filled "generic" array according to a provided callback function. * * @param len - array length * @param clbk - callback function * @param thisArg - callback function execution context * @returns output array * * @example * var constantFunction = require( '@stdlib/utils/constant-function' ); * * var arr = ns.filledBy( 5, constantFunction( 1.0 ) ); * // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ filledBy: typeof filledBy; /