Skip to main content

A library for executing running calculations

Project description

Introduction

Instances of the RunnincCalc classes in this library can be fed one input value at a time. This allows running several calculations in a single pass over an iterator. This isn’t possible with the built-in variants of most calculations, such as max() and heapq.nlargest().

RunningCalc instances can be fed values directly, for example:

mean_rc, stddev_rc = RunningMean(), RunningStdDev()
for x in values:
    mean_rc.feed(x)
    stddev_rc.feed(x)
mean, stddev = mean_rc.value, stddev_rc.value

Additionally, the apply_in_parallel() function is supplied, which makes performing several calculations in parallel easy (and fast!). For example:

mean, stddev = apply_in_parallel([RunningMean(), RunningStdDev()], values)
five_smallest, five_largest = apply_in_parallel([RunningNSmallest(5), RunningNLargest(5)], values)

Optimizations

In addition to the basic feed() method, some RunningCalc classes also implement an optimized feedMultiple() method, which accepts a sequence of values to be processed. This allows values to be processed in chunks, allowing for faster processing in many cases.

The apply_in_parallel() function automatically splits the given iterable of input values into chunks (chunk size can be controlled via the chunk_size keyword argument). Therefore using apply_in_parallel() is both fast and easy.

Writing Your Own RunningCalc Class

  1. sub-class RunningCalc

  2. implement the __init__() and feed() methods

  3. make the calculation output value accessible via the value attribute

  4. optionally implement an optimized feedMultiple() method Note: the RunningCalc base class includes a default naive implementation of feedMultiple()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RunningCalcs-0.4.zip (6.6 kB view details)

Uploaded Source

File details

Details for the file RunningCalcs-0.4.zip.

File metadata

  • Download URL: RunningCalcs-0.4.zip
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for RunningCalcs-0.4.zip
Algorithm Hash digest
SHA256 f763b0900de2922c0b31dfcead5e132050895285f709ccf6eee84dcaa56def2b
MD5 0b865454d8d7dc43bc99c82fe31beea4
BLAKE2b-256 b1d7eba1b3f001b59083d295219494af9514849ded5dbf19421ac777cac87087

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page