Skip to content
Open
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,123 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var zeros = require( '@stdlib/array/zeros' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var gfillRows = require( './../lib' );


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {PositiveInteger} M - number of elements along each row
* @param {PositiveInteger} N - number of elements along each column
* @returns {Function} benchmark function
*/
function createBenchmark( order, M, N ) {
var alpha;
var ldx;
var X;

if ( order === 'column-major' ) {
ldx = M;
} else {
ldx = N;
}

alpha = zeros( M, 'generic' );
X = zeros( M*N, 'generic' );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = gfillRows( order, M, N, alpha, X, ldx );
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var shapes = [
[ 10, 100000 ],
[ 100, 10000 ],
[ 1000, 1000 ],
[ 10000, 100 ],
[ 100000, 10 ]
];
var shape;
var ord;
var f;
var i;
var k;

for ( k = 0; k < LAYOUTS.length; k++ ) {
ord = LAYOUTS[ k ];
for ( i = 0; i < shapes.length; i++ ) {
shape = shapes[ i ];
f = createBenchmark( ord, shape[ 0 ], shape[ 1 ] );
bench( format( '%s::matrix:ndarray:order=%s:M=%d:N=%d:size=%d', pkg, ord, shape[ 0 ], shape[ 1 ], shape[ 0 ] * shape[ 1 ] ), f );
}
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var zeros = require( '@stdlib/array/zeros' );
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var gfillRows = require( './../lib' ).ndarray;


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {PositiveInteger} M - number of elements along each row
* @param {PositiveInteger} N - number of elements along each column
* @returns {Function} benchmark function
*/
function createBenchmark( order, M, N ) {
var alpha;
var sx1;
var sx2;
var X;

alpha = zeros( M, 'generic' );
X = zeros( M*N, 'generic' );

if ( isColumnMajor( order ) ) {
sx1 = 1;
sx2 = M;
} else { // order === 'row-major'
sx1 = N;
sx2 = 1;
}
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = gfillRows( M, N, alpha, 1, 0, X, sx1, sx2, 0 );
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var shapes = [
[ 10, 100000 ],
[ 100, 10000 ],
[ 1000, 1000 ],
[ 10000, 100 ],
[ 100000, 10 ]
];
var shape;
var ord;
var f;
var i;
var k;

for ( k = 0; k < LAYOUTS.length; k++ ) {
ord = LAYOUTS[ k ];
for ( i = 0; i < shapes.length; i++ ) {
shape = shapes[ i ];
f = createBenchmark( ord, shape[ 0 ], shape[ 1 ] );
bench( format( '%s::matrix:ndarray:order=%s:M=%d:N=%d:size=%d', pkg, ord, shape[ 0 ], shape[ 1 ], shape[ 0 ] * shape[ 1 ] ), f );
}
}
}

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

// TypeScript Version: 4.1

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

import { Collection, AccessorArrayLike } from '@stdlib/types/array';
import { Layout } from '@stdlib/types/blas';

/**
* Input array.
*/
type InputArray<T> = AccessorArrayLike<T> | Collection<T>;

/**
* Output array.
*/
type OutputArray<T> = AccessorArrayLike<T> | Collection<T>;

/**
* Interface describing `gfillRows`.
*/
interface Routine {
/**
* Fills the rows of a matrix from a vector of fill values.
*
* @param order - storage layout
* @param M - number of rows in `X`
* @param N - number of columns in `X`
* @param alpha - vector of fill values
* @param X - input matrix
* @param LDX - stride of the first dimension of `X`
* @returns `X`
*
* @example
* var alpha = [ 10.0, 20.0 ];
* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
*
* gfillRows( 'row-major', 2, 3, alpha, X, 3 );
* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ]
*/
<T = unknown, U = unknown>( order: Layout, M: number, N: number, alpha: InputArray<T>, X: InputArray<U>, LDX: number ): OutputArray<T | U>;

/**
* Fills the rows of a matrix from a vector of fill values using alternative indexing semantics.
*
* @param order - storage layout
* @param M - number of rows in `X`
* @param N - number of columns in `X`
* @param alpha - vector of fill values
* @param strideAlpha - stride length of `alpha`
* @param offsetAlpha - starting index of `alpha`
* @param X - input matrix
* @param strideX1 - stride length for the first dimension of `X`
* @param strideX2 - stride length for the second dimension of `X`
* @param offsetX - starting offset of `X`
* @returns `X`
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
*
* var alpha = [ 10, 20 ];
* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
*
* gfillRows.ndarray( 2, 3, toAccessorArray( alpha ), 1, 0, toAccessorArray( X ), 1, 2, 0 );
* // X => [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ]
*/
ndarray<T = unknown, U = unknown>( M: number, N: number, alpha: InputArray<T>, strideAlpha: number, offsetAlpha: number, X: InputArray<U>, strideX1: number, strideX2: number, offsetX: number ): OutputArray<T | U>;
}

/**
* Fills the rows of a matrix from a vector of fill values.
*
* @param order - storage layout
* @param M - number of rows in `X`
* @param N - number of columns in `X`
* @param alpha - vector of fill values
* @param X - input matrix
* @param LDX - stride of the first dimension of `X`
* @returns `X`
*
* @example
* var alpha = [ 10.0, 20.0 ];
* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
*
* gfillRows( 'row-major', 2, 3, alpha, X, 3 );
* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ]
*/
declare var gfillRows: Routine;


// EXPORTS //

export = gfillRows;
Loading