Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @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.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
var Float16Array = require( '@stdlib/array/float16' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var linspace = require( './../lib' );

Check warning on line 29 in lib/node_modules/@stdlib/array/linspace/benchmark/benchmark.assign.float16_real.length.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `assign` property of the required module is used; require the property directly


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out = new Float16Array( len );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var v;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = linspace.assign( 0.0, 100.0, out );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array-like object' );
}
}
b.toc();
if ( !isArrayLikeObject( v ) ) {
b.fail( 'should return an array-like object' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s::real:assign:dtype=float16,len=%d', pkg, len ), f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @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.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var linspace = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var opts;
var v;
var i;

opts = {
'dtype': 'float16'
};

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = linspace( 0.0, 100.0, len, opts );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array-like object' );
}
}
b.toc();
if ( !isArrayLikeObject( v ) ) {
b.fail( 'should return an array-like object' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s::real:dtype=float16,len=%d', pkg, len ), f );
}
}

main();
24 changes: 24 additions & 0 deletions lib/node_modules/@stdlib/array/linspace/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ bench( format( '%s::real:dtype=float32', pkg ), function benchmark( b ) {
b.end();
});

bench( format( '%s::real:dtype=float16', pkg ), function benchmark( b ) {
var opts;
var v;
var i;

opts = {
'dtype': 'float16'
};

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = linspace( 0.0, 100.0, 10, opts );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array-like object' );
}
}
b.toc();
if ( !isArrayLikeObject( v ) ) {
b.fail( 'should return an array-like object' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::real:dtype=generic', pkg ), function benchmark( b ) {
var opts;
var v;
Expand Down
51 changes: 50 additions & 1 deletion lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/// <reference types="@stdlib/types"/>

import { FloatingPointDataType as DataType, ArrayLike, FloatOrComplexTypedArray, Complex64Array, Complex128Array } from '@stdlib/types/array';
import { FloatingPointDataType as DataType, ArrayLike, FloatOrComplexTypedArray, Float16Array, Complex64Array, Complex128Array } from '@stdlib/types/array';
import { ComplexLike, Complex64, Complex128 } from '@stdlib/types/complex';

/**
Expand Down Expand Up @@ -72,6 +72,16 @@
dtype: 'float32';
}

/**
* Interface describing function options.
*/
interface Float16Options extends BaseOptions {
/**
* Output array data type.
*/
dtype: 'float16';
}

/**
* Interface describing function options.
*/
Expand Down Expand Up @@ -150,6 +160,26 @@
*/
( start: number, stop: number, len: number, options: Float32Options ): Float32Array;

/**
* Generates a linearly spaced array over a specified interval.
*
* @param start - start of interval
* @param stop - end of interval
* @param len - length of output array
* @param options - function options
* @param options.dtype - output array data type
* @param options.endpoint - `boolean` indicating whether to include the `stop` value in the output array
* @returns linearly spaced array
*
* @example
* var opts = {
* 'dtype': 'float16'
* };
* var arr = linspace( 0.0, 100.0, 6, opts );
* // returns <Float16Array>[ 0.0, 20.0, 40.0, 60.0, 80.0, 100.0 ]
*/
( start: number, stop: number, len: number, options: Float16Options ): Float16Array;

/**
* Generates a linearly spaced array over a specified interval.
*
Expand Down Expand Up @@ -450,6 +480,25 @@
*/
assign( start: number, stop: number, out: Float32Array, options?: BaseOptions ): Float32Array;

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
*
* @param start - start of interval
* @param stop - end of interval
* @param out - output array
* @param options - function options
* @param options.endpoint - `boolean` indicating whether to include the `stop` value in the output array
* @returns output array
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
*
* var out = new Float16Array( 6 );
* var arr = linspace.assign( 0.0, 100.0, out );
* // returns <Float16Array>[ 0.0, 20.0, 40.0, 60.0, 80.0, 100.0 ]
*/
assign( start: number, stop: number, out: Float16Array, options?: BaseOptions ): Float16Array;

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
*
Expand Down Expand Up @@ -487,7 +536,7 @@
* var arr = linspace.assign( start, stop, out );
* // returns [...]
*/
assign( start: Complex64, stop: Complex64, out: Array<any>, options?: BaseOptions ): Array<Complex64>;

Check warning on line 539 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
Expand All @@ -509,7 +558,7 @@
* var arr = linspace.assign( start, stop, out );
* // returns [...]
*/
assign( start: ComplexLike, stop: number | ComplexLike, out: Array<any>, options?: BaseOptions ): Array<Complex128>;

Check warning on line 561 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
Expand All @@ -531,7 +580,7 @@
* var arr = linspace.assign( start, stop, out );
* // returns [...]
*/
assign( start: number | ComplexLike, stop: ComplexLike, out: Array<any>, options?: BaseOptions ): Array<Complex128>;

Check warning on line 583 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
Expand Down Expand Up @@ -588,7 +637,7 @@
* var arr = linspace.assign( 0.0, 100.0, out );
* // returns <Float64Array>[ 0.0, 20.0, 40.0, 60.0, 80.0, 100.0 ]
*/
assign( start: number, stop: number, out: ArrayLike<any>, options?: BaseOptions ): ArrayLike<number>;

Check warning on line 640 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
Expand All @@ -611,7 +660,7 @@
* var arr = linspace.assign( start, stop, out );
* // returns [...]
*/
assign( start: ComplexLike, stop: number | ComplexLike, out: ArrayLike<any>, options?: BaseOptions ): ArrayLike<ComplexLike>;

Check warning on line 663 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Generates a linearly spaced sequence over a specified interval and assigns results to a provided output array.
Expand All @@ -634,7 +683,7 @@
* var arr = linspace.assign( start, stop, out );
* // returns [...]
*/
assign( start: number | ComplexLike, stop: ComplexLike, out: ArrayLike<any>, options?: BaseOptions ): ArrayLike<ComplexLike>;

Check warning on line 686 in lib/node_modules/@stdlib/array/linspace/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/array/linspace/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Complex64 = require( '@stdlib/complex/float32/ctor' );
import Complex128 = require( '@stdlib/complex/float64/ctor' );
import Complex128Array = require( '@stdlib/array/complex128' );
import Complex64Array = require( '@stdlib/array/complex64' );
import Float16Array = require( '@stdlib/array/float16' );
import linspace = require( './index' );


Expand All @@ -34,6 +35,7 @@ import linspace = require( './index' );

linspace( 0, 11, 20, { 'dtype': 'float64' } ); // $ExpectType Float64Array
linspace( 0, 11, 20, { 'dtype': 'float32' } ); // $ExpectType Float32Array
linspace( 0, 11, 20, { 'dtype': 'float16' } ); // $ExpectType Float16ArrayFallback
linspace( 0, 11, 20, { 'dtype': 'complex64' } ); // $ExpectType Complex64Array
linspace( 0, 11, 20, { 'dtype': 'complex128' } ); // $ExpectType Complex128Array
linspace( 0, 11, 20, { 'dtype': 'generic' } ); // $ExpectType number[]
Expand Down Expand Up @@ -216,13 +218,15 @@ import linspace = require( './index' );
const o3 = [ 1, 2, 3, 4 ];
const o4 = new Complex128Array( 10 );
const o5 = new Complex64Array( 10 );
const o6 = new Float16Array( 10 );

linspace.assign( 0, 11, o1 ); // $ExpectType Float64Array

linspace.assign( 0, 11, o1, { 'endpoint': true } ); // $ExpectType Float64Array
linspace.assign( 0, 11, o1, { 'endpoint': false } ); // $ExpectType Float64Array

linspace.assign( 0, 11, o2 ); // $ExpectType Float32Array
linspace.assign( 0, 11, o6 ); // $ExpectType Float16ArrayFallback
linspace.assign( 0, 11, o3 ); // $ExpectType number[]
linspace.assign( 0, 11, o4 ); // $ExpectType Complex128Array
linspace.assign( 0, 11, o5 ); // $ExpectType Complex64Array
Expand Down
Loading