Skip to content

Commit

Permalink
add fft2d + test (ruslo#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
headupinclouds authored and ruslo committed Nov 10, 2017
1 parent 38a255d commit 0759ff2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ hunter_config(drm VERSION 2.4.67)
hunter_config(eigen3-nnls VERSION 1.0.1)
hunter_config(eos VERSION 0.12.1)
hunter_config(FakeIt VERSION 2.0.3)
hunter_config(fft2d VERSION 1.0.0-p0)
hunter_config(farmhash VERSION 1.1)
hunter_config(fixesproto VERSION 5.0)
hunter_config(flatbuffers VERSION 1.3.0-p3)
Expand Down
26 changes: 26 additions & 0 deletions cmake/projects/fft2d/hunter.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2016-2017, Ruslan Baratov
# Copyright (c) 2017, David Hirvonen
# All rights reserved.

# !!! DO NOT PLACE HEADER GUARDS HERE !!!

include(hunter_add_version)
include(hunter_cacheable)
include(hunter_cmake_args)
include(hunter_download)
include(hunter_pick_scheme)

hunter_add_version(
PACKAGE_NAME
fft2d
VERSION
1.0.0-p0
URL
"https://github.com/hunter-packages/fft2d/archive/v1.0.0-p0.tar.gz"
SHA1
080f5415229653fe032e981e4ce65a05a6967bbe
)

hunter_pick_scheme(DEFAULT url_sha1_cmake)
hunter_cacheable(fft2d)
hunter_download(PACKAGE_NAME fft2d)
17 changes: 17 additions & 0 deletions examples/fft2d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016-2017, Ruslan Baratov
# Copyright (c) 2017, David Hirvonen
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-fft2d)

hunter_add_package(fft2d)
find_package(fft2d CONFIG REQUIRED)

add_executable(foo foo.cpp)
target_link_libraries(foo fft2d::fft2d)
59 changes: 59 additions & 0 deletions examples/fft2d/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Source : fft2d/sample1/testxg.c (open license)
//
// Reproduce samples for valid link test, since no headers are exported.
//
// This is used as a build test only.

#include <math.h>
#include <stdio.h>
#define MAX(x,y) ((x) > (y) ? (x) : (y))

/* random number generator, 0 <= RND < 1 */
#define RND(p) ((*(p) = (*(p) * 7141 + 54773) % 259200) * (1.0 / 259200.0))

#ifndef NMAX
#define NMAX 8192
#define NMAXSQRT 64
#endif

extern "C" {
void cdft(int, int, double *, int *, double *);
void putdata(int nini, int nend, double *a)
{
int j, seed = 0;

for (j = nini; j <= nend; j++) {
a[j] = RND(&seed);
}
}
double errorcheck(int nini, int nend, double scale, double *a)
{
int j, seed = 0;
double err = 0, e;

for (j = nini; j <= nend; j++) {
e = RND(&seed) - a[j] * scale;
err = MAX(err, fabs(e));
}
return err;
}

} // extern "C"

int main()
{
int n = 64, ip[NMAXSQRT + 2];
double a[NMAX + 1], w[NMAX * 5 / 4], t[NMAX / 2 + 1], err;

printf("data length n=? (must be 2^m)\n");
//scanf("%d", &n);
ip[0] = 0;

/* check of CDFT */

putdata(0, n - 1, a);
cdft(n, 1, a, ip, w);
cdft(n, -1, a, ip, w);
return errorcheck(0, n - 1, 2.0 / n, a);
}

0 comments on commit 0759ff2

Please sign in to comment.