Skip to content

Conversation

@mgeier
Copy link
Contributor

@mgeier mgeier commented Sep 29, 2015

While I'm at suggesting breaking changes (see #132), I thought I might as well suggest another one ...

We discussed this already to quite some length in #16, but while I'm using it, I get the feeling that we may have chosen the wrong pill.

Arguments for always_2d=True:

  • it's consistent in itself (everything is 2D, even mono signals)
  • it's what you normally want in generic code (where you don't know if you get a mono or multi-channel file)

Arguments for always_2d=False:

  • it's consistent with most of NumPy/SciPy (one-channel signals are 1D arrays)
  • it's what you normally want in an interactive session (where you normally know if you are working on mono or multi-channel files)

I think we should simplify the interactive case, where being concise and the amount of typing matters most.
In the non-interactive case, it would even make the code more explicit and therefore easier to read, if people are forced to explicitly add always_2d=True.
This would be the equivalent to (but of course much simpler than) manually checking for the dimensions of an input array and reshaping it to the expected dimensionality, which is for sure done in many code bases.

There are several functions (like matplotlib.pyplot.specgram()) which only work on one-dimensional signals.
For those it would clearly be more practical to use always_2d=False.

There are other functions (like numpy.fft.rfft()) which work by default on axis=-1.
This works smoothly with always_2d=False, but it fails silently (just giving a completely wrong result) with always_2d=True.
For multi-channel files, people will have to explicitly use axis=0 anyway, there is no way around this (and if they forget, they will get unexpected - a.k.a. wrong - results).

I would expect to be able to do the simple steps

  1. load a mono file
  2. compute its FFT

without having to specify some cryptic argument always_2d=False.

For people working mainly with mono signals (which is probably the majority of people working in audio and especially speech signal processing), it would be much more natural to have always_2d=False as default setting.

It would also make things simpler for people learning signal processing with NumPy/SciPy.
Here are 2 examples where I had to explicitly add always_2d=False:
http://nbviewer.jupyter.org/github/mgeier/jupyter-presentation/blob/master/jupyter-presentation.ipynb
http://nbviewer.jupyter.org/github/spatialaudio/communication-acoustics-exercises/blob/master/ir-solutions.ipynb

This makes the following steps much simpler and easier to understand, but of course the explicit argument always_2d=False confuses the hell out of students and colleagues.

@mgeier mgeier added this to the 0.8.0 milestone May 5, 2015
@bastibe
Copy link
Owner

bastibe commented May 6, 2015

Sure, why not. I don't feel particularly strongly about this either way.

@mgeier mgeier changed the title Change default value of always_2d to False? Change default value of always_2d to False Aug 4, 2015
@mgeier
Copy link
Contributor Author

mgeier commented Sep 29, 2015

I added a commit (9b2556e) with a possible implementation.
Is it OK?

@bastibe
Copy link
Owner

bastibe commented Sep 30, 2015

Looks good, merge when you're ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants