diff --git a/gnu/local.mk b/gnu/local.mk index 34726b8b1b8..42146d8ec46 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1699,6 +1699,7 @@ dist_patch_DATA = \ %D%/packages/patches/kinit-kdeinit-extra_libs.patch \ %D%/packages/patches/kio-search-smbd-on-PATH.patch \ %D%/packages/patches/kismet-unbundle-boost.patch \ + %D%/packages/patches/kissfft-tflite-micro.patch \ %D%/packages/patches/kitty-fix-wayland-protocols.patch \ %D%/packages/patches/kmod-module-directory.patch \ %D%/packages/patches/kmscon-runtime-keymap-switch.patch \ diff --git a/gnu/packages/algebra.scm b/gnu/packages/algebra.scm index fc412ad5eab..2a2d840b9cc 100644 --- a/gnu/packages/algebra.scm +++ b/gnu/packages/algebra.scm @@ -21,6 +21,7 @@ ;;; Copyright © 2025 Nigko Yerden ;;; Copyright © 2025 Skylar Hill ;;; Copyright © 2025 Janneke Nieuwenhuizen +;;; Copyright © 2025 Andy Tai ;;; ;;; This file is part of GNU Guix. ;;; @@ -60,6 +61,7 @@ #:use-module (gnu packages image) #:use-module (gnu packages java) #:use-module (gnu packages libffi) + #:use-module (gnu packages linux) #:use-module (gnu packages maths) #:use-module (gnu packages mpi) #:use-module (gnu packages multiprecision) @@ -808,6 +810,80 @@ a C program.") principle, 'Keep It Simple, Stupid.'") (license license:bsd-3))) +(define-public kissfft-for-tflite-micro + (package + (inherit kissfft) + (name "kissfft-for-tflite-micro") + (version "130") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/mborgerding/kissfft") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + "137h3pkn6jmc3pcgnqsq481f6jjblx7ygw9gyipgcdysmnhrwiv2") + (patches (search-patches "kissfft-tflite-micro.patch")))) + (build-system gnu-build-system) + (arguments + (list + #:phases + #~(modify-phases %standard-phases + (delete 'configure) + (delete 'build) + (replace 'install + (lambda _ + (for-each (lambda (f) + (install-file f + (string-append #$output "/include"))) + '("kiss_fft.h" "kissfft.hh")) + (for-each (lambda (f) + (install-file f + (string-append #$output + "/include/tools"))) + (find-files "tools")))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (invoke "make" "CC=gcc" "testall"))))))) + (native-inputs (list procps)) + (inputs (list fftw)))) + +(define-public clac + (package + (name "clac") + (version "0.3.4") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/soveran/clac") + (commit version))) + (file-name (git-file-name name version)) + (sha256 + "0crpm5rxxipiz6kqs5ip900d77vvnslyjn5f6nj0lrc86bkbgi8d"))) + (build-system gnu-build-system) + (arguments + (list + #:test-target "test" + #:phases + #~(modify-phases %standard-phases + (delete 'configure) + (add-before 'build 'set-env + (lambda _ + (setenv "CC" "gcc") + (setenv "PREFIX" #$output)))))) + (home-page "https://github.com/soveran/clac") + (synopsis "Command-line, stack-based calculator with postfix notation") + (description + "Clac is a command line, stack-based calculator with postfix notation +that displays the stack contents at all times. As you type, the stack +changes are reflected immediately.") + ;; Bundles two dependencies, both also BSD-2. SDS is not yet packaged. + ;; linenoise is packaged, but the package doesn't provide shared + ;; object files so we have to build it anyway. + (license license:bsd-2))) (define-public fftw (package (name "fftw") @@ -2215,38 +2291,3 @@ systems. This encompasses: @item the computation of the dimension and the degree of the solution set. @end itemize") (license license:gpl2+))) - -(define-public clac - (package - (name "clac") - (version "0.3.4") - (source - (origin - (method git-fetch) - (uri (git-reference - (url "https://github.com/soveran/clac") - (commit version))) - (file-name (git-file-name name version)) - (sha256 - "0crpm5rxxipiz6kqs5ip900d77vvnslyjn5f6nj0lrc86bkbgi8d"))) - (build-system gnu-build-system) - (arguments - (list - #:test-target "test" - #:phases - #~(modify-phases %standard-phases - (delete 'configure) - (add-before 'build 'set-env - (lambda _ - (setenv "CC" "gcc") - (setenv "PREFIX" #$output)))))) - (home-page "https://github.com/soveran/clac") - (synopsis "Command-line, stack-based calculator with postfix notation") - (description - "Clac is a command line, stack-based calculator with postfix notation -that displays the stack contents at all times. As you type, the stack -changes are reflected immediately.") - ;; Bundles two dependencies, both also BSD-2. SDS is not yet packaged. - ;; linenoise is packaged, but the package doesn't provide shared - ;; object files so we have to build it anyway. - (license license:bsd-2))) diff --git a/gnu/packages/patches/kissfft-tflite-micro.patch b/gnu/packages/patches/kissfft-tflite-micro.patch new file mode 100644 index 00000000000..4dfdfeb9358 --- /dev/null +++ b/gnu/packages/patches/kissfft-tflite-micro.patch @@ -0,0 +1,229 @@ +diff --git a/Makefile b/Makefile +index 96f43d3..d8e9be2 100644 +--- a/Makefile ++++ b/Makefile +@@ -8,11 +8,11 @@ doc: + + testall: + # The simd and int32_t types may or may not work on your machine +- make -C test DATATYPE=simd CFLAGADD="$(CFLAGADD)" test +- make -C test DATATYPE=int32_t CFLAGADD="$(CFLAGADD)" test +- make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test +- make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test +- make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test ++ #make -C test DATATYPE=simd CFLAGADD="$(CFLAGADD)" test ++ #make -C test DATATYPE=int32_t CFLAGADD="$(CFLAGADD)" test ++ #make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test ++ #make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test ++ #make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test + echo "all tests passed" + + tarball: clean +diff --git a/_kiss_fft_guts.h b/_kiss_fft_guts.h +index ba66144..1a0f4c2 100644 +--- a/_kiss_fft_guts.h ++++ b/_kiss_fft_guts.h +@@ -1,3 +1,6 @@ ++#ifndef _KISS_FFT_GUTS_H ++#define _KISS_FFT_GUTS_H ++ + /* + Copyright (c) 2003-2010, Mark Borgerding + +@@ -135,7 +138,7 @@ struct kiss_fft_state{ + #else + # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) + # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) +-# define HALF_OF(x) ((x)*.5) ++# define HALF_OF(x) ((x)*(kiss_fft_scalar).5) + #endif + + #define kf_cexp(x,phase) \ +@@ -162,3 +165,4 @@ struct kiss_fft_state{ + #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) + #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) + #endif ++#endif // _KISS_FFT_GUTS_H +diff --git a/kiss_fft.c b/kiss_fft.c +index 465d6c9..9133a01 100644 +--- a/kiss_fft.c ++++ b/kiss_fft.c +@@ -375,7 +375,7 @@ void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout, + //It just performs an out-of-place FFT into a temp buffer + kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft); + kf_work(tmpbuf,fin,1,in_stride, st->factors,st); +- memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); ++ /* memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft); */ + KISS_FFT_TMP_FREE(tmpbuf); + }else{ + kf_work( fout, fin, 1,in_stride, st->factors,st ); +diff --git a/kiss_fft.h b/kiss_fft.h +index 64c50f4..24e4d0c 100644 +--- a/kiss_fft.h ++++ b/kiss_fft.h +@@ -7,7 +7,7 @@ + #include + + #ifdef __cplusplus +-extern "C" { ++extern "C++" { + #endif + + /* +@@ -29,13 +29,13 @@ extern "C" { + #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) + #define KISS_FFT_FREE _mm_free + #else +-#define KISS_FFT_MALLOC malloc +-#define KISS_FFT_FREE free ++#define KISS_FFT_MALLOC(X) (void*)(0x0) /* Patched. */ ++#define KISS_FFT_FREE(X) /* Patched. */ + #endif + + + #ifdef FIXED_POINT +-#include ++#include /* Patched. */ + # if (FIXED_POINT == 32) + # define kiss_fft_scalar int32_t + # else +diff --git a/test/Makefile b/test/Makefile +index c204511..d2fe0ea 100644 +--- a/test/Makefile ++++ b/test/Makefile +@@ -3,7 +3,7 @@ WARNINGS=-W -Wall -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return \ + -Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wbad-function-cast \ + -Wwrite-strings + +-CFLAGS=-O3 -I.. -I../tools $(WARNINGS) ++CFLAGS=-O3 -I.. -I../tools $(WARNINGS) -ggdb -O0 + CFLAGS+=-ffast-math -fomit-frame-pointer + #CFLAGS+=-funroll-loops + #CFLAGS+=-march=prescott +diff --git a/test/testkiss.py b/test/testkiss.py +index af75065..cae8494 100755 +--- a/test/testkiss.py ++++ b/test/testkiss.py +@@ -5,7 +5,7 @@ import sys + import os + import random + import struct +-import popen2 ++import subprocess + import getopt + import numpy + +@@ -35,11 +35,11 @@ elif datatype=='float': + else: + sys.stderr.write('unrecognized datatype %s\n' % datatype) + sys.exit(1) +- ++ + + def dopack(x,cpx=1): + x = numpy.reshape( x, ( numpy.size(x),) ) +- ++ + if cpx: + s = ''.join( [ struct.pack(fmt*2,c.real,c.imag) for c in x ] ) + else: +@@ -89,7 +89,7 @@ def test_fft(ndims): + xver = numpy.fft.rfftn(x) + else: + xver = numpy.fft.fftn(x) +- ++ + open('/tmp/fftexp.dat','w').write(dopack( flatten(xver) , True ) ) + + x2=dofft(x,doreal) +@@ -99,14 +99,14 @@ def test_fft(ndims): + errpow = numpy.vdot(errf,errf)+1e-10 + sigpow = numpy.vdot(xverf,xverf)+1e-10 + snr = 10*math.log10(abs(sigpow/errpow) ) +- print 'SNR (compared to NumPy) : %.1fdB' % float(snr) ++ print( 'SNR (compared to NumPy) : %.1fdB' % float(snr)) + + if snr>= 1; +@@ -71,8 +71,8 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr + kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; + + if ( st->substate->inverse) { +- fprintf(stderr,"kiss fft usage error: improper alloc\n"); +- exit(1); ++ /* fprintf(stderr,"kiss fft usage error: improper alloc\n"); */ ++ return; /* exit(1); */ + } + + ncfft = st->substate->nfft; +@@ -126,8 +126,8 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *t + int k, ncfft; + + if (st->substate->inverse == 0) { +- fprintf (stderr, "kiss fft usage error: improper alloc\n"); +- exit (1); ++ /* fprintf (stderr, "kiss fft usage error: improper alloc\n"); */ ++ return; /* exit (1); */ + } + + ncfft = st->substate->nfft; +diff --git a/tools/kiss_fftr.h b/tools/kiss_fftr.h +index 72e5a57..b888a28 100644 +--- a/tools/kiss_fftr.h ++++ b/tools/kiss_fftr.h +@@ -3,7 +3,7 @@ + + #include "kiss_fft.h" + #ifdef __cplusplus +-extern "C" { ++extern "C++" { + #endif + +