Git Product home page Git Product logo

pytorch_fftnd's Introduction

fftNd in Pytorch

An n-dimensional implementation of the Fast Fourier Transform and its inverse in Pytorch. The included functions are:

  • fftNd(input, signal_ndim=1, normalized=False)
  • ifftNd(input, signal_ndim=1, normalized=False, signal_sizes=())
  • rfftNd(input, signal_ndim=1, normalized=False, onesided=True)
  • irfftNd(input, signal_ndim=1, normalized=False, onesided=True, signal_sizes=()) These functions are working with all

Functionality

The nD fourier transform is performed by applying n 1D FFTs in a batch matter. This functions use Pytorch named tensors for aranging the dimensions in each 1D FFT.

Examples

The main.py contains a comparison between each fft function against its numpy conterpart. Also a simple nD Fourier convolution is used for evaluation.

Usage

import torch
from fftNd import *

device = "cpu"
# Create input complex tensor
x = torch.rand(1,1,5,5,2) 
# dimensions: [batch, channels, dim1, dim2, ... , dimN, complex] note that the last dimension is shape two, to allocate the real and imaginary parts.

# Test wrappers with 2D
y = rfftNd(x,2)
y = ifftNd(y,2)
y = rfftNd(x[:,:,:,:,0],2)
y = irfftNd(y,2)

# Test 6D fft
nDims = 6
dim_sizes = [1,1]
# each dimension has size 5
dim_sizes.extend(nDims*[5])
# add complex dimension
dim_sizes.extend([2])
# Create complex input tensor
x = torch.rand(*dim_sizes).to(device)

with torch.no_grad():
    # Run proposed implementation
    torch.cuda.synchronize()
    start = time.time()
    y = fftNd(x,nDims)
    torch.cuda.synchronize()
    end = time.time()
    print("time: " + str(end-start))

pytorch_fftnd's People

Contributors

pvjosue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.