Skip to content

Commit 4241b96

Browse files
committed
transforms wip
1 parent cb9e4c6 commit 4241b96

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

src/dsp/fft_comparison.clj

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
;; - **Apache Commons Math** - Mature library with general mathematical transforms
3636
;; - **JDSP** - Digital signal processing library (uses Apache Commons Math internally)
3737
;; - **JTransforms** - First multithreaded, pure-Java FFT library
38-
;; - **fastmath** - Clojure math library (wraps JTransforms with idiomatic API)
38+
;; - **Fastmath** - Clojure math library (wraps JTransforms with idiomatic API)
3939
;;
4040
;; We'll compute the FFT of the same test signal using each library, measure performance, and discuss their trade-offs.
4141

@@ -71,9 +71,9 @@
7171
;; - Supports **1D, 2D, and 3D** transforms (FFT, [DCT](https://en.wikipedia.org/wiki/Discrete_cosine_transform), [DST](https://en.wikipedia.org/wiki/Discrete_sine_transform), [DHT](https://en.wikipedia.org/wiki/Discrete_Hartley_transform))
7272
;; - [In-place mutations](https://en.wikipedia.org/wiki/In-place_algorithm) (efficient but not functional)
7373
;; - Mixed-radix support: works with arbitrary sizes (not just power-of-2)
74-
;; - Used internally by fastmath and dtype-next
74+
;; - Used internally by Fastmath and dtype-next
7575

76-
;; ### fastmath
76+
;; ### Fastmath
7777
;;
7878
;; [fastmath](https://github.com/generateme/fastmath) (version 3.x) by [Tomasz Sulej](https://github.com/genmeblog) is a Clojure library for fast primitive-based mathematics. Its [`fastmath.transform`](https://generateme.github.io/fastmath/fastmath.transform.html) namespace wraps JTransforms with an idiomatic Clojure API.
7979
;;
@@ -247,9 +247,9 @@
247247
"FFT Spectrum (JTransforms)"
248248
"purple")
249249

250-
;; ## FFT Implementation #4: fastmath
250+
;; ## FFT Implementation #4: Fastmath
251251

252-
;; fastmath provides the most Clojure-idiomatic API. Create a transformer, then use `forward-1d`.
252+
;; Fastmath provides the most Clojure-idiomatic API. Create a transformer, then use `forward-1d`.
253253

254254
(defn fft-fastmath
255255
"Compute FFT using fastmath."
@@ -260,7 +260,7 @@
260260
(def fastmath-result
261261
(time (fft-fastmath signal)))
262262

263-
;; Extract magnitudes (fastmath uses JTransforms format internally):
263+
;; Extract magnitudes (Fastmath uses JTransforms format internally):
264264

265265
(defn fastmath-magnitude
266266
"Compute magnitudes from fastmath FFT output."
@@ -278,7 +278,7 @@
278278
; Visualize
279279
(plot-fft-spectrum
280280
fastmath-magnitudes
281-
"FFT Spectrum (fastmath)"
281+
"FFT Spectrum (Fastmath)"
282282
"crimson")
283283

284284
;; ## Performance Comparison
@@ -302,7 +302,7 @@
302302
[lib-name fft-fn] [["Apache Commons Math" fft-apache-commons]
303303
["JDSP" fft-jdsp]
304304
["JTransforms" fft-jtransforms]
305-
["fastmath" fft-fastmath]]]
305+
["Fastmath" fft-fastmath]]]
306306
(let [sig (generate-test-signal size)
307307
result (benchmark-library fft-fn sig)]
308308
(assoc result
@@ -388,7 +388,7 @@
388388
:=y :mean-ms
389389
:=color :size
390390
:=color-type :nominal
391-
:=title "FFT Performance vs Thread Count (fastmath/JTransforms)"
391+
:=title "FFT Performance vs Thread Count (Fastmath/JTransforms)"
392392
:=x-title "Number of Threads"
393393
:=y-title "Mean Time per FFT (ms)"
394394
:=width 800
@@ -433,7 +433,7 @@
433433
;;
434434
;; If you need good performance, focus on:
435435
;; - Using power-of-2 signal sizes (triggers fast SPLIT_RADIX plan)
436-
;; - Choosing an appropriate library (JTransforms/fastmath are typically fastest for 1D, though differences aren't huge)
436+
;; - Choosing an appropriate library (JTransforms/Fastmath are typically fastest for 1D, though differences aren't huge)
437437
;; - Optimizing your overall algorithm to minimize FFT calls
438438

439439
;; **Note:** 2D and 3D FFTs may benefit more from parallelization since they have more work to distribute. We only tested 1D here.
@@ -471,7 +471,7 @@
471471
;;
472472
;; Apache Commons Math **strictly requires** signal length to be a [power of 2](https://en.wikipedia.org/wiki/Power_of_two) (128, 256, 512, 1024, etc.). This is because it only implements the classic [Cooley-Tukey algorithm](https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm).
473473

474-
;; ### JTransforms/fastmath: Flexible (with caveats)
474+
;; ### JTransforms/Fastmath: Flexible (with caveats)
475475
;;
476476
;; Based on our source code investigation (see the threading section above), JTransforms uses **three execution plans**:
477477
;;
@@ -484,7 +484,7 @@
484484
;; - ⚠️ Performance may be slower for non-power-of-2 sizes
485485
;; - ⚠️ MIXED_RADIX is primarily sequential; BLUESTEIN supports limited parallelization
486486
;;
487-
;; **Recommendation:** Use power-of-2 sizes when possible for best performance (triggers SPLIT_RADIX). If your data doesn't fit, zero-pad to the next power of 2, or use JTransforms/fastmath with the understanding that a different plan will be selected.
487+
;; **Recommendation:** Use power-of-2 sizes when possible for best performance (triggers SPLIT_RADIX). If your data doesn't fit, zero-pad to the next power of 2, or use JTransforms/Fastmath with the understanding that a different plan will be selected.
488488

489489
;; ## Related Functionality
490490

@@ -512,7 +512,7 @@
512512
;; - [DHT](https://en.wikipedia.org/wiki/Discrete_Hartley_transform) (Discrete Hartley Transform)
513513
;; - [Multithreaded](https://en.wikipedia.org/wiki/Multithreading_(computer_architecture)) variants for all transforms
514514

515-
;; ### fastmath
515+
;; ### Fastmath
516516
;; - [Protocol-based](https://clojure.org/reference/protocols) transform system
517517
;; - All JTransforms transforms (FFT, DCT, DST, DHT)
518518
;; - [Wavelet transforms](https://en.wikipedia.org/wiki/Wavelet) (Haar, Daubechies, Coiflet, Symlet)
@@ -524,9 +524,9 @@
524524

525525
;; After comparing these libraries, here are my recommendations:
526526

527-
;; **For most Clojure projects: fastmath 3**
527+
;; **For most Clojure projects: Fastmath 3**
528528
;;
529-
;; fastmath provides a good balance of performance and developer experience:
529+
;; Fastmath provides a good balance of performance and developer experience:
530530
;; - Idiomatic Clojure API (functional, immutable)
531531
;; - Leverages JTransforms' performance
532532
;; - Rich ecosystem (transforms, signal processing, statistics)
@@ -546,7 +546,7 @@
546546
;; If you want to use JTransforms directly and don't mind mutation:
547547
;; - Use `DoubleFFT_1D` directly
548548
;; - In-place mutations avoid allocations
549-
;; - May be slightly faster than fastmath wrapper in some cases
549+
;; - May be slightly faster than Fastmath wrapper in some cases
550550
;; - Good for real-time audio processing or when you need fine-grained control
551551

552552
;; **For broader DSP needs: JDSP**
@@ -555,15 +555,15 @@
555555
;; - Convenient, batteries-included library
556556
;; - Simple API
557557
;; - Good documentation
558-
;; - Note: FFT performance is somewhat slower than JTransforms/fastmath
558+
;; - Note: FFT performance is somewhat slower than JTransforms/Fastmath
559559

560560
;; **Apache Commons Math: Consider alternatives**
561561
;;
562562
;; While Commons Math is excellent for general mathematics, for FFT specifically you might prefer other options:
563-
;; - Somewhat slower than JTransforms/fastmath
563+
;; - Somewhat slower than JTransforms/Fastmath
564564
;; - Returns boxed `Complex[]` objects (allocation overhead)
565565
;; - Still a reasonable choice if you're already using Commons Math for other features
566566

567567
;; ## Summary
568568

569-
;; The Clojure ecosystem offers several good FFT options through Java interop. For typical signal processing tasks, **fastmath 3** is a solid choice: JTransforms' performance wrapped in a Clojure-friendly API. For direct control, use **JTransforms directly**. And if you need comprehensive DSP utilities beyond FFT, **JDSP** is worth exploring.
569+
;; The Clojure ecosystem offers several good FFT options through Java interop. For typical signal processing tasks, **Fastmath 3** is a solid choice: JTransforms' performance wrapped in a Clojure-friendly API. For direct control, use **JTransforms directly**. And if you need comprehensive DSP utilities beyond FFT, **JDSP** is worth exploring.

0 commit comments

Comments
 (0)