diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/README.md b/lib/node_modules/@stdlib/blas/base/gnrm2/README.md
index 7475dea9c0f5..59bc3333833c 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/README.md
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/README.md
@@ -49,7 +49,7 @@ var gnrm2 = require( '@stdlib/blas/base/gnrm2' );
#### gnrm2( N, x, stride )
-Computes the [L2-norm][l2-norm] of a vector `x`.
+Computes the [L2-norm][l2-norm] of a vector.
```javascript
var x = [ 1.0, -2.0, 2.0 ];
@@ -62,9 +62,9 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
-- **stride**: index increment for `x`.
+- **stride**: stride length.
-The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [L2-norm][l2-norm] of every other element in `x`,
+The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [L2-norm][l2-norm] of every other element:
```javascript
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
@@ -87,7 +87,7 @@ var z = gnrm2( 4, x1, 2 );
// returns 5.0
```
-If either `N` or `stride` is less than or equal to `0`, the function returns `0`.
+If `N` is less than or equal to `0`, the function returns `0`.
#### gnrm2.ndarray( N, x, stride, offset )
@@ -102,9 +102,9 @@ var z = gnrm2.ndarray( x.length, x, 1, 0 );
The function has the following additional parameters:
-- **offset**: starting index for `x`.
+- **offset**: starting index.
-While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [L2-norm][l2-norm] for every other value in `x` starting from the second value
+While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [L2-norm][l2-norm] for every other value in the strided array starting from the second value:
```javascript
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
@@ -123,6 +123,7 @@ var z = gnrm2.ndarray( 4, x, 2, 1 );
- If `N <= 0`, both functions return `0.0`.
- `gnrm2()` corresponds to the [BLAS][blas] level 1 function [`dnrm2`][dnrm2] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`dnrm2`][@stdlib/blas/base/dnrm2], [`snrm2`][@stdlib/blas/base/snrm2], 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]).
@@ -181,6 +182,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/dnrm2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dnrm2
[@stdlib/blas/base/snrm2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/snrm2
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/repl.txt
index 7934ee05c5d6..3a9a9870fdb3 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/repl.txt
@@ -2,13 +2,13 @@
{{alias}}( N, x, stride )
Computes the L2-norm of a vector.
- The `N` and `stride` parameters determine which elements in `x` are accessed
- at runtime.
+ The `N` and stride parameters determine which elements in the strided array
+ are accessed at runtime.
Indexing is relative to the first index. To introduce an offset, use a typed
array view.
- If `N <= 0` or `stride <= 0`, the function returns `0`.
+ If `N <= 0`, the function returns `0`.
Parameters
----------
@@ -19,7 +19,7 @@
Input array.
stride: integer
- Index increment.
+ Stride length.
Returns
-------
@@ -49,8 +49,8 @@
Computes the L2-norm of a vector using alternative indexing semantics.
While typed array views mandate a view offset based on the underlying
- buffer, the `offset` parameter supports indexing semantics based on a
- starting index.
+ buffer, the offset parameter supports indexing semantics based on a starting
+ index.
Parameters
----------
@@ -61,7 +61,7 @@
Input array.
stride: integer
- Index increment.
+ Stride length.
offset: integer
Starting index.
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/index.d.ts
index 650387c71f64..d1c1ffe2db95 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/index.d.ts
@@ -20,7 +20,12 @@
///
-import { NumericArray } from '@stdlib/types/array';
+import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
+
+/**
+* Input array.
+*/
+type InputArray = NumericArray | Collection | AccessorArrayLike;
/**
* Interface describing `gnrm2`.
@@ -40,7 +45,7 @@ interface Routine {
* var z = gnrm2( x.length, x, 1 );
* // returns 3.0
*/
- ( N: number, x: NumericArray, stride: number ): number;
+ ( N: number, x: InputArray, stride: number ): number;
/**
* Computes the L2-norm of a vector using alternative indexing semantics.
@@ -57,7 +62,7 @@ interface Routine {
* var z = gnrm2.ndarray( x.length, x, 1, 0 );
* // returns 3.0
*/
- ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
+ ndarray( N: number, x: InputArray, stride: number, offset: number ): number;
}
/**
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/test.ts
index 0fed6a2d250b..323bf75d86aa 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/test.ts
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/test.ts
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import AccessorArray = require( '@stdlib/array/base/accessor' );
import gnrm2 = require( './index' );
@@ -26,6 +27,7 @@ import gnrm2 = require( './index' );
const x = new Float64Array( 10 );
gnrm2( x.length, x, 1 ); // $ExpectType number
+ gnrm2( 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...
@@ -85,6 +87,7 @@ import gnrm2 = require( './index' );
const x = new Float64Array( 10 );
gnrm2.ndarray( x.length, x, 1, 0 ); // $ExpectType number
+ gnrm2.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...
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/accessors.js
new file mode 100644
index 000000000000..7b9ef0d080a1
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/accessors.js
@@ -0,0 +1,90 @@
+/**
+* @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 sqrt = require( '@stdlib/math/base/special/sqrt' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var pow = require( '@stdlib/math/base/special/pow' );
+
+
+// MAIN //
+
+/**
+* Computes the L2-norm of a vector.
+*
+* @private
+* @param {PositiveInteger} N - number of indexed elements
+* @param {Object} x - input array object
+* @param {Collection} x.data - input array data
+* @param {Array} x.accessors - array element accessors
+* @param {integer} stride - stride length
+* @param {NonNegativeInteger} offset - starting index
+* @returns {number} L2-norm
+*
+* @example
+* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
+* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
+*
+* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
+*
+* var z = gnrm2( 4, arraylike2object( toAccessorArray( x ) ), 2, 1 );
+* // returns 5.0
+*/
+function gnrm2( N, x, stride, offset ) {
+ var scale;
+ var buf;
+ var get;
+ var ssq;
+ var ax;
+ var ix;
+ var i;
+
+ buf = x.data;
+ get = x.accessors[ 0 ];
+
+ ix = offset;
+ if ( N === 1 ) {
+ return abs( get( buf, ix ) );
+ }
+ if ( stride === 0 ) {
+ return sqrt( N ) * abs( get( buf, ix ) );
+ }
+ scale = 0.0;
+ ssq = 1.0;
+ for ( i = 0; i < N; i++ ) {
+ if ( get( buf, ix ) !== 0.0 ) {
+ ax = abs( get( buf, ix ) );
+ if ( scale < ax ) {
+ ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) );
+ scale = ax;
+ } else {
+ ssq += pow( ax/scale, 2 );
+ }
+ }
+ ix += stride;
+ }
+ return scale * sqrt( ssq );
+}
+
+
+// EXPORTS //
+
+module.exports = gnrm2;
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/index.js
index a7d0ec60ff45..2ea9d198d313 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/index.js
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/index.js
@@ -32,13 +32,11 @@
* // returns 3.0
*
* @example
-* var floor = require( '@stdlib/math/base/special/floor' );
* var gnrm2 = require( '@stdlib/blas/base/gnrm2' );
*
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
-* var N = floor( x.length / 2 );
*
-* var z = gnrm2.ndarray( N, x, 2, 1 );
+* var z = gnrm2.ndarray( 4, x, 2, 1 );
* // returns 5.0
*/
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/main.js b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/main.js
index 49bc57e3f801..78c3a7ed6c3e 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/main.js
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/main.js
@@ -20,9 +20,8 @@
// MODULES //
-var sqrt = require( '@stdlib/math/base/special/sqrt' );
-var abs = require( '@stdlib/math/base/special/abs' );
-var pow = require( '@stdlib/math/base/special/pow' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
+var ndarray = require( './ndarray.js' );
// MAIN //
@@ -42,32 +41,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
* // returns 3.0
*/
function gnrm2( N, x, stride ) {
- var scale;
- var ssq;
- var ax;
- var i;
-
- if ( N <= 0 || stride <= 0 ) {
- return 0.0;
- }
- if ( N === 1 ) {
- return abs( x[ 0 ] );
- }
- scale = 0.0;
- ssq = 1.0;
- N *= stride;
- for ( i = 0; i < N; i += stride ) {
- if ( x[ i ] !== 0.0 ) {
- ax = abs( x[ i ] );
- if ( scale < ax ) {
- ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) );
- scale = ax;
- } else {
- ssq += pow( ax/scale, 2 );
- }
- }
- }
- return scale * sqrt( ssq );
+ return ndarray( N, x, stride, stride2offset( N, stride ) );
}
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/ndarray.js
index 651b5f42c160..ae11c044faf4 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/lib/ndarray.js
@@ -20,9 +20,11 @@
// MODULES //
+var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var abs = require( '@stdlib/math/base/special/abs' );
var pow = require( '@stdlib/math/base/special/pow' );
+var accessors = require( './accessors.js' );
// MAIN //
@@ -37,12 +39,9 @@ var pow = require( '@stdlib/math/base/special/pow' );
* @returns {number} L2-norm
*
* @example
-* var floor = require( '@stdlib/math/base/special/floor' );
-*
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
-* var N = floor( x.length / 2 );
*
-* var z = gnrm2( N, x, 2, 1 );
+* var z = gnrm2( 4, x, 2, 1 );
* // returns 5.0
*/
function gnrm2( N, x, stride, offset ) {
@@ -50,15 +49,25 @@ function gnrm2( N, x, stride, offset ) {
var ssq;
var ax;
var ix;
+ var o;
var i;
if ( N <= 0 ) {
return 0.0;
}
- if ( N === 1 ) {
- return abs( x[ offset ] );
+
+ o = arraylike2object( x );
+ if ( o.accessorProtocol ) {
+ return accessors( N, o, stride, offset );
}
+
ix = offset;
+ if ( N === 1 ) {
+ return abs( x[ ix ] );
+ }
+ if ( stride === 0 ) {
+ return sqrt( N ) * abs( x[ ix ] );
+ }
scale = 0.0;
ssq = 1.0;
for ( i = 0; i < N; i++ ) {
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.main.js b/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.main.js
index 37daffb4ed91..21422270f707 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.main.js
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.main.js
@@ -22,6 +22,8 @@
var tape = require( 'tape' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
+var abs = require( '@stdlib/math/base/special/abs' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var Float64Array = require( '@stdlib/array/float64' );
var gnrm2 = require( './../lib/main.js' );
@@ -56,6 +58,23 @@ tape( 'the function calculates the L2-norm of a vector', function test( t ) {
t.end();
});
+tape( 'the function calculates the L2-norm of a vector (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 1 );
+ t.strictEqual( z, sqrt( 55.0 ), 'returns expected value' );
+
+ x = [ -4.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 1 );
+ t.strictEqual( z, 4.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) {
var x;
var z;
@@ -72,7 +91,6 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
});
tape( 'the function supports a `stride` parameter', function test( t ) {
- var N;
var x;
var z;
@@ -87,24 +105,95 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
2.0
];
- N = 4;
- z = gnrm2( N, x, 2 );
+ z = gnrm2( 4, x, 2 );
t.strictEqual( z, 5.0, 'returns expected value' );
t.end();
});
-tape( 'if provided a `stride` parameter less than or equal to `0`, the function returns `0`', function test( t ) {
+tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 1.0, // 0
+ 2.0,
+ 2.0, // 1
+ -7.0,
+ -2.0, // 2
+ 3.0,
+ 4.0, // 3
+ 2.0
+ ];
+
+ z = gnrm2( 4, toAccessorArray( x ), 2 );
+
+ t.strictEqual( z, 5.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a negative `stride` parameter', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ z = gnrm2( 4, x, -2 );
+
+ t.strictEqual( z, 5.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports providing a negative `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ z = gnrm2( 4, x, -2 );
+
+ t.strictEqual( z, 5.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the L2-norm of a vector', function test( t ) {
var x;
var z;
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
z = gnrm2( x.length, x, 0 );
- t.strictEqual( z, 0.0, 'returns expected value' );
+ t.strictEqual( z, sqrt( x.length ) * abs( x[0] ), 'returns expected value' );
- z = gnrm2( x.length, x, -1 );
- t.strictEqual( z, 0.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the L2-norm of a vector (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 0 );
+ t.strictEqual( z, sqrt( x.length ) * abs( x[0] ), 'returns expected value' );
t.end();
});
@@ -112,7 +201,6 @@ tape( 'if provided a `stride` parameter less than or equal to `0`, the function
tape( 'the function supports view offsets', function test( t ) {
var x0;
var x1;
- var N;
var z;
x0 = new Float64Array([
@@ -128,9 +216,8 @@ tape( 'the function supports view offsets', function test( t ) {
]);
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
- N = 4;
- z = gnrm2( N, x1, 2 );
+ z = gnrm2( 4, x1, 2 );
t.strictEqual( z, 5.0, 'returns expected value' );
t.end();
diff --git a/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.ndarray.js
index ee7a936ad764..d48bb20e5fb2 100644
--- a/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/base/gnrm2/test/test.ndarray.js
@@ -21,7 +21,9 @@
// MODULES //
var tape = require( 'tape' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
+var abs = require( '@stdlib/math/base/special/abs' );
var gnrm2 = require( './../lib/ndarray.js' );
@@ -55,6 +57,23 @@ tape( 'the function calculates the L2-norm of a vector', function test( t ) {
t.end();
});
+tape( 'the function calculates the L2-norm of a vector (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( z, sqrt( 55.0 ), 'returns expected value' );
+
+ x = [ -4.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( z, 4.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) {
var x;
var z;
@@ -71,7 +90,6 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
});
tape( 'the function supports a `stride` parameter', function test( t ) {
- var N;
var x;
var z;
@@ -86,15 +104,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
2.0
];
- N = 4;
- z = gnrm2( N, x, 2, 0 );
+ z = gnrm2( 4, x, 2, 0 );
t.strictEqual( z, 5.0, 'returns expected value' );
t.end();
});
-tape( 'the function supports a negative `stride` parameter', function test( t ) {
- var N;
+tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
var x;
var z;
@@ -109,15 +125,79 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
2.0
];
- N = 4;
- z = gnrm2( N, x, -2, x.length-2 );
+ z = gnrm2( 4, toAccessorArray( x ), 2, 0 );
+
+ t.strictEqual( z, 5.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a negative `stride` parameter', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ z = gnrm2( 4, x, -2, x.length-2 );
t.strictEqual( z, 5.0, 'returns expected value' );
t.end();
});
+tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ z = gnrm2( 4, x, -2, x.length-2 );
+
+ t.strictEqual( z, 5.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the L2-norm of a vector', function test( t ) {
+ var x;
+ var z;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ z = gnrm2( x.length, x, 0, 0 );
+ t.strictEqual( z, sqrt( x.length ) * abs( x[0] ), 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the L2-norm of a vector (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ z = gnrm2( x.length, toAccessorArray( x ), 0, 0 );
+ t.strictEqual( z, sqrt( x.length ) * abs( x[0] ), 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports an `offset` parameter', function test( t ) {
- var N;
var x;
var z;
@@ -131,9 +211,29 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
3.0,
4.0 // 3
];
- N = 4;
- z = gnrm2( N, x, 2, 1 );
+ z = gnrm2( 4, x, 2, 1 );
+ t.strictEqual( z, 5.0, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function supports an `offset` parameter (accessors)', function test( t ) {
+ var x;
+ var z;
+
+ x = [
+ 2.0,
+ 1.0, // 0
+ 2.0,
+ -2.0, // 1
+ -2.0,
+ 2.0, // 2
+ 3.0,
+ 4.0 // 3
+ ];
+
+ z = gnrm2( 4, toAccessorArray( x ), 2, 1 );
t.strictEqual( z, 5.0, 'returns expected value' );
t.end();