<jupyter_start><jupyter_text>Building BlocksFFT code is made up of small DFT building blocks.<jupyter_code>import pyJvsip as pv
from math import pi
def dftCoefE(n):
     m=pv.create('cmview_d',n,n)
     for i in range(n):
         for j in range(n):
             t=(i*j)%n
             x=2.0*pi/n * float(t)
             m[i,j]=complex(cos(x),-sin(x))
     return m
def dftLut(t,n):
    lut=pv.create(t,n)
    w=2.0 * pi / n
    lut.realview.ramp(0,w)
    pv.sin(lut.realview,lut.imagview)
    lut.imagview.neg
    lut.realview.cos
    return lut
def dftBB0(x):
    n=x.length
    if x.type in ['cvview_d','vview_d']:
        t = 'cvview_d'
    elif x.type in ['cvview_f','vview_f']:
        t = 'cvview_f'
    else:
        exit
    y=pv.create(t,x.length).fill(0.0)
    lut=dftLut(t,n)
    for i in range(n):
        for j in range(x.length):
            thta=(i*j) % n
            y[i] += x[j] * lut[thta]
    return y
def dftBB1(x):
    n=x.length
    if x.type in ['cvview_d','vview_d']:
        t = 'cvview_d'
    elif x.type in ['cvview_f','vview_f']:
        t = 'cvview_f'
    else:
        exit
    y=pv.create(t,x.length).fill(0.0)
    lut=dftLut(t,n)
    for i in range(n):
        t=0.0
        for j in range(x.length):
            thta=(i*j) % n
            t+= x[j] * lut[thta]
        y[i]=t
    return y
def dftBB2(x):
    n=x.length
    if x.type in ['cvview_d','vview_d']:
        t = 'cvview_d'
    elif x.type in ['cvview_f','vview_f']:
        t = 'cvview_f'
    else:
        exit
    y=pv.create(t,x.length).fill(0.0)
    lut=dftLut(t,n)
    for j in range(n):
        t=x[j]
        for i in range(x.length):
            thta=(i*j) % n
            y[i] += t * lut[thta]
    return y
z=pv.create('cvview_d',100).randn(5)
z.mprint("%4.3f")
%%timeit
Z=z.fftop
Z = z.fftop
Z.mprint("%5.4f")
zc = z.copy
zc.fftip
(Z-zc).normFro
%%timeit
Zbb=dftBB0(z)
print('%.5e'%(Z-Zbb).normFro)
%%timeit
Zbb=dftBB1(z)
print('%.5e'%(Z-Zbb).normFro)
%%timeit
Zbb=dftBB2(z)
print('%.5e'%(Z-Zbb).normFro)<jupyter_output>0.00000e+00
0.00000e+00
0.00000e+00
0.00000e+00
1 loop, best of 3: 586 ms per loop
{'fraction_non_alphanumeric': 0.17672209026128266, 'fraction_numerical': 0.031828978622327794, 'mean_word_length': 2.2449922958397535, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '273260', 'license': 'MIT', 'n_tokens_mistral': 1002, 'n_tokens_neox': 967, 'n_words': 184, 'path': 'python/python_examples/fftDev/dftBB_NB.ipynb', 'repo_name': 'rrjudd/jvsip', 'size': '2105'}