/* * @license Apache-2.0 * * Copyright (c) 2025 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. */ /* eslint-disable space-in-parens */ /// import zeros = require( './../../../zeros' ); import empty = require( './../../../empty' ); import some = require( './index' ); // TESTS // // The function returns an ndarray... { const x = zeros( [ 2, 2 ] ); const n = zeros( [], { 'dtype': 'int32' }); some( x, 2 ); // $ExpectType boolndarray some( x, 2, { 'keepdims': true } ); // $ExpectType boolndarray some( x, 2, { 'dims': [ 0 ] } ); // $ExpectType boolndarray some( x, n ); // $ExpectType boolndarray some( x, n, { 'keepdims': true } ); // $ExpectType boolndarray some( x, n, { 'dims': [ 0 ] } ); // $ExpectType boolndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { some( 5, 2 ); // $ExpectError some( true, 2 ); // $ExpectError some( false, 2 ); // $ExpectError some( null, 2 ); // $ExpectError some( undefined, 2 ); // $ExpectError some( {}, 2 ); // $ExpectError some( [ 1 ], 2 ); // $ExpectError some( ( x: number ): number => x, 2 ); // $ExpectError some( 5, 2, {} ); // $ExpectError some( true, 2, {} ); // $ExpectError some( false, 2, {} ); // $ExpectError some( null, 2, {} ); // $ExpectError some( undefined, 2, {} ); // $ExpectError some( {}, 2, {} ); // $ExpectError some( [ 1 ], 2, {} ); // $ExpectError some( ( x: number ): number => x, 2, {} ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not an ndarray or a number... { const x = zeros( [ 2, 2 ] ); some( x, true ); // $ExpectError some( x, false ); // $ExpectError some( x, null ); // $ExpectError some( x, undefined ); // $ExpectError some( x, [] ); // $ExpectError some( x, {} ); // $ExpectError some( x, ( x: number ): number => x ); // $ExpectError some( x, true, {} ); // $ExpectError some( x, false, {} ); // $ExpectError some( x, null, {} ); // $ExpectError some( x, undefined, {} ); // $ExpectError some( x, [], {} ); // $ExpectError some( x, {}, {} ); // $ExpectError some( x, ( x: number ): number => x, {} ); // $ExpectError } // The compiler throws an error if the function is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ] ); some( x, 2, null ); // $ExpectError some( x, 2, 'abc' ); // $ExpectError some( x, 2, 1 ); // $ExpectError some( x, 2, true ); // $ExpectError some( x, 2, false ); // $ExpectError some( x, 2, [] ); // $ExpectError some( x, 2, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a `keepdims` option which is not a boolean... { const x = zeros( [ 2, 2 ] ); some( x, 2, { 'keepdims': '5' } ); // $ExpectError some( x, 2, { 'keepdims': 5 } ); // $ExpectError some( x, 2, { 'keepdims': null } ); // $ExpectError some( x, 2, { 'keepdims': [ 1 ] } ); // $ExpectError some( x, 2, { 'keepdims': {} } ); // $ExpectError some( x, 2, { 'keepdims': ( x: number ): number => x } ); // $ExpectError some( x, 2, { 'keepdims': '5' } ); // $ExpectError some( x, 2, { 'keepdims': 5 } ); // $ExpectError some( x, 2, { 'keepdims': null } ); // $ExpectError some( x, 2, { 'keepdims': [ 1 ] } ); // $ExpectError some( x, 2, { 'keepdims': {} } ); // $ExpectError some( x, 2, { 'keepdims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `dims` option which is not an array of numbers... { const x = zeros( [ 2, 2 ] ); some( x, 2, { 'dims': '5' } ); // $ExpectError some( x, 2, { 'dims': 5 } ); // $ExpectError some( x, 2, { 'dims': null } ); // $ExpectError some( x, 2, { 'dims': true } ); // $ExpectError some( x, 2, { 'dims': false } ); // $ExpectError some( x, 2, { 'dims': {} } ); // $ExpectError some( x, 2, { 'dims': ( x: number ): number => x } ); // $ExpectError some( x, 2, { 'dims': '5' } ); // $ExpectError some( x, 2, { 'dims': 5 } ); // $ExpectError some( x, 2, { 'dims': null } ); // $ExpectError some( x, 2, { 'dims': true } ); // $ExpectError some( x, 2, { 'dims': false } ); // $ExpectError some( x, 2, { 'dims': {} } ); // $ExpectError some( x, 2, { 'dims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( [ 2, 2 ] ); some(); // $ExpectError some( x ); // $ExpectError some( x, 2, {}, {} ); // $ExpectError } // Attached to the function is an `assign` method which returns an ndarray... { const x = zeros( [ 2, 2 ] ); const n = zeros( [], { 'dtype': 'int32' }); const y = empty( [], { 'dtype': 'bool' }); some.assign( x, 2, y ); // $ExpectType boolndarray some.assign( x, 2, y, {} ); // $ExpectType boolndarray some.assign( x, 2, y, { 'dims': [ 0 ] } ); // $ExpectType boolndarray some.assign( x, 2, y ); // $ExpectType boolndarray some.assign( x, 2, y, {} ); // $ExpectType boolndarray some.assign( x, 2, y, { 'dims': [ 0 ] } ); // $ExpectType boolndarray some.assign( x, n, y ); // $ExpectType boolndarray some.assign( x, n, y, {} ); // $ExpectType boolndarray some.assign( x, n, y, { 'dims': [ 0 ] } ); // $ExpectType boolndarray some.assign( x, n, y ); // $ExpectType boolndarray some.assign( x, n, y, {} ); // $ExpectType boolndarray some.assign( x, n, y, { 'dims': [ 0 ] } ); // $ExpectType boolndarray } // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { const y = empty( [] ); some.assign( 5, 2, y ); // $ExpectError some.assign( true, 2, y ); // $ExpectError some.assign( false, 2, y ); // $ExpectError some.assign( null, 2, y ); // $ExpectError some.assign( undefined, 2, y ); // $ExpectError some.assign( {}, 2, y ); // $ExpectError some.assign( [ 1 ], 2, y ); // $ExpectError some.assign( 5, 2, y, {} ); // $ExpectError some.assign( true, 2, y, {} ); // $ExpectError some.assign( false, 2, y, {} ); // $ExpectError some.assign( null, 2, y, {} ); // $ExpectError some.assign( undefined, 2, y, {} ); // $ExpectError some.assign( {}, 2, y, {} ); // $ExpectError some.assign( [ 1 ], 2, y, {} ); // $ExpectError some.assign( ( x: number ): number => x, 2, y, {} ); // $ExpectError some.assign( ( x: number ): number => x, 2, y, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray or a number... { const x = zeros( [ 2, 2 ] ); const y = empty( [] ); some.assign( x, '5', y ); // $ExpectError some.assign( x, true, y ); // $ExpectError some.assign( x, false, y ); // $ExpectError some.assign( x, null, y ); // $ExpectError some.assign( x, undefined, y ); // $ExpectError some.assign( x, [], y ); // $ExpectError some.assign( x, {}, y ); // $ExpectError some.assign( x, ( x: number ): number => x, y ); // $ExpectError some.assign( x, '5', y, {} ); // $ExpectError some.assign( x, true, y, {} ); // $ExpectError some.assign( x, false, y, {} ); // $ExpectError some.assign( x, null, y, {} ); // $ExpectError some.assign( x, undefined, y, {} ); // $ExpectError some.assign( x, [], y, {} ); // $ExpectError some.assign( x, {}, y, {} ); // $ExpectError some.assign( x, ( x: number ): number => x, y, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... { const x = zeros( [ 2, 2 ] ); some.assign( x, 2, '5' ); // $ExpectError some.assign( x, 2, 5 ); // $ExpectError some.assign( x, 2, true ); // $ExpectError some.assign( x, 2, false ); // $ExpectError some.assign( x, 2, null ); // $ExpectError some.assign( x, 2, undefined ); // $ExpectError some.assign( x, 2, {} ); // $ExpectError some.assign( x, 2, [ 1 ] ); // $ExpectError some.assign( x, 2, ( x: number ): number => x ); // $ExpectError some.assign( x, 2, '5', {} ); // $ExpectError some.assign( x, 2, 5, {} ); // $ExpectError some.assign( x, 2, true, {} ); // $ExpectError some.assign( x, 2, false, {} ); // $ExpectError some.assign( x, 2, null, {} ); // $ExpectError some.assign( x, 2, undefined, {} ); // $ExpectError some.assign( x, 2, {}, {} ); // $ExpectError some.assign( x, 2, [ 1 ], {} ); // $ExpectError some.assign( x, 2, ( x: number ): number => x, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ] ); const y = empty( [], { 'dtype': 'bool' }); some.assign( x, 2, y, '5' ); // $ExpectError some.assign( x, 2, y, 5 ); // $ExpectError some.assign( x, 2, y, true ); // $ExpectError some.assign( x, 2, y, false ); // $ExpectError some.assign( x, 2, y, null ); // $ExpectError some.assign( x, 2, y, [ 1 ] ); // $ExpectError some.assign( x, 2, y, ( x: number ): number => x ); // $ExpectError some.assign( x, 2, y, '5' ); // $ExpectError some.assign( x, 2, y, 5 ); // $ExpectError some.assign( x, 2, y, true ); // $ExpectError some.assign( x, 2, y, false ); // $ExpectError some.assign( x, 2, y, null ); // $ExpectError some.assign( x, 2, y, [ 1 ] ); // $ExpectError some.assign( x, 2, y, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a `dims` option which is not an array of numbers... { const x = zeros( [ 2, 2 ] ); const y = empty( [], { 'dtype': 'bool' }); some.assign( x, 2, y, { 'dims': '5' } ); // $ExpectError some.assign( x, 2, y, { 'dims': 5 } ); // $ExpectError some.assign( x, 2, y, { 'dims': null } ); // $ExpectError some.assign( x, 2, y, { 'dims': true } ); // $ExpectError some.assign( x, 2, y, { 'dims': false } ); // $ExpectError some.assign( x, 2, y, { 'dims': {} } ); // $ExpectError some.assign( x, 2, y, { 'dims': ( x: number ): number => x } ); // $ExpectError some.assign( x, 2, y, { 'dims': '5' } ); // $ExpectError some.assign( x, 2, y, { 'dims': 5 } ); // $ExpectError some.assign( x, 2, y, { 'dims': null } ); // $ExpectError some.assign( x, 2, y, { 'dims': true } ); // $ExpectError some.assign( x, 2, y, { 'dims': false } ); // $ExpectError some.assign( x, 2, y, { 'dims': {} } ); // $ExpectError some.assign( x, 2, y, { 'dims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... { const x = zeros( [ 2, 2 ] ); const y = empty( [] ); some.assign(); // $ExpectError some.assign( x ); // $ExpectError some.assign( x, 2 ); // $ExpectError some.assign( x, 2, y, {}, {} ); // $ExpectError }