dlib icon indicating copy to clipboard operation
dlib copied to clipboard

Adding backport of bessel functions + window functions

Open pfeatherstone opened this issue 3 years ago • 13 comments

This is generally useful, but also this is laying down the foundation for stuff like filter design, computing STFTs and maybe who knows, some DSP.

pfeatherstone avatar Jul 06 '22 13:07 pfeatherstone

The boost implementation is unbelievably complicated. Sod it, would it be agreeable to add PRs for filter design and STFTs and have __cpp_lib_math_special_functions as a contract pre-condition?

pfeatherstone avatar Jul 09 '22 06:07 pfeatherstone

Looked at scipy implementation, it's Fortran...

pfeatherstone avatar Jul 09 '22 06:07 pfeatherstone

The boost implementation is unbelievably complicated. Sod it, would it be agreeable to add PRs for filter design and STFTs and have __cpp_lib_math_special_functions as a contract pre-condition?

Eh, I don't want to have stuff that doesn't always work. Dlib is all about everything always working regardless of platform.

Nothing stopping you from doing this in another repo though. Dlib repo isn't special at the end of the day.

At some point I'll jump dlib to needing c++17 too. I usually make sure dlib works with compilers from the last 6 or 7 years. Which is coming up soonish for c++17.

davisking avatar Jul 09 '22 11:07 davisking

Not sure. Libc++ doesn't support special math functions so clang on macOS wouldn't work. Some compilers don't fully support std::filesystem which is c++17. So I don't think c++17 is universally supported yet.

pfeatherstone avatar Jul 09 '22 14:07 pfeatherstone

I'll crack on with stripping boost but my god they needlessly make things complicated. Like every single function is templated with a policy, like even something as trivial sign().

pfeatherstone avatar Jul 09 '22 14:07 pfeatherstone

There you go, stripping boost only requires 1300 lines of code to implement two math functions. Nice and succinct in typical boost fashion.

pfeatherstone avatar Jul 10 '22 07:07 pfeatherstone

Don't know what's going on but the Python/windows build configuration always fails with:

python setup.py bdist_wheel did not run successfully.
  exit code: 1
  [6 lines of output]
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  error: invalid command 'bdist_wheel'

pfeatherstone avatar Jul 12 '22 11:07 pfeatherstone

Don't know what's going on but the Python/windows build configuration always fails with:

python setup.py bdist_wheel did not run successfully.
  exit code: 1
  [6 lines of output]
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  error: invalid command 'bdist_wheel'

Yeah it's on master too. Was just looking at that. Not sure what the deal is.

davisking avatar Jul 12 '22 23:07 davisking

Otherwise are you happy with the code ?

pfeatherstone avatar Jul 13 '22 07:07 pfeatherstone

Sorry i modified the API. I've opted for using strong types and function overloading for kaiser() instead of different function signatures. I think it's clearer and the user has to stop and think a bit about how to call the function correctly using the right strong type decorators. I think it's less error-prone.

pfeatherstone avatar Jul 13 '22 13:07 pfeatherstone

Ok I think I have everything I need now. So if unit tests pass, we're good to go. For those who are interested, next PR will be STFT and ISTFT. This is useful generally in DSP and audio processing. But it's also useful in blind source separation algorithms like ILRMA and MNMF which use traditional machine learning algorithms operating on STFT domain to blindly separate channels which I think @davisking will enjoy.

pfeatherstone avatar Jul 14 '22 21:07 pfeatherstone

@davisking what do you think ? Ok or horse manure ?

pfeatherstone avatar Jul 18 '22 12:07 pfeatherstone

Looks ok. I looked a little last night. Will look more again soon. Seems sensible though :)

davisking avatar Jul 18 '22 12:07 davisking