Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Aug 12, 2023
1 parent aeba934 commit 6e75e12
Show file tree
Hide file tree
Showing 103 changed files with 6,775 additions and 1,221 deletions.
2 changes: 1 addition & 1 deletion accelerate/fft/futhark.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require {
github.com/diku-dk/complex 0.1.4 #01620a944f6c9522163364f5a2ce97e3829ce734
github.com/diku-dk/complex 0.2.0 #19c5afb0931c4cfe4d8f2e9540ba01edd9460639
github.com/athas/matte 0.1.3 #ec4243a5f64cb818a4289dbc4953460ea19da12c
github.com/diku-dk/fft 0.2.1 #2190ef56cd45293e35180c594b8fed8767573a94
}
43 changes: 43 additions & 0 deletions accelerate/fft/lib/github.com/diku-dk/complex/complex.fut
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module type complex = {
type real
-- | The type of complex numbers.
type complex
-- | Helper type for easy compatiblity with other modules.
type t = complex

-- | Construct a complex number from real and imaginary components.
val mk: real -> real -> complex
Expand All @@ -20,9 +22,14 @@ module type complex = {
-- | Construct a complex number from just the imaginary component. The
-- real part will be zero.
val mk_im: real -> complex
-- | Construct a complex number from i64. The
-- imaginary part will be zero.
val i64: i64 -> complex

-- | Conjugate a complex number.
val conj: complex -> complex
-- | Negate a complex number.
val neg: complex -> complex
-- | The real part of a complex number.
val re: complex -> real
-- | The imaginary part of a complex number.
Expand All @@ -37,10 +44,21 @@ module type complex = {
val -: complex -> complex -> complex
val *: complex -> complex -> complex
val /: complex -> complex -> complex
val **: complex -> complex -> complex

val <: complex -> complex -> bool
val >: complex -> complex -> bool
val >=: complex -> complex -> bool
val <=: complex -> complex -> bool

val sqrt: complex -> complex
val exp: complex -> complex
val log: complex -> complex
val abs: complex -> complex

val fma: complex -> complex -> complex -> complex

val sum [n]: [n]complex -> complex
}

-- | Given a module describing a number type, construct a module
Expand All @@ -49,12 +67,15 @@ module mk_complex(T: real): (complex with real = T.t
with complex = (T.t, T.t)) = {
type real = T.t
type complex = (T.t, T.t)
type t = complex

def mk (a: real) (b: real) = (a,b)
def mk_re (a: real) = (a, T.i32 0)
def mk_im (b: real) = (T.i32 0, b)
def i64 (a: i64) = mk_re (T.i64 a)

def conj ((a,b): complex) = T.((a, i32 0 - b))
def neg ((a,b): complex) = T.((i32 0 - a, i32 0 - b))
def re ((a,_b): complex) = a
def im ((_a,b): complex) = b

Expand Down Expand Up @@ -83,4 +104,26 @@ module mk_complex(T: real): (complex with real = T.t

def log (z: complex) =
mk (T.log (mag z)) (arg z)

def abs (a: complex) =
mk_re (mag a)

def (a: complex) < (b: complex) = (re (abs a)) T.< (re (abs b))
def (a: complex) > (b: complex) = (re (abs a)) T.> (re (abs b))
def (a: complex) >= (b: complex) = !(a < b)
def (a: complex) <= (b: complex) = !(a > b)

def fma ((a,b): complex) ((c,d): complex) ((e,f): complex) =
let r = T.fma a c e T.- b T.* d
let i = T.(fma a d (fma c b f))
in mk r i

def ((a,b): complex) ** ((c,d): complex) =
let x = T.(a * a + b * b)
let y = T.(x ** (c / i32 2) * e ** (i32 0 - d * arg (a,b)))
let z = T.(c * arg (a,b) + d / i32 2 * log x)
in T.((y * cos z, y * sin z))

def sum (a: []complex) =
reduce (+) T.((i32 0, i32 0)) a
}
108 changes: 108 additions & 0 deletions accelerate/fft/lib/github.com/diku-dk/complex/complex_tests.fut
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,111 @@ entry test_log (a: f32) (b: f32) =
entry test_conj (a: f32) (b: f32) =
let x = c32.conj (c32.mk a b)
in (c32.re x, c32.im x)

-- ==
-- entry: test_neg
-- input { 2f32 3f32 }
-- output { -2f32 -3f32 }
entry test_neg(a: f32) (b: f32) =
let x = c32.neg (c32.mk a b)
in (c32.re x, c32.im x)

-- ==
-- entry: test_abs
-- input { 2f32 3f32 }
-- output { 3.605551275463989f32 0f32 }
-- input { 3f32 -4f32 }
-- output { 5f32 0f32 }
entry test_abs (a: f32) (b: f32) =
let x = c32.abs (c32.mk a b)
in (c32.re x, c32.im x)

-- ==
-- entry: test_lt
-- input { 3f32 2f32 1f32 4f32}
-- output { true }
-- input { 3f32 3f32 1f32 4f32}
-- output { false }
entry test_lt (a: f32) (b: f32) (c: f32) (d: f32) =
let x = c32.mk a b
let y = c32.mk c d
in x c32.< y

-- ==
-- entry: test_gt
-- input { 3f32 2f32 1f32 4f32}
-- output { false }
-- input { 3f32 3f32 1f32 4f32}
-- output { true }
entry test_gt (a: f32) (b: f32) (c: f32) (d: f32) =
let x = c32.mk a b
let y = c32.mk c d
in x c32.> y

-- ==
-- entry: test_leq
-- input { 2f32 4f32 5f32 4f32}
-- output { true }
-- input { 3f32 4f32 3f32 4f32}
-- output { true }
-- input { 3f32 3f32 1f32 4f32}
-- output { false }
entry test_leq (a: f32) (b: f32) (c: f32) (d: f32) =
let x = c32.mk a b
let y = c32.mk c d
in x c32.<= y

-- ==
-- entry: test_geq
-- input { 3f32 2f32 1f32 4f32}
-- output { false }
-- input { 3f32 3f32 3f32 3f32}
-- output { true }
-- input { 5f32 3f32 3f32 3f32}
-- output { true }
entry test_geq (a: f32) (b: f32) (c: f32) (d: f32) =
let x = c32.mk a b
let y = c32.mk c d
in x c32.>= y

-- ==
-- entry: test_pow
-- input { 2f32 1f32 2f32 1f32}
-- output { -0.5048246889783189f32 3.1041440769955293f32 }
-- input { 3f32 4f32 2f32 3f32}
-- output { 1.4260094753925756f32 0.6024346301905391f32 }
entry test_pow (a: f32) (b: f32) (c: f32) (d: f32) =
let x = c32.mk a b
let y = c32.mk c d
let z = x c32.** y
in (c32.re z, c32.im z)

-- ==
-- entry: test_fma
-- input { 2f32 2f32 3f32 1f32 2f32 1f32 }
-- output { 6f32 9f32 }
-- input { 3f32 4f32 5f32 3f32 5f32 3f32 }
-- output { 8f32 32f32 }
entry test_fma (a: f32) (b: f32) (c: f32) (d: f32) (e: f32) (f: f32) =
let x = c32.mk a b
let y = c32.mk c d
let z = c32.mk e f
let q = c32.fma x y z
in (c32.re q, c32.im q)

-- ==
-- entry: test_sum
-- input { [1f32, 2f32] [1f32, 2f32] }
-- output { 3f32 3f32 }
entry test_sum (a: []f32) (b: []f32) =
let x = map2 c32.mk a b
let y = c32.sum x
in (c32.re y, c32.im y)

-- ==
-- entry: test_i64
-- input { 5i64 }
-- output { 5f32 0f32 }
entry test_i64 (a: i64) =
let x = c32.i64 a
in (c32.re x, c32.im x)
4 changes: 2 additions & 2 deletions accelerate/julia/futhark.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require {
github.com/diku-dk/complex 0.1.4 #01620a944f6c9522163364f5a2ce97e3829ce734
github.com/diku-dk/complex 0.2.0 #19c5afb0931c4cfe4d8f2e9540ba01edd9460639
github.com/athas/matte 0.1.3 #ec4243a5f64cb818a4289dbc4953460ea19da12c
github.com/diku-dk/lys 0.1.16 #f59d97c25005f04a1b518e092707e1e54e593715
github.com/diku-dk/lys 0.1.20 #c67c64659893ee9657845d00c5be8bdb6ed495ff
}
43 changes: 43 additions & 0 deletions accelerate/julia/lib/github.com/diku-dk/complex/complex.fut
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module type complex = {
type real
-- | The type of complex numbers.
type complex
-- | Helper type for easy compatiblity with other modules.
type t = complex

-- | Construct a complex number from real and imaginary components.
val mk: real -> real -> complex
Expand All @@ -20,9 +22,14 @@ module type complex = {
-- | Construct a complex number from just the imaginary component. The
-- real part will be zero.
val mk_im: real -> complex
-- | Construct a complex number from i64. The
-- imaginary part will be zero.
val i64: i64 -> complex

-- | Conjugate a complex number.
val conj: complex -> complex
-- | Negate a complex number.
val neg: complex -> complex
-- | The real part of a complex number.
val re: complex -> real
-- | The imaginary part of a complex number.
Expand All @@ -37,10 +44,21 @@ module type complex = {
val -: complex -> complex -> complex
val *: complex -> complex -> complex
val /: complex -> complex -> complex
val **: complex -> complex -> complex

val <: complex -> complex -> bool
val >: complex -> complex -> bool
val >=: complex -> complex -> bool
val <=: complex -> complex -> bool

val sqrt: complex -> complex
val exp: complex -> complex
val log: complex -> complex
val abs: complex -> complex

val fma: complex -> complex -> complex -> complex

val sum [n]: [n]complex -> complex
}

-- | Given a module describing a number type, construct a module
Expand All @@ -49,12 +67,15 @@ module mk_complex(T: real): (complex with real = T.t
with complex = (T.t, T.t)) = {
type real = T.t
type complex = (T.t, T.t)
type t = complex

def mk (a: real) (b: real) = (a,b)
def mk_re (a: real) = (a, T.i32 0)
def mk_im (b: real) = (T.i32 0, b)
def i64 (a: i64) = mk_re (T.i64 a)

def conj ((a,b): complex) = T.((a, i32 0 - b))
def neg ((a,b): complex) = T.((i32 0 - a, i32 0 - b))
def re ((a,_b): complex) = a
def im ((_a,b): complex) = b

Expand Down Expand Up @@ -83,4 +104,26 @@ module mk_complex(T: real): (complex with real = T.t

def log (z: complex) =
mk (T.log (mag z)) (arg z)

def abs (a: complex) =
mk_re (mag a)

def (a: complex) < (b: complex) = (re (abs a)) T.< (re (abs b))
def (a: complex) > (b: complex) = (re (abs a)) T.> (re (abs b))
def (a: complex) >= (b: complex) = !(a < b)
def (a: complex) <= (b: complex) = !(a > b)

def fma ((a,b): complex) ((c,d): complex) ((e,f): complex) =
let r = T.fma a c e T.- b T.* d
let i = T.(fma a d (fma c b f))
in mk r i

def ((a,b): complex) ** ((c,d): complex) =
let x = T.(a * a + b * b)
let y = T.(x ** (c / i32 2) * e ** (i32 0 - d * arg (a,b)))
let z = T.(c * arg (a,b) + d / i32 2 * log x)
in T.((y * cos z, y * sin z))

def sum (a: []complex) =
reduce (+) T.((i32 0, i32 0)) a
}
Loading

0 comments on commit 6e75e12

Please sign in to comment.