You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: add accessor protocol support to stats/base/mean #5629
Refactor the mean function to add support for the accessor protocol. This
change ensures that the function can handle array-like objects with custom
accessors, improving flexibility and compatibility with various data
structures.
- Refactor mean function in main.js to delegate to ndarray.js
- Update ndarray.js to handle accessor protocol
- Add tests for accessor protocol support
- Fix JSDoc comments and examples for accuracy
Fixes: #5629
---
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: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- 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
---
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/stats/base/mean/README.md
+17-30
Original file line number
Diff line number
Diff line change
@@ -51,33 +51,29 @@ The [arithmetic mean][arithmetic-mean] is defined as
51
51
var mean =require( '@stdlib/stats/base/mean' );
52
52
```
53
53
54
-
#### mean( N, x, stride )
54
+
#### mean( N, x, strideX )
55
55
56
56
Computes the [arithmetic mean][arithmetic-mean] of a strided array `x`.
57
57
58
58
```javascript
59
59
var x = [ 1.0, -2.0, 2.0 ];
60
-
varN=x.length;
61
60
62
-
var v =mean( N, x, 1 );
61
+
var v =mean( x.length, x, 1 );
63
62
// returns ~0.3333
64
63
```
65
64
66
65
The function has the following parameters:
67
66
68
67
-**N**: number of indexed elements.
69
68
-**x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
70
-
-**stride**: index increment for `x`.
69
+
-**strideX**: stride length for `x`.
71
70
72
-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
71
+
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
73
72
74
73
```javascript
75
-
var floor =require( '@stdlib/math/base/special/floor' );
76
-
77
74
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
78
-
varN=floor( x.length/2 );
79
75
80
-
var v =mean( N, x, 2 );
76
+
var v =mean( 4, x, 2 );
81
77
// returns 1.25
82
78
```
83
79
@@ -87,42 +83,36 @@ Note that indexing is relative to the first index. To introduce an offset, use [
var x1 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
94
89
95
-
varN=floor( x0.length/2 );
96
-
97
-
var v =mean( N, x1, 2 );
90
+
var v =mean( 4, x1, 2 );
98
91
// returns 1.25
99
92
```
100
93
101
-
#### mean.ndarray( N, x, stride, offset )
94
+
#### mean.ndarray( N, x, strideX, offsetX )
102
95
103
96
Computes the [arithmetic mean][arithmetic-mean] of a strided array using alternative indexing semantics.
104
97
105
98
```javascript
106
99
var x = [ 1.0, -2.0, 2.0 ];
107
100
varN=x.length;
108
101
109
-
var v =mean.ndarray( N, x, 1, 0 );
102
+
var v =mean.ndarray( x.length, x, 1, 0 );
110
103
// returns ~0.33333
111
104
```
112
105
113
106
The function has the following additional parameters:
114
107
115
-
-**offset**: starting index for `x`.
108
+
-**offsetX**: starting index for `x`.
116
109
117
110
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 [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value
118
111
119
112
```javascript
120
-
var floor =require( '@stdlib/math/base/special/floor' );
121
-
122
113
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
123
-
varN=floor( x.length/2 );
124
114
125
-
var v =mean.ndarray( N, x, 2, 1 );
115
+
var v =mean.ndarray( 4, x, 2, 1 );
126
116
// returns 1.25
127
117
```
128
118
@@ -135,6 +125,7 @@ var v = mean.ndarray( N, x, 2, 1 );
135
125
## Notes
136
126
137
127
- If `N <= 0`, both functions return `NaN`.
128
+
- 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]).
138
129
- Depending on the environment, the typed versions ([`dmean`][@stdlib/stats/base/dmean], [`smean`][@stdlib/stats/base/smean], etc.) are likely to be significantly more performant.
139
130
140
131
</section>
@@ -148,18 +139,12 @@ var v = mean.ndarray( N, x, 2, 1 );
148
139
<!-- eslint no-undef: "error" -->
149
140
150
141
```javascript
151
-
var randu =require( '@stdlib/random/base/randu' );
152
-
var round =require( '@stdlib/math/base/special/round' );
0 commit comments