Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing GitHub workflows #1

Merged
merged 12 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ on:
branches: [ "main" ]

jobs:
linters-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pdm
python -m pdm install --no-lock --no-self --no-default -G linters
- name: Run flake8
run: |
python -m flake8 src/ tests/
linters-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pdm install --no-lock --no-self --no-default -G linters
- name: Run flake8
run: |
pdm run -v flake8 src/ tests/
85 changes: 23 additions & 62 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,26 @@ permissions:
contents: read

jobs:
build-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pdm
pdm install --no-lock -G tests
- name: Test with pytest
run: |
cd tests/
pytest .

build-macos:
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pdm
pdm install --no-lock -G tests
- name: Test with pytest
run: |
cd tests/
pytest .

build-windows:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pdm
pdm install --no-lock -G tests
- name: Test with pytest
run: |
cd tests/
pytest .
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest] # TODO: extend with windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pdm install --no-lock -v -G tests
- name: Test with pytest
run: |
cd tests/
pdm run -v pytest .
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

# Compiler flags
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # is -O3 worth it? -O2

# Find libs nanobind
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ linters = [
tests = [
"pytest",
"numpy >= 1.24.4",
"torchaudio >= 2.0.1",
"scipy",
]

Expand Down
30 changes: 22 additions & 8 deletions src/_fastwave.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#include <string>
#include <array>
#include <chrono>
#include <cstring> // std::memcpy
#include <iterator>
#include <iostream>
#include <stdexcept>

#include <fstream>
#include <iterator>
#include <vector>
#include <chrono>
#include <numeric>
#include <string>
#include <stdexcept>
#include <thread>
#include <vector>

#if defined(__linux__) || defined(__APPLE__)
#include <sys/mman.h> // include for mmap support
// includes for open and it's flags
#include <sys/stat.h>
#include <fcntl.h>

#include <numeric>
// #elif _WIN32
// // windows code goes here
// #else
#endif

#include "nanobind/nanobind.h"
#include "nanobind/ndarray.h"
Expand Down Expand Up @@ -376,7 +382,11 @@ namespace fastwave
{
if (_buffer != nullptr) {
if (is_mmap) {
#if defined(__linux__) || defined(__APPLE__)
munmap(reinterpret_cast<void *>(_buffer), _buffer_size);
#else
throw std::runtime_error("MUNMAP is not supported on this platform!");
#endif
}
else {
free(_buffer);
Expand All @@ -387,6 +397,7 @@ namespace fastwave

void read_mmap(const std::string &file_path, bool is_shared)
{
#if defined(__linux__) || defined(__APPLE__)
// Allow MAP_SHARED and MAP_PRIVATE
// https://man7.org/linux/man-pages/man2/mmap.2.html
// Unmap the memory if it was previously mapped
Expand All @@ -405,6 +416,9 @@ namespace fastwave
// Update mmap flag:
is_mmap = true;
return;
#else
throw std::runtime_error("MMAP is not supported on this platform!");
#endif
}

void read_threads(const std::string &file_path, const size_t cache_size, const size_t num_threads)
Expand Down
33 changes: 21 additions & 12 deletions tests/test_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import numpy as np
import torchaudio # reference library
import wave # reference library -- native Python

import fastwave as f

Expand All @@ -15,7 +15,16 @@


def ref_read(file_path):
return torchaudio.info(file_path)
info = {}
with wave.open(file_path, mode="rb") as audio:
# Need to calculate duration by hand:
info["duration"] = audio.getnframes() / audio.getframerate()
info["num_samples"] = audio.getnframes()
info["num_channels"] = audio.getnchannels()
info["sample_rate"] = audio.getframerate()
# wave returns width in bytes, multiply it to get bits:
info["bit_depth"] = audio.getsampwidth() * 8
return info


@pytest.mark.parametrize(
Expand All @@ -25,11 +34,11 @@ def ref_read(file_path):
def test_info_direct(file_name):
ref_info = ref_read(file_name)
audio_info = f.info(file_name)
assert ref_info.num_frames / ref_info.sample_rate == audio_info.duration
assert ref_info.num_frames == audio_info.num_samples
assert ref_info.num_channels == audio_info.num_channels
assert ref_info.sample_rate == audio_info.sample_rate
assert ref_info.bits_per_sample == audio_info.bit_depth
assert ref_info["duration"] == audio_info.duration
assert ref_info["num_samples"] == audio_info.num_samples
assert ref_info["num_channels"] == audio_info.num_channels
assert ref_info["sample_rate"] == audio_info.sample_rate
assert ref_info["bit_depth"] == audio_info.bit_depth


@pytest.mark.parametrize(
Expand All @@ -48,8 +57,8 @@ def test_info_direct(file_name):
def test_info_read(file_name, mode):
ref_info = ref_read(file_name)
audio_info = f.read(file_name, mode=mode).info
assert ref_info.num_frames / ref_info.sample_rate == audio_info.duration
assert ref_info.num_frames == audio_info.num_samples
assert ref_info.num_channels == audio_info.num_channels
assert ref_info.sample_rate == audio_info.sample_rate
assert ref_info.bits_per_sample == audio_info.bit_depth
assert ref_info["duration"] == audio_info.duration
assert ref_info["num_samples"] == audio_info.num_samples
assert ref_info["num_channels"] == audio_info.num_channels
assert ref_info["sample_rate"] == audio_info.sample_rate
assert ref_info["bit_depth"] == audio_info.bit_depth