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/gasum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ sum = gasum.ndarray( 3, x, -1, x.length-1 );

- If `N <= 0`, both functions return `0`.
- `gasum()` corresponds to the [BLAS][blas] level 1 function [`dasum`][dasum] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`dasum`][@stdlib/blas/base/dasum], [`sasum`][@stdlib/blas/base/sasum], 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( y );

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

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

<!-- <related-links> -->

<!-- </related-links> -->
Expand Down
11 changes: 8 additions & 3 deletions lib/node_modules/@stdlib/blas/base/gasum/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 `gasum`.
Expand All @@ -40,7 +45,7 @@ interface Routine {
* var z = gasum( x.length, x, 1 );
* // returns 15.0
*/
( N: number, x: NumericArray, stride: number ): number;
( N: number, x: InputArray, stride: number ): number;

/**
* Computes the sum of the absolute values using alternative indexing semantics.
Expand All @@ -57,7 +62,7 @@ interface Routine {
* var z = gasum.ndarray( x.length, x, 1, 0 );
* // returns 21.0
*/
ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
ndarray( N: number, x: InputArray, stride: number, offset: number ): number;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gasum/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 gasum = require( './index' );


Expand All @@ -26,6 +27,7 @@ import gasum = require( './index' );
const x = new Float64Array( 10 );

gasum( x.length, x, 1 ); // $ExpectType number
gasum( x.length, new AccessorArray( x ), 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 @@ -86,6 +88,7 @@ import gasum = require( './index' );
const x = new Float64Array( 10 );

gasum.ndarray( x.length, x, 1, 0 ); // $ExpectType number
gasum.ndarray( x.length, new AccessorArray( x ), 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
101 changes: 101 additions & 0 deletions lib/node_modules/@stdlib/blas/base/gasum/lib/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @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';

// MODULES //

var abs = require( '@stdlib/math/base/special/abs' );


// VARIABLES //

var M = 6;


// MAIN //

/**
* Computes the sum of absolute values.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Object} x - input array object
* @param {Collection} x.data - input array data
* @param {Array<Function>} x.accessors - array element accessors
* @param {integer} stride - index increment
* @param {NonNegativeInteger} offset - starting index
* @returns {number} sum
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = [ 1.0, -2.0, 3.0, -4.0, 5.0 ];
*
* var s = gasum( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0 );
* // returns 15.0
*/
function gasum( N, x, stride, offset ) {
var buf;
var get;
var sum;
var ix;
var m;
var i;

buf = x.data;
get = x.accessors[ 0 ];

sum = 0.0;
ix = offset;
if ( stride === 0 ) {
sum = abs( get( buf, ix ) * N );
return sum;
}

// Use unrolled loops if the stride is equal to `1`...
if ( stride === 1 ) {
m = N % M;

// If we have a remainder, run a clean-up loop...
if ( m > 0 ) {
for ( i = 0; i < m; i++ ) {
sum += abs( get( buf, ix ) );
ix += stride;
}
}
if ( N < M ) {
return sum;
}
for ( i = m; i < N; i += M ) {
sum += abs( get( buf, ix ) ) + abs( get( buf, ix+1 ) ) + abs( get( buf, ix+2 ) ) + abs( get( buf, ix+3 ) ) + abs( get( buf, ix+4 ) ) + abs( get( buf, ix+5 ) ); // eslint-disable-line max-len
ix += M;
}
return sum;
}
for ( i = 0; i < N; i++ ) {
sum += abs( get( buf, ix ) );
ix += stride;
}
return sum;
}


// EXPORTS //

module.exports = gasum;
42 changes: 4 additions & 38 deletions lib/node_modules/@stdlib/blas/base/gasum/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@

// MODULES //

var abs = require( '@stdlib/math/base/special/abs' );


// VARIABLES //

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


// MAIN //
Expand All @@ -42,40 +38,10 @@ var M = 6;
* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] );
*
* var s = gasum( x.length, x, 1 );
* // 15.0
* // returns 15.0
*/
function gasum( N, x, stride ) {
var sum;
var m;
var i;

sum = 0.0;
if ( N <= 0 || stride <= 0 ) {
return sum;
}
// Use unrolled loops if the stride is equal to `1`...
if ( stride === 1 ) {
m = N % M;

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


Expand Down
14 changes: 13 additions & 1 deletion lib/node_modules/@stdlib/blas/base/gasum/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// MODULES //

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


// VARIABLES //
Expand All @@ -43,19 +45,29 @@ var M = 6;
* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] );
*
* var s = gasum( x.length, x, 1, 0 );
* // 15.0
* // returns 15.0
*/
function gasum( N, x, stride, offset ) {
var sum;
var ix;
var m;
var i;
var o;

sum = 0.0;
if ( N <= 0 ) {
return sum;
}
o = arraylike2object( x );
if ( o.accessorProtocol ) {
return accessors( N, o, stride, offset );
}

ix = offset;
if ( stride === 0 ) {
sum = abs( x[ix] * N );
return sum;
}

// Use unrolled loops if the stride is equal to `1`...
if ( stride === 1 ) {
Expand Down
Loading