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
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gdot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ var z = gdot.ndarray( 3, x, 2, 1, y, -1, y.length-1 );

- If `N <= 0` both functions return `0.0`.
- `gdot()` corresponds to the [BLAS][blas] level 1 function [`ddot`][ddot] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`ddot`][@stdlib/blas/base/ddot], [`sdot`][@stdlib/blas/base/sdot], etc.) are likely to be significantly more performant.
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).

</section>

Expand Down Expand Up @@ -199,6 +200,8 @@ console.log( out );

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor

[@stdlib/blas/base/ddot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ddot

[@stdlib/blas/base/sdot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sdot
Expand Down
11 changes: 8 additions & 3 deletions lib/node_modules/@stdlib/blas/base/gdot/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

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

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

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

/**
* Interface describing `gdot`.
Expand All @@ -43,7 +48,7 @@ interface Routine {
* var z = gdot( x.length, x, 1, y, 1 );
* // returns -5.0
*/
( N: number, x: NumericArray, strideX: number, y: NumericArray, strideY: number ): number;
( N: number, x: InputArray, strideX: number, y: InputArray, strideY: number ): number;

/**
* Computes the dot product of two vectors using alternative indexing semantics.
Expand All @@ -64,7 +69,7 @@ interface Routine {
* var z = gdot.ndarray( x.length, x, 1, 0, y, 1, 0 );
* // returns -5.0
*/
ndarray( N: number, x: NumericArray, strideX: number, offsetX: number, y: NumericArray, strideY: number, offsetY: number ): number;
ndarray( N: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number ): number;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gdot/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import AccessorArray = require( '@stdlib/array/base/accessor' );
import gdot = require( './index' );


Expand All @@ -27,6 +28,7 @@ import gdot = require( './index' );
const y = new Float64Array( 10 );

gdot( x.length, x, 1, y, 1 ); // $ExpectType number
gdot( x.length, new AccessorArray( x ), 1, y, 1 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a first argument which is not a number...
Expand Down Expand Up @@ -124,6 +126,7 @@ import gdot = require( './index' );
const y = new Float64Array( 10 );

gdot.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType number
gdot.ndarray( x.length, new AccessorArray( x ), 1, 0, y, 1, 0 ); // $ExpectType number
}

// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
Expand Down
108 changes: 108 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gdot/lib/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @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.
*/

'use strict';

// VARIABLES //

var M = 5;


// MAIN //

/**
* Computes the dot product of `x` and `y`.
*
* @private
* @param {integer} N - number of indexed elements
* @param {Object} x - first input array object
* @param {Collection} x.data - first input array data
* @param {Array<Function>} x.accessors - first array element accessors
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Object} y - second input array object
* @param {Collection} y.data - second input array data
* @param {Array<Function>} y.accessors - second array element accessors
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @returns {number} dot product
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = [ 4.0, 2.0, -3.0, 5.0, -1.0 ];
* var y = [ 2.0, 6.0, -1.0, -4.0, 8.0 ];
*
* var z = gdot( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0 );
* // returns -5.0
*/
function gdot( N, x, strideX, offsetX, y, strideY, offsetY ) {
var xbuf;
var ybuf;
var xget;
var yget;
var dot;
var ix;
var iy;
var m;
var i;

xbuf = x.data;
ybuf = y.data;
xget = x.accessors[ 0 ];
yget = y.accessors[ 0 ];

dot = 0.0;
ix = offsetX;
iy = offsetY;

// Use unrolled loops if both strides are equal to `1`...
if ( strideX === 1 && strideY === 1 ) {
m = N % M;

// If we have a remainder, run a clean-up loop...
if ( m > 0 ) {
for ( i = 0; i < m; i++ ) {
dot += xget( xbuf, ix ) * yget( ybuf, iy );
ix += 1;
iy += 1;
}
}
if ( N < M ) {
return dot;
}
for ( i = m; i < N; i += M ) {
dot += ( xget( xbuf, ix ) * yget( ybuf, iy ) ) + ( xget( xbuf, ix+1 ) * yget( ybuf, iy+1 ) ) + ( xget( xbuf, ix+2 ) * yget( ybuf, iy+2 ) ) + ( xget( xbuf, ix+3 ) * yget( ybuf, iy+3 ) ) + ( xget( xbuf, ix+4 ) * yget( ybuf, iy+4 ) ); // eslint-disable-line max-len
ix += M;
iy += M;
}
return dot;
}
for ( i = 0; i < N; i++ ) {
dot += xget( xbuf, ix ) * yget( ybuf, iy );
ix += strideX;
iy += strideY;
}
return dot;
}


// EXPORTS //

module.exports = gdot;
50 changes: 4 additions & 46 deletions lib/node_modules/@stdlib/blas/base/gdot/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

'use strict';

// VARIABLES //
// MODULES //

var M = 5;
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var ndarray = require( './ndarray.js' );


// MAIN //
Expand All @@ -43,50 +44,7 @@ var M = 5;
* // returns -5.0
*/
function gdot( N, x, strideX, y, strideY ) {
var dot;
var ix;
var iy;
var m;
var i;

dot = 0.0;
if ( N <= 0 ) {
return dot;
}
// Use unrolled loops if both strides are equal to `1`...
if ( strideX === 1 && strideY === 1 ) {
m = N % M;

// If we have a remainder, run a clean-up loop...
if ( m > 0 ) {
for ( i = 0; i < m; i++ ) {
dot += x[ i ] * y[ i ];
}
}
if ( N < M ) {
return dot;
}
for ( i = m; i < N; i += M ) {
dot += ( x[i]*y[i] ) + ( x[i+1]*y[i+1] ) + ( x[i+2]*y[i+2] ) + ( x[i+3]*y[i+3] ) + ( x[i+4]*y[i+4] ); // eslint-disable-line max-len
}
return dot;
}
if ( strideX < 0 ) {
ix = ( 1-N ) * strideX;
} else {
ix = 0;
}
if ( strideY < 0 ) {
iy = ( 1-N ) * strideY;
} else {
iy = 0;
}
for ( i = 0; i < N; i++ ) {
dot += ( x[ ix ] * y[ iy ] );
ix += strideX;
iy += strideY;
}
return dot;
return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len
}


Expand Down
13 changes: 13 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gdot/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

'use strict';

// MODULES //

var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
var accessors = require( './accessors.js' );


// VARIABLES //

var M = 5;
Expand Down Expand Up @@ -48,13 +54,20 @@ function gdot( N, x, strideX, offsetX, y, strideY, offsetY ) {
var dot;
var ix;
var iy;
var ox;
var oy;
var m;
var i;

dot = 0.0;
if ( N <= 0 ) {
return dot;
}
ox = arraylike2object( x );
oy = arraylike2object( y );
if ( ox.accessorProtocol || oy.accessorProtocol ) {
return accessors( N, ox, strideX, offsetX, oy, strideY, offsetY );
}
ix = offsetX;
iy = offsetY;

Expand Down
Loading