Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ARRAY-2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PAUGET Baptiste
ARRAY-2023
Commits
f790db37
Commit
f790db37
authored
2 years ago
by
Baptiste Pauget
Browse files
Options
Downloads
Patches
Plain Diff
Some examples
parent
dd8bdbe0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ex/fft.surf
+0
-84
0 additions, 84 deletions
ex/fft.surf
ex/test-polymorphism.surf
+0
-27
0 additions, 27 deletions
ex/test-polymorphism.surf
with
0 additions
and
111 deletions
ex/fft.surf
deleted
100644 → 0
+
0
−
84
View file @
dd8bdbe0
/*-------- Fast Fourier transform --------*/
// Language: Surface
// Checking: ../compiler.exe Surf fft.surf
let vec_vec u v = $fold (+) 0 ($map2 (*) u v)
let mat_vec A u = $map (vec_vec u) A
let mat_mat A B = $map (mat_vec A) ($transpose B)
// Extract smaller divisor of n
let div n = 1 /*
let rec f k =
if k * k < n then 1 else
if n % k = 0 then k else
f (k+1)
in f (2)
**/
// Dummy exponential and pure imaginary unity
let exp x = 1+x*(1+x/2*(1+x/3*(1+0)))
let i = 1
let pi = 3
let rec fft <<n>> (x:[n]_) : [n]_ =
// Twiddle factors
let tw [j,k] = exp (2*i*pi*j*k/n) in
// One step of decomposition
let dft <<n,p>> =
|> $split
|> $map fft <<n>>
|> $transpose |> $map2 ($map2 (*)) tw
|> $map fft <<p>>
|> $flatten
in
// Recusive call
let size d = div n in
let size k = n / d in
if d = 1 then mat_vec tw x else
(dft <<d,k>> (x:>[k*d]_) :> [n]_)
let rec fft <<n>> : [n]_ -> [n]_ =
// Twiddle factors
let tw [j,k] = exp (2*i*pi*j*k/n) in
let size d = div n in
let size k = n / d in
if d = 1 then mat_vec tw else
:> [k*d]_
|> $split
|> $map fft <<d>>
|> $transpose |> $map2 ($map2 (*)) tw
|> $map fft <<k>>
|> $flatten
:> [n]_
// Twiddle factors
let tw n [j,k] = exp (2*i*pi*j*k/n)
let rec fft <<n>> : [n]_ -> [n]_ =
let size d = div n in
let size k = n / d in
if d = 1 then mat_vec (tw n) else
:> [k*d]_
|> $split
|> $map fft <<d>>
|> $transpose |> $map2 ($map2 (*)) (tw n)
|> $map fft <<k>>
|> $flatten
:> [n]_
let repeat <<n>> c [_<n] = c
let repeat2 <<n,p>> =
|> repeat <<n>>
|> repeat <<p>>
This diff is collapsed.
Click to expand it.
ex/test-polymorphism.surf
deleted
100644 → 0
+
0
−
27
View file @
dd8bdbe0
/*-------- Examples on type variables generalization --------*/
// Language: Surface
// Checking: ../compiler.exe Surf test-polymorphism.surf
let ign _ _ = false
// Generalization of quoted type vars (top-decl)
let f x = let g : 'a = fun x -> x in g (x) // SUCC
let f = let g (x:'a) = x in ign (g 0) (g 42 ) // SUCC
let f = let g (x:'a) = x in ign (g 0) (g true) // FAIL
let f = let g (x: _) = x in ign (g 0) (g true) // SUCC
let f x = let g (x:'a) = x in ign (g x) (g x) // SUCC
let f = let g (x:'a) (y:'b) = x=y in g true false // SUCC
let f: type a. a -> _ = fun x -> let g (x:'a) = x in ign (g x) (g true) // FAIL
let f: bool -> _ = fun x -> let g (x:'a) = x in ign (g x) (g true) // SUCC
let f: type a. a -> _ = fun x -> let g (x: _) = x in ign (g x) (g true) // SUCC
let z = let i x = x in i i 0 // SUCC
let z = let i x = (x:'a) in i i 0 // FAIL
// Type var escaping
let f (x:'c) : 'd = x // SUCC
let f (type c d) (x:c) : d = x // FAIL
let f (type a) (x:a) y = x = y // SUCC
let f x = let g: type a. a -> _ = fun y -> x = y in g (x) // FAIL
let f: type a. a -> _ = fun x y -> x = y // FAIL
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment