@@ -3,25 +3,52 @@ import TensorCrossInterpolation as TCI
33import QuanticsGrids as QG
44import Random
55
6+ """
7+ function index_to_quantics!(digitlist, index::Integer; base::Integer=2)
8+
9+ * `digitlist` base-b representation (1d vector)
10+ * `base` base for quantics (default: 2)
11+ """
12+ function index_to_quantics! (digitlist, index:: Integer ; base:: Integer = 2 )
13+ numdigits = length (digitlist)
14+ for i = 1 : numdigits
15+ digitlist[i] = mod (index - 1 , base^ (numdigits - i + 1 )) ÷ base^ (numdigits - i) + 1
16+ end
17+ return digitlist
18+ end
19+
20+ """
21+ index_to_quantics(index::Integer; numdigits=8, base::Integer=2)
22+
23+ Does the same as [`index_to_quantics!`](@ref) but returns a new vector.
24+ """
25+ function index_to_quantics (index:: Integer ; numdigits= 8 , base:: Integer = 2 )
26+ digitlist = Vector {Int} (undef, numdigits)
27+ return index_to_quantics! (digitlist, index; base= base)
28+ end
29+
30+ # @testset "Quantics Fourier Transform, R=$R" for R in [4, 16, 62]
631@testset " Quantics Fourier Transform, R=$R " for R in [4 , 16 , 62 ]
732 Random. seed! (23593243 )
833
34+ grid = QG. DiscretizedGrid {1} (R, 0 , 1 )
35+
936 r = 12
1037 coeffs = randn (ComplexF64, r)
1138 fm (x) = sum (coeffs .* cispi .(2 * (0 : r- 1 ) * x))
12- fq (q) = fm (( QG. quantics_to_index_fused ( q)[1 ] - 1 ) / 2 ^ big (R) )
39+ fq (q) = fm (QG. quantics_to_origcoord (grid, q)[1 ])
1340
1441 qtci, = TCI. crossinterpolate2 (ComplexF64, fq, fill (2 , R); tolerance= 1e-14 )
1542 fouriertt = QTCI. quanticsfouriermpo (R; normalize= false ) / 2 ^ big (R)
1643 qtcif = TCI. contract (fouriertt, qtci)
1744
1845 for i in 1 : min (r, 2 ^ big (R))
19- q = QG . index_to_quantics (i, numdigits= R)
46+ q = index_to_quantics (i, numdigits= R)
2047 @test qtcif (reverse (q)) ≈ coeffs[i]
2148 end
2249
2350 for i in Int .(round .(range (r+ 2 , 2 ^ big (R); length= 100 )))
24- q = QG . index_to_quantics (i, numdigits= R)
51+ q = index_to_quantics (i, numdigits= R)
2552 @test abs (qtcif (reverse (q))) < 1e-12
2653 end
2754end
0 commit comments