aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-30 10:49:59 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-30 10:49:59 +0200
commitbd672e1f7aefc66e95c4e4a27388a99248358d8c (patch)
tree684c420c319486be9b0bf05344fbe87dd357b330
parent3b1767a3f4fd2f0ff2b03d7daa9307fce115b5ea (diff)
aberth: Compile with latest futhark
-rw-r--r--aberth/aberth_kernel.fut14
-rw-r--r--aberth/futhark.pkg2
-rw-r--r--aberth/kernel.cpp1
-rw-r--r--aberth/polygen.cpp1
4 files changed, 11 insertions, 7 deletions
diff --git a/aberth/aberth_kernel.fut b/aberth/aberth_kernel.fut
index fd4d943..5d851f0 100644
--- a/aberth/aberth_kernel.fut
+++ b/aberth/aberth_kernel.fut
@@ -29,7 +29,8 @@ let evaln_d (p: poly) (nterms: i32) (pt: f32): f32 =
let eval_d (p: poly) (pt: f32): f32 = evaln_d p (length p) pt
let derivative (p: poly): *poly =
- map (\(i, v) -> f32.i32 i * v) (zip (1..<PolyN) (tail p)) ++ [0]
+ let res = map (\(i, v) -> f32.i32 i * v) (tail (zip (0..<PolyN) p)) ++ [0]
+ in res :> poly
-- Cauchy's bound: https://en.wikipedia.org/wiki/Geometrical_properties_of_polynomial_roots#Lagrange's_and_Cauchy's_bounds
let max_root_norm (p: poly): f32 =
@@ -44,14 +45,14 @@ module aberth = {
let gen_coord (r: f32) (rng: *rand_engine.rng): *(rand_engine.rng, f32) =
uniform_real.rand (-r, r) rng
- let gen_coord_c (r: f32) (rng: rand_engine.rng): (rand_engine.rng, complex) =
+ let gen_coord_c (r: f32) (rng: *rand_engine.rng): (rand_engine.rng, complex) =
let (rng, x) = gen_coord r rng
let (rng, y) = gen_coord r rng
in (rng, cplx.mk x y)
let generate (ctx: context) (rng: *rand_engine.rng): *(rand_engine.rng, approx) =
let rngs = rand_engine.split_rng N rng
- let (rngs, approx) = unzip (map (gen_coord_c ctx.radius) rngs)
+ let (rngs, approx) = unzip (map (\rng -> gen_coord_c ctx.radius (copy rng)) rngs)
let rng = rand_engine.join_rng rngs
in (rng, approx)
@@ -107,7 +108,8 @@ module aberth = {
-- Set the constant coefficient to 1; nextDerbyshire will never change it
let init_derbyshire: poly =
- [1] ++ replicate (PolyN - 1) (-1)
+ let res = [1] ++ replicate (PolyN - 1) (-1)
+ in res :> poly
let next_derbyshire (p: *poly): *(bool, poly) =
let (_, p, looped) =
@@ -152,14 +154,14 @@ entry main_job
let indices = flatten
(map (\idx ->
let p = derbyshire_at_index idx
- let (_, pts) = aberth.aberth p rng
+ let (_, pts) = aberth.aberth p (copy rng)
in map (point_index width height bottom_left top_right) pts)
(start_index ..< start_index + num_polys))
let filtered = filter (\i -> i != -1) indices
in reduce_by_index (replicate (width * height) 0)
(+) 0
filtered
- (replicate (length filtered) 1)
+ (map (const 1) filtered)
entry main_all
(width: i32) (height: i32)
diff --git a/aberth/futhark.pkg b/aberth/futhark.pkg
index 963e457..c136912 100644
--- a/aberth/futhark.pkg
+++ b/aberth/futhark.pkg
@@ -1,4 +1,4 @@
require {
github.com/diku-dk/complex 0.1.2 #790bf261a6a36a9454b55f3f8109ac5cb1f4bf6e
- github.com/diku-dk/cpprandom 1.1.4 #7dd47f3f2f5a8fa24d6847b34d9f8a9091b5d94a
+ github.com/diku-dk/cpprandom 1.2.1 #869304710af3a023683d6670316d55dafd973c71
}
diff --git a/aberth/kernel.cpp b/aberth/kernel.cpp
index 36c3102..92d2d20 100644
--- a/aberth/kernel.cpp
+++ b/aberth/kernel.cpp
@@ -1,4 +1,5 @@
#include <iostream>
+#include <cassert>
#include "kernel.h"
extern "C" {
diff --git a/aberth/polygen.cpp b/aberth/polygen.cpp
index e606dc8..d846e90 100644
--- a/aberth/polygen.cpp
+++ b/aberth/polygen.cpp
@@ -1,3 +1,4 @@
+#include <cassert>
#include "polygen.h"
#include "util.h"