Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. # Apply smoothing operator to a, putting result in b.
  2. function relax{T}( b::Vector{T}, a::Vector{T} )
  3. assert(length(a)==length(b))
  4. c = T(0.25)
  5. d = T(0.5)
  6. n = length(b)
  7. b[1] = 1 # Boundary condition
  8. @inbounds for i=2:n-1
  9. b[i] = c*a[i-1]+d*a[i]+c*a[i+1]
  10. end
  11. b[n] = 0 # Boundary condition
  12. end
  13.  
  14. # Apply smoothing operator 1000 times
  15. function flog{T}( b::Vector{T}, a::Vector{T} )
  16. for t=1:500
  17. relax(b,a)
  18. relax(a,b)
  19. end
  20. end
  21.  
  22. # Warmup
  23. flog(rand(Float32,100), rand(Float32,100))
  24.  
  25. # Do some timing trials.
  26. for i=1:12
  27. b = zeros(Float32,1000)
  28. if i%3==0
  29. # Use tiny noise instead of zeros
  30. a = rand(Float32,1000) .* 1E-9
  31. input = "nano-noise"
  32. else
  33. a = zeros(Float32,1000)
  34. input = "zeros"
  35. end
  36. if i%3==2
  37. set_zero_subnormals(true)
  38. rounding = "subnormals are zero"
  39. else
  40. set_zero_subnormals(false)
  41. rounding = "IEEE"
  42. end
  43. a[1] = 1
  44. print(rpad(string(input," with ",rounding),30))
  45. @time flog(b,a)
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement