diff --git a/PythonWrapper/build_darwin/create.sh b/PythonWrapper/build_darwin/create.sh index 219c1c2c3..0878dd422 100644 --- a/PythonWrapper/build_darwin/create.sh +++ b/PythonWrapper/build_darwin/create.sh @@ -3,6 +3,7 @@ cmake -DHOST=YES \ -DWRAPPER=YES \ -DCMAKE_POSITION_INDEPENDENT_CODE=YES \ -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ + -DCMAKE_OSX_DEPLOYMENT_TARGET="10.9" \ -DCMSISDSP="path to CMSIS-DSP folder" \ -DCMAKE_C_FLAGS_RELEASE="-std=c11 -Ofast -ffast-math -DNDEBUG -Wall -Wextra" \ -DCMAKE_CXX_FLAGS_RELEASE="-fno-rtti -std=c++11 -Ofast -ffast-math -DNDEBUG -Wall -Wextra -Wno-unused-parameter" \ diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c index 83c7de4eb..61c5d4f28 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c @@ -1908,6 +1908,15 @@ cmsis_arm_mat_cholesky_f32(PyObject *obj, PyObject *args) uint32_t row = src_converted.numRows ; createf32Matrix(&dst_converted,row,column); + float32_t *p=dst_converted.pData; + for(int r=0;r -// API version used on google colab +// Check it is built with right version +// (should be backward compatible down to 1.23.5) // https://github.com/numpy/numpy/blob/main/numpy/_core/include/numpy/numpyconfig.h -#if (NPY_API_VERSION != 0x0000000F ) -//#error("Error building with wrong NumPy API version") +#if (NPY_API_VERSION != NPY_2_0_API_VERSION ) +#error("Error building with wrong NumPy API version") #endif #ifdef WIN diff --git a/PythonWrapper/examples/debug.py b/PythonWrapper/examples/debug.py index 0ab597510..43e6f29c7 100755 --- a/PythonWrapper/examples/debug.py +++ b/PythonWrapper/examples/debug.py @@ -1,15 +1,14 @@ -import cmsisdsp as dsp -import cmsisdsp.fixedpoint as f - +import cmsisdsp as dsp import numpy as np +from numpy.testing import assert_allclose +from scipy.stats import entropy,tstd, tvar +from scipy.special import logsumexp +from scipy.linalg import cholesky,ldl,solve_triangular from scipy import signal -import matplotlib.pyplot as plt -import scipy.fft + import colorama from colorama import init,Fore, Back, Style -from numpy.testing import assert_allclose -import scipy.spatial.distance as d init() @@ -20,61 +19,16 @@ def printSubTitle(s): print("\n" + Style.BRIGHT + s + Style.RESET_ALL) -def packset(a): - b = np.packbits(a) - newSize = int(np.ceil(b.shape[0] / 4.0)) * 4 - c = np.copy(b).astype(np.uint32) - c.resize(newSize) - #print(c) - vecSize = round(newSize/4) - c=c.reshape(vecSize,4) - #print(c) - r = np.zeros(vecSize) - result = [] - for i in range(0,vecSize): - print(c[i,:]) - #print("%X %X %X %X" % (c[i,0],c[i,1],c[i,2],c[i,3])) - d = (c[i,0] << 24) | (c[i,1] << 16) | (c[i,2] << 8) | c[i,3] - result.append(np.uint32(d)) - return(result) - -nb = 34 -#va = np.random.choice([0,1],nb) -# Array of word32 containing all of our bits -#pva = packset(va) - - -#vb = np.random.choice([0,1],nb) -# Array of word32 containing all of our bits -#pvb = packset(vb) -# -va=[1, 0, 1, 0, 1, 1, 1, 0 ,0, 1, 1, 0, 1, 0, 0, 0, 0, 1,0,0,0,1,1,0,1,0,1,0,0,1,1,1,1,1] -vb=[0,1,0,0,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,1,0,0,1,1,0,0,0,1,0] - -va = np.array(va) -vb = np.array(vb) +print("Cholesky") -pva=packset(va) -pvb=packset(vb) - -#pva = [np.uint32(167), np.uint32(0)] -#pvb = [np.uint32(152), np.uint32(0)] - -#print(va,pva) -#print(vb,pvb) - -ctt=1.0*np.count_nonzero((va==1) & (vb==1)) -ctf=1.0*np.count_nonzero((va==1) & (vb==0)) -cft=1.0*np.count_nonzero((va==0) & (vb==1)) - -res=(cft+ctf)/(2*ctt+cft+ctf) +a=np.array([[4,12,-16],[12,37,-43],[-16,-43,98]]) +ref=cholesky(a,lower=True) +print(ref) +status,res=dsp.arm_mat_cholesky_f32(a) print(res) +assert_allclose(ref,res,1e-6,1e-6) - -print("\nDice") -ref=d.dice(va,vb) -res=dsp.arm_dice_distance(pva,pvb,nb) -print(ref) +status,res=dsp.arm_mat_cholesky_f64(a) print(res) -assert_allclose(ref,res,1e-6) +assert_allclose(ref,res,1e-10,1e-10) \ No newline at end of file diff --git a/PythonWrapper/examples/requirements.txt b/PythonWrapper/examples/requirements.txt new file mode 100644 index 000000000..62dd783ac --- /dev/null +++ b/PythonWrapper/examples/requirements.txt @@ -0,0 +1,4 @@ +numpy>=1.23.5 +scipy~=1.13.1 +scikit_learn~=1.5.0 +colorama~=0.4.6 \ No newline at end of file diff --git a/PythonWrapper/examples/runall.sh b/PythonWrapper/examples/runall.sh new file mode 100644 index 000000000..9ce3a3e5c --- /dev/null +++ b/PythonWrapper/examples/runall.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +python testdistance.py +python testdsp6.py +python testdsp5.py +python example_1_10.py +python example_1_6.py +python example_1_9.py + diff --git a/PythonWrapper_README.md b/PythonWrapper_README.md index fe7172150..fe4d2ba20 100644 --- a/PythonWrapper_README.md +++ b/PythonWrapper_README.md @@ -236,6 +236,8 @@ MEL filters are represented as 3 arrays to encode a sparse array. ## Version 1.9.9: * Supports Python 3.12 +* Works with Numpy 2.0 +* Corrections on Cholesky ## Version 1.9.8: * Compute graph API has been removed diff --git a/Source/MatrixFunctions/arm_mat_cholesky_f16.c b/Source/MatrixFunctions/arm_mat_cholesky_f16.c index a56719781..dc2aa1748 100755 --- a/Source/MatrixFunctions/arm_mat_cholesky_f16.c +++ b/Source/MatrixFunctions/arm_mat_cholesky_f16.c @@ -52,6 +52,10 @@ * @par * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition. * The decomposition of A is returning a lower triangular matrix U such that A = L L^t + * + * @par + * The destination matrix should be set to 0 before calling the functions because + * the function may not overwrite all output elements. */ #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) diff --git a/Source/MatrixFunctions/arm_mat_cholesky_f32.c b/Source/MatrixFunctions/arm_mat_cholesky_f32.c index b1d33dd89..e1ad00d17 100755 --- a/Source/MatrixFunctions/arm_mat_cholesky_f32.c +++ b/Source/MatrixFunctions/arm_mat_cholesky_f32.c @@ -60,6 +60,10 @@ * @par * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition. * The decomposition of A is returning a lower triangular matrix L such that A = L L^t + * + * @par + * The destination matrix should be set to 0 before calling the functions because + * the function may not overwrite all output elements. */ #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) diff --git a/Source/MatrixFunctions/arm_mat_cholesky_f64.c b/Source/MatrixFunctions/arm_mat_cholesky_f64.c index fefddcc50..a9d83c2dc 100755 --- a/Source/MatrixFunctions/arm_mat_cholesky_f64.c +++ b/Source/MatrixFunctions/arm_mat_cholesky_f64.c @@ -50,6 +50,10 @@ * @par * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition. * The decomposition of A is returning a lower triangular matrix L such that A = L L^t + * + * @par + * The destination matrix should be set to 0 before calling the functions because + * the function may not overwrite all output elements. */ #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE) && defined(__aarch64__) diff --git a/cmsisdsp/__init__.py b/cmsisdsp/__init__.py index 95f78a84f..a46592993 100755 --- a/cmsisdsp/__init__.py +++ b/cmsisdsp/__init__.py @@ -20,15 +20,15 @@ __version__ = cmsisdsp.version.__version__ # CMSIS-DSP Version used to build the wrapper -cmsis_dsp_version="1.14.4" +cmsis_dsp_version="1.15.0" # CMSIS-DSP Commit hash used to build the wrapper -commit_hash="d760b356172ae04528ba567a51188561ebf72eb0" +commit_hash="04c0b534edf16bd2898ecc66c1c660c27158f286" # True if development version of CMSIS-DSP used # (So several CMSIS-DSP versions may have same version number hence the commit hash) -developmentVersion=False +developmentVersion=True __all__ = ["datatype", "fixedpoint", "mfcc"] diff --git a/pyproject.toml b/pyproject.toml index 777806804..4a8984593 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,7 @@ requires = [ "setuptools>=42", "wheel", - "numpy>=1.22" + "numpy>=2.0.0", ] build-backend = "setuptools.build_meta" + diff --git a/setup.py b/setup.py index aa576848f..6ba4a21cd 100644 --- a/setup.py +++ b/setup.py @@ -188,7 +188,7 @@ def build(): author = 'Copyright (C) 2010-2024 ARM Limited or its affiliates. All rights reserved.', author_email = 'christophe.favergeon@arm.com', url="https://github.com/ARM-software/CMSIS-DSP", - python_requires='>=3.7', + python_requires='>=3.9', license="License :: OSI Approved :: Apache Software License", platforms=['any'], classifiers=[ @@ -205,7 +205,7 @@ def build(): ], keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths','ml','cortex-m','cortex-a'], install_requires=[ - 'numpy>=1.22', + 'numpy>=1.23.5', ], project_urls={ # Optional 'Bug Reports': 'https://github.com/ARM-software/CMSIS-DSP/issues',