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

Replace deprecated NumPy types (np.int and np.float) with int and float #542

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
92 changes: 92 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"

on:
push:
branches: [ "main", "GrillingUXO" ]
pull_request:
branches: [ "main", "GrillingUXO" ]
schedule:
- cron: '27 8 * * 1'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: python
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
21 changes: 13 additions & 8 deletions madmom/evaluation/chords.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
from . import evaluation_io, EvaluationMixin
from ..io import load_chords


CHORD_DTYPE = [('root', int),
('bass', int),
('intervals', int, (12,))]
('intervals', object)]


CHORD_ANN_DTYPE = [('start', float),
('end', float),
('chord', CHORD_DTYPE)]

NO_CHORD = (-1, -1, np.zeros(12, dtype=int))
UNKNOWN_CHORD = (-1, -1, np.ones(12, dtype=int) * -1)

NO_CHORD = (-1, -1, np.zeros(12, dtype=np.int32))
UNKNOWN_CHORD = (-1, -1, np.ones(12, dtype=np.int32) * -1)


def encode(chord_labels):
Expand Down Expand Up @@ -98,7 +101,7 @@ def chords(labels):

def chord(label):
"""
Transform a chord label into the internal numeric representation of
Transform a chord label into the internal numeric represenation of
(root, bass, intervals array) as defined by `CHORD_DTYPE`.

Parameters
Expand Down Expand Up @@ -179,6 +182,8 @@ def modify(base_pitch, modifier):
return base_pitch


import numpy as np

def pitch(pitch_str):
"""
Convert a string representation of a pitch class (consisting of root
Expand Down Expand Up @@ -243,7 +248,7 @@ def interval_list(intervals_str, given_pitch_classes=None):

"""
if given_pitch_classes is None:
given_pitch_classes = np.zeros(12, dtype=int)
given_pitch_classes = np.zeros(12, dtype=np.int32)
for int_def in intervals_str[1:-1].split(','):
int_def = int_def.strip()
if int_def[0] == '*':
Expand Down Expand Up @@ -304,7 +309,7 @@ def chord_intervals(quality_str):
if list_idx != 0:
ivs = _shorthands[quality_str[:list_idx]].copy()
else:
ivs = np.zeros(12, dtype=int)
ivs = np.zeros(12, dtype=np.int32)

return interval_list(quality_str[list_idx:], ivs)

Expand Down Expand Up @@ -345,6 +350,7 @@ def merge_chords(chords):
return crds



def evaluation_pairs(det_chords, ann_chords):
"""
Match detected with annotated chords and create paired label segments
Expand Down Expand Up @@ -590,7 +596,6 @@ def reduce_to_tetrads(chords, keep_bass=False):

return reduced_chords


def select_majmin(chords):
"""
Compute a mask that selects all major, minor, and
Expand Down Expand Up @@ -641,7 +646,7 @@ def adjust(det_chords, ann_chords):

Discard detected chords that start after the annotation ended,
and shorten the last detection to fit the last annotation;
discared detected chords that end before the annotation begins,
discarded detected chords that end before the annotation begins,
and shorten the first detection to match the first annotation.

Parameters
Expand Down
18 changes: 11 additions & 7 deletions madmom/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from __future__ import absolute_import, division, print_function

import contextlib
import io as _io
import contextlib

import numpy as np

Expand Down Expand Up @@ -144,11 +144,15 @@ def load_beats(filename, downbeats=False):
Beats.

"""
values = np.loadtxt(filename, ndmin=2)
if downbeats:
# rows with a "1" in the 2nd column are downbeats
values = values[values[:, 1] == 1]
return values[:, 0]
values = np.loadtxt(filename, ndmin=1)
if values.ndim > 1:
if downbeats:
# rows with a "1" in the 2nd column are downbeats
return values[values[:, 1] == 1][:, 0]
else:
# 1st column is the beat time, the rest is ignored
return values[:, 0]
return values


def write_beats(beats, filename, fmt=None, delimiter='\t', header=None):
Expand Down Expand Up @@ -279,7 +283,7 @@ def write_notes(notes, filename, fmt=None, delimiter='\t', header=None):
fmt = ['%.3f', '%d', '%.3f', '%d']
if not notes.ndim == 2:
raise ValueError('unknown format for `notes`')
# truncate format to the number of columns given
# truncate format to the number of colums given
fmt = delimiter.join(fmt[:notes.shape[1]])
# write the notes
write_events(notes, filename, fmt=fmt, delimiter=delimiter, header=header)
Expand Down