Skip to content

Commit 7568358

Browse files
committed
fix: add missing docs and refactor
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 3db1791 commit 7568358

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

lib/node_modules/@stdlib/blas/base/gnrm2/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var z = gnrm2.ndarray( 4, x, 2, 1 );
123123

124124
- If `N <= 0`, both functions return `0.0`.
125125
- `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.
126+
- 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]).
126127

127128
</section>
128129

@@ -181,6 +182,8 @@ console.log( out );
181182

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

185+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
186+
184187
[@stdlib/blas/base/dnrm2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dnrm2
185188

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

lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/index.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

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

23-
import { NumericArray } from '@stdlib/types/array';
23+
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Input array.
27+
*/
28+
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
2429

2530
/**
2631
* Interface describing `gnrm2`.
@@ -40,7 +45,7 @@ interface Routine {
4045
* var z = gnrm2( x.length, x, 1 );
4146
* // returns 3.0
4247
*/
43-
( N: number, x: NumericArray, stride: number ): number;
48+
( N: number, x: InputArray, stride: number ): number;
4449

4550
/**
4651
* Computes the L2-norm of a vector using alternative indexing semantics.
@@ -57,7 +62,7 @@ interface Routine {
5762
* var z = gnrm2.ndarray( x.length, x, 1, 0 );
5863
* // returns 3.0
5964
*/
60-
ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
65+
ndarray( N: number, x: InputArray, stride: number, offset: number ): number;
6166
}
6267

6368
/**

lib/node_modules/@stdlib/blas/base/gnrm2/docs/types/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import AccessorArray = require( '@stdlib/array/base/accessor' );
1920
import gnrm2 = require( './index' );
2021

2122

@@ -26,6 +27,7 @@ import gnrm2 = require( './index' );
2627
const x = new Float64Array( 10 );
2728

2829
gnrm2( x.length, x, 1 ); // $ExpectType number
30+
gnrm2( x.length, new AccessorArray( x ), 1 ); // $ExpectType number
2931
}
3032

3133
// 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' );
8587
const x = new Float64Array( 10 );
8688

8789
gnrm2.ndarray( x.length, x, 1, 0 ); // $ExpectType number
90+
gnrm2.ndarray( x.length, new AccessorArray( x ), 1, 0 ); // $ExpectType number
8891
}
8992

9093
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...

lib/node_modules/@stdlib/blas/base/gnrm2/lib/accessors.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,28 @@ var pow = require( '@stdlib/math/base/special/pow' );
4949
*/
5050
function gnrm2( N, x, stride, offset ) {
5151
var scale;
52-
var xbuf;
53-
var xget;
52+
var buf;
53+
var get;
5454
var ssq;
5555
var ax;
5656
var ix;
5757
var i;
5858

59-
xbuf = x.data;
60-
xget = x.accessors[ 0 ];
59+
buf = x.data;
60+
get = x.accessors[ 0 ];
6161

6262
ix = offset;
6363
if ( N === 1 ) {
64-
return abs( xget( xbuf, ix ) );
64+
return abs( get( buf, ix ) );
6565
}
6666
if ( stride === 0 ) {
67-
return abs( N * xget( xbuf, ix ) );
67+
return abs( N * get( buf, ix ) );
6868
}
6969
scale = 0.0;
7070
ssq = 1.0;
7171
for ( i = 0; i < N; i++ ) {
72-
if ( xget( xbuf, ix ) !== 0.0 ) {
73-
ax = abs( xget( xbuf, ix ) );
72+
if ( get( buf, ix ) !== 0.0 ) {
73+
ax = abs( get( buf, ix ) );
7474
if ( scale < ax ) {
7575
ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) );
7676
scale = ax;

0 commit comments

Comments
 (0)