GithubHelp home page GithubHelp logo

Comments (7)

rgommers avatar rgommers commented on September 28, 2024

The code from the PR, just in case that PRs on that repo won't be accessible in the future (we may close them completely if people keep sending PRs there instead of here):

def wavedec_coeff_len(data_len, filter_len, mode, level=None):
    """
    Total number of coefficients in the output of `wavedec`, given data
    length, filter length, mode and level.
    Returns integer: len(cAn) + len(cDn) + len(cDn-1) + ... + len(cD1)
    data_len   - data length
    filter_len - filter length or Wavelet instance
    level      - decomposition level. If level is None then it will be
                 calculated using `dwt_max_level` function.
    """

    if level is None:
        level = dwt_max_level(data_len, filter_len)
    elif level < 0:
        raise ValueError(
            "Level value of %d is too low . Minimum level is 0." % level)
    total_len = 0

    for i in xrange(level):
        data_len = dwt_coeff_len(data_len, filter_len, mode)
        total_len += data_len 

    return total_len + data_len

from pywt.

rgommers avatar rgommers commented on September 28, 2024

PR author is @belevtsoff

from pywt.

belevtsoff avatar belevtsoff commented on September 28, 2024

Wow, thanks for resurrecting this, it's been 3 years :)

from pywt.

rgommers avatar rgommers commented on September 28, 2024

time flies:)

from pywt.

rgommers avatar rgommers commented on September 28, 2024

The motivation given on the original PR:

We used PyWavelets recently in our SpikeSort project. In particular, hstacked ouput from pywt.wavedec was used as a single feature vector. This approach is often used for spike sorting. The function I'm proposing, will be very handy when one wants to allocate a fixed-size numpy array to store wavelet coefficients (obtained from wavedec), before the input data is processed (for example, if one has a huge stack of equal-length independent signals to process and store).

@PyWavelets/core opinions on adding this function?

from pywt.

grlee77 avatar grlee77 commented on September 28, 2024

I think the implementation is correct and it would not be a burden to maintain. However, I'm not sure if there is still much of a use case for it (see below).

For batched 1D transforms, it should now be faster to run them all at once using the axis feature of wavedec (which was not present at the time the original PR was opened).

If wavedecn was used to do the 1D transforms, one could also then use coeffs_to_array to convert to a single array, which I think is the use case stated above?

e.g. to transform 1000 signals, each of length 256 and get the results in a single array:

coeffs = pywt.wavedecn(np.random.randn(256, 1000), 'db2', 'periodization', axes=(0, ))
coeff_array, slices = pywt.coeffs_to_array(coeffs, axes=(0, ))

from pywt.

rgommers avatar rgommers commented on September 28, 2024

Thanks @grlee77, good points. And if one really wanted to do preallocation for some reason, it wouldn't be much of an issue to run a single transform once and obtain the length from the output of that.

So closing.

from pywt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.