<commit_before><!--

@license Apache-2.0

Copyright (c) 2019 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.

-->

# itermsum

> Create an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum.

<section class="intro">

For a window of size `W`, the moving sum is defined as

<!-- <equation class="equation" label="eq:moving_sum" align="center" raw="s = \sum_{i=0}^{W-1} x_i" alt="Equation for the moving sum."> -->

<div class="equation" align="center" data-raw-text="s = \sum_{i=0}^{W-1} x_i" data-equation="eq:moving_sum">
    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/649f1d940ae76f02c3c2fc97e52f59b452e2e15f/lib/node_modules/@stdlib/stats/iter/msum/docs/img/equation_moving_sum.svg" alt="Equation for the moving sum.">
    <br>
</div>

<!-- </equation> -->

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var itermsum = require( '@stdlib/stats/iter/msum' );
```

#### itermsum( iterator, W )

Returns an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum. The `W` parameter defines the number of iterated values over which to compute the moving sum.

```javascript
var array2iterator = require( '@stdlib/array/to-iterator' );

var arr = array2iterator( [ 2.0, 1.0, 3.0, -7.0, -5.0 ] );
var it = itermsum( arr, 3 );

// Fill the window...
var m = it.next().value; // [2.0]
// returns 2.0

m = it.next().value; // [2.0, 1.0]
// returns 3.0

m = it.next().value; // [2.0, 1.0, 3.0]
// returns 6.0

// Window begins sliding...
m = it.next().value; // [1.0, 3.0, -7.0]
// returns -3.0

m = it.next().value; // [3.0, -7.0, -5.0]
// returns -9.0<commit_msg>Rename variable<commit_after><!--

@license Apache-2.0

Copyright (c) 2019 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.

-->

# itermsum

> Create an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum.

<section class="intro">

For a window of size `W`, the moving sum is defined as

<!-- <equation class="equation" label="eq:moving_sum" align="center" raw="s = \sum_{i=0}^{W-1} x_i" alt="Equation for the moving sum."> -->

<div class="equation" align="center" data-raw-text="s = \sum_{i=0}^{W-1} x_i" data-equation="eq:moving_sum">
    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/649f1d940ae76f02c3c2fc97e52f59b452e2e15f/lib/node_modules/@stdlib/stats/iter/msum/docs/img/equation_moving_sum.svg" alt="Equation for the moving sum.">
    <br>
</div>

<!-- </equation> -->

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var itermsum = require( '@stdlib/stats/iter/msum' );
```

#### itermsum( iterator, W )

Returns an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum. The `W` parameter defines the number of iterated values over which to compute the moving sum.

```javascript
var array2iterator = require( '@stdlib/array/to-iterator' );

var arr = array2iterator( [ 2.0, 1.0, 3.0, -7.0, -5.0 ] );
var it = itermsum( arr, 3 );

// Fill the window...
var s = it.next().value; // [2.0]
// returns 2.0

s = it.next().value; // [2.0, 1.0]
// returns 3.0

s = it.next().value; // [2.0, 1.0, 3.0]
// returns 6.0

// Window begins sliding...
s = it.next().value; // [1.0, 3.0, -7.0]
// returns -3.0

s = it.next().value; // [3.0, -7.0, -5.0]
// returns -9.0
{'fraction_non_alphanumeric': 0.16421343146274148, 'fraction_numerical': 0.03955841766329347, 'mean_word_length': 3.6167728237791934, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6339528', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1474, 'n_words': 476}