/* * @license Apache-2.0 * * Copyright (c) 2026 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. */ import zeros = require( './../../../base/zeros' ); import onesLike = require( './index' ); // TESTS // // The function returns an ndarray... { const sh = [ 2, 2 ]; const ord = 'row-major'; onesLike( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray onesLike( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray onesLike( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray onesLike( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray onesLike( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray onesLike( zeros( 'int16', sh, ord ) ); // $ExpectType int16ndarray onesLike( zeros( 'int8', sh, ord ) ); // $ExpectType int8ndarray onesLike( zeros( 'uint32', sh, ord ) ); // $ExpectType uint32ndarray onesLike( zeros( 'uint16', sh, ord ) ); // $ExpectType uint16ndarray onesLike( zeros( 'uint8', sh, ord ) ); // $ExpectType uint8ndarray onesLike( zeros( 'uint8c', sh, ord ) ); // $ExpectType uint8cndarray onesLike( zeros( 'generic', sh, ord ) ); // $ExpectType genericndarray onesLike( zeros( 'float64', sh, ord ), {} ); // $ExpectType float64ndarray onesLike( zeros( 'float32', sh, ord ), {} ); // $ExpectType float32ndarray onesLike( zeros( 'complex128', sh, ord ), {} ); // $ExpectType complex128ndarray onesLike( zeros( 'complex64', sh, ord ), {} ); // $ExpectType complex64ndarray onesLike( zeros( 'int32', sh, ord ), {} ); // $ExpectType int32ndarray onesLike( zeros( 'int16', sh, ord ), {} ); // $ExpectType int16ndarray onesLike( zeros( 'int8', sh, ord ), {} ); // $ExpectType int8ndarray onesLike( zeros( 'uint32', sh, ord ), {} ); // $ExpectType uint32ndarray onesLike( zeros( 'uint16', sh, ord ), {} ); // $ExpectType uint16ndarray onesLike( zeros( 'uint8', sh, ord ), {} ); // $ExpectType uint8ndarray onesLike( zeros( 'uint8c', sh, ord ), {} ); // $ExpectType uint8cndarray onesLike( zeros( 'generic', sh, ord ), {} ); // $ExpectType genericndarray onesLike( zeros( 'float64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float64ndarray onesLike( zeros( 'float32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float32ndarray onesLike( zeros( 'complex128', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex128ndarray onesLike( zeros( 'complex64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex64ndarray onesLike( zeros( 'int32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int32ndarray onesLike( zeros( 'int16', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int16ndarray onesLike( zeros( 'int8', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int8ndarray onesLike( zeros( 'uint32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint32ndarray onesLike( zeros( 'uint16', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint16ndarray onesLike( zeros( 'uint8', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint8ndarray onesLike( zeros( 'uint8c', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint8cndarray onesLike( zeros( 'generic', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType genericndarray onesLike( zeros( 'float64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float64ndarray onesLike( zeros( 'float32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float32ndarray onesLike( zeros( 'complex128', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex128ndarray onesLike( zeros( 'complex64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex64ndarray onesLike( zeros( 'int32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int32ndarray onesLike( zeros( 'int16', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int16ndarray onesLike( zeros( 'int8', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int8ndarray onesLike( zeros( 'uint32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint32ndarray onesLike( zeros( 'uint16', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint16ndarray onesLike( zeros( 'uint8', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint8ndarray onesLike( zeros( 'uint8c', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint8cndarray onesLike( zeros( 'generic', sh, ord ), { 'order': 'column-major' } ); // $ExpectType genericndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'float64' } ); // $ExpectType float64ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'float32' } ); // $ExpectType float32ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'int32' } ); // $ExpectType int32ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'int16' } ); // $ExpectType int16ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'int8' } ); // $ExpectType int8ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' } ); // $ExpectType uint32ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' } ); // $ExpectType uint16ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' } ); // $ExpectType uint8ndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' } ); // $ExpectType uint8cndarray onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'generic' } ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument is not an ndarray which has a recognized/supported data type... { onesLike( '10' ); // $ExpectError onesLike( 10 ); // $ExpectError onesLike( false ); // $ExpectError onesLike( true ); // $ExpectError onesLike( null ); // $ExpectError onesLike( [] ); // $ExpectError onesLike( {} ); // $ExpectError onesLike( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a second argument is not an options object... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, '10' ); // $ExpectError onesLike( x, 10 ); // $ExpectError onesLike( x, false ); // $ExpectError onesLike( x, true ); // $ExpectError onesLike( x, [] ); // $ExpectError onesLike( x, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a `dtype` option which is not a valid data type... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'dtype': '10' } ); // $ExpectError onesLike( x, { 'dtype': 10 } ); // $ExpectError onesLike( x, { 'dtype': null } ); // $ExpectError onesLike( x, { 'dtype': false } ); // $ExpectError onesLike( x, { 'dtype': true } ); // $ExpectError onesLike( x, { 'dtype': [] } ); // $ExpectError onesLike( x, { 'dtype': {} } ); // $ExpectError onesLike( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an `order` option which is not a valid order... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'order': '10' } ); // $ExpectError onesLike( x, { 'order': 10 } ); // $ExpectError onesLike( x, { 'order': false } ); // $ExpectError onesLike( x, { 'order': true } ); // $ExpectError onesLike( x, { 'order': [] } ); // $ExpectError onesLike( x, { 'order': {} } ); // $ExpectError onesLike( x, { 'order': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `shape` option which is not a valid shape... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'shape': '10' } ); // $ExpectError onesLike( x, { 'shape': false } ); // $ExpectError onesLike( x, { 'shape': true } ); // $ExpectError onesLike( x, { 'shape': [ '5' ] } ); // $ExpectError onesLike( x, { 'shape': {} } ); // $ExpectError onesLike( x, { 'shape': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `mode` option which is not a valid mode... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'mode': '5' } ); // $ExpectError onesLike( x, { 'mode': 5 } ); // $ExpectError onesLike( x, { 'mode': false } ); // $ExpectError onesLike( x, { 'mode': true } ); // $ExpectError onesLike( x, { 'mode': [ '5' ] } ); // $ExpectError onesLike( x, { 'mode': {} } ); // $ExpectError onesLike( x, { 'mode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `submode` option which is not valid... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'submode': '5' } ); // $ExpectError onesLike( x, { 'submode': 5 } ); // $ExpectError onesLike( x, { 'submode': false } ); // $ExpectError onesLike( x, { 'submode': true } ); // $ExpectError onesLike( x, { 'submode': [ '5' ] } ); // $ExpectError onesLike( x, { 'submode': {} } ); // $ExpectError onesLike( x, { 'submode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `readonly` option which is not a boolean... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); onesLike( x, { 'readonly': '5' } ); // $ExpectError onesLike( x, { 'readonly': 5 } ); // $ExpectError onesLike( x, { 'readonly': [ '5' ] } ); // $ExpectError onesLike( x, { 'readonly': {} } ); // $ExpectError onesLike( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { onesLike(); // $ExpectError onesLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), {}, 1 ); // $ExpectError }