Skip to content

Commit de4fffa

Browse files
committed
fix: implementation to use meanpn
--- 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 4d689a3 commit de4fffa

File tree

5 files changed

+57
-144
lines changed

5 files changed

+57
-144
lines changed

lib/node_modules/@stdlib/stats/base/mean/lib/accessors.js

Lines changed: 0 additions & 85 deletions
This file was deleted.

lib/node_modules/@stdlib/stats/base/mean/lib/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,11 @@
4242

4343
// MODULES //
4444

45-
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
46-
var main = require( './main.js' );
47-
var ndarray = require( './ndarray.js' );
48-
49-
50-
// MAIN //
51-
52-
setReadOnly( main, 'ndarray', ndarray );
45+
var mean = require( './main.js' );
5346

5447

5548
// EXPORTS //
5649

57-
module.exports = main;
50+
module.exports = mean;
5851

59-
// exports: { "ndarray": "main.ndarray" }
52+
// exports: { "ndarray": "mean.ndarray" }

lib/node_modules/@stdlib/stats/base/mean/lib/main.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,14 @@
2020

2121
// MODULES //
2222

23-
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
23+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var mean = require( './mean.js' );
2425
var ndarray = require( './ndarray.js' );
2526

2627

2728
// MAIN //
2829

29-
/**
30-
* Computes the mean value of a strided array.
31-
*
32-
* @param {PositiveInteger} N - number of indexed elements
33-
* @param {NumericArray} x - input array
34-
* @param {integer} strideX - stride length
35-
* @returns {number} mean value
36-
*
37-
* @example
38-
* var x = [ 1.0, -2.0, 2.0 ];
39-
* var N = x.length;
40-
*
41-
* var v = mean( N, x, 1 );
42-
* // returns 0.3333333333333333
43-
*/
44-
function mean( N, x, strideX ) {
45-
return ndarray( N, x, strideX, stride2offset( N, strideX ) );
46-
}
30+
setReadOnly( mean, 'ndarray', ndarray );
4731

4832

4933
// EXPORTS //
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var meanpn = require( '@stdlib/stats/base/meanpn' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Computes the arithmetic mean of a strided array.
30+
*
31+
* @param {PositiveInteger} N - number of indexed elements
32+
* @param {NumericArray} x - input array
33+
* @param {integer} strideX - stride length
34+
* @returns {number} arithmetic mean
35+
*
36+
* @example
37+
* var x = [ 1.0, -2.0, 2.0 ];
38+
*
39+
* var v = mean( x.length, x, 1 );
40+
* // returns ~0.3333
41+
*/
42+
function mean( N, x, strideX ) {
43+
return meanpn( N, x, strideX );
44+
}
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = mean;

lib/node_modules/@stdlib/stats/base/mean/lib/ndarray.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
// MODULES //
2222

23-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24-
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
25-
var accessors = require( './accessors.js' );
23+
var meanpn = require( '@stdlib/stats/base/meanpn' ).ndarray;
2624

2725

2826
// MAIN //
@@ -43,33 +41,7 @@ var accessors = require( './accessors.js' );
4341
* // returns 1.25
4442
*/
4543
function mean( N, x, strideX, offsetX ) {
46-
var sum;
47-
var ix;
48-
var o;
49-
var v;
50-
var i;
51-
52-
if ( N <= 0 ) {
53-
return NaN;
54-
}
55-
o = arraylike2object( x );
56-
if ( o.accessorProtocol ) {
57-
return accessors( N, o, strideX, offsetX );
58-
}
59-
if ( N === 1 || strideX === 0 ) {
60-
return x[ offsetX ];
61-
}
62-
ix = offsetX;
63-
sum = 0;
64-
for ( i = 0; i < N; i++ ) {
65-
v = x[ ix ];
66-
if ( isnan( v ) ) {
67-
return v;
68-
}
69-
sum += v;
70-
ix += strideX;
71-
}
72-
return sum / N;
44+
return meanpn( N, x, strideX, offsetX );
7345
}
7446

7547

0 commit comments

Comments
 (0)