<div dir="ltr"><div><div><div><div><div>Thanks for the advice! It's certainly been an interesting journey into Typed Racket... :) <br><br>Here are the results thus far (for a 256x256 perlin, simplex, and colored-simplex image).<br>
</div><br></div><div>Original:<br><span style="font-family:courier new,monospace"> cpu time: 1139 real time: 1134 gc time: 232<br> cpu time: 780 real time: 773 gc time: 124<br> cpu time: 1950 real time: 2044 gc time: 328</span><br>
</div><div><br></div>Typed:<br><span style="font-family:courier new,monospace"> cpu time: 640 real time: 653 gc time: 110<br> cpu time: 546 real time: 542 gc time: 62<br> cpu time: 1342 real time: 1364 gc time: 218</span><br>
<br></div>So it's definitely a good start. <br><br></div>Unfortunately, there are a few oddities that I'm not sure how to deal with.<br><br></div><b>1) </b>Which is more idiomatic / easier for Typed Racket to deal with:<br>
<br><span style="font-family:courier new,monospace">(: mix (Flonum Flonum Flonum -> Flonum))<br>(define (mix a b t)<br> ...)</span><br><span style="font-family:courier new,monospace"><br>(define: (mix [a : Flonum] [b : Flonum] [t : Flonum]) : Flonum<br>
</span><div><span style="font-family:courier new,monospace"> ...)</span><br><br></div><div>Right now, I'm using the former, but I'm not sure I'm happy with it.<br><br></div><div><b>2)</b> How can I deal with integer values (specifically 0) to a function with flonum types?<br>
<br></div><div>Specifically, perlin (and simplex) have the type:\<br><br><span style="font-family:courier new,monospace">(: perlin<br> (case-> (Flonum -> Flonum)<br> (Flonum Flonum -> Flonum)<br> (Flonum Flonum Flonum -> Flonum)))</span><br>
<br></div><div>But if I try to do something like this:<br><br></div><div><span style="font-family:courier new,monospace">(perlin (* 1.0 (/ 0 256)))</span><br><br>I get this error:<br><span style="font-family:courier new,monospace"><br>
Type Checker: No function domains matched in function application:<br>Domains: Flonum Flonum Flonum<br> Flonum Flonum<br> Flonum<br>Arguments: Zero</span><br><br></div><div>Basically, <span style="font-family:courier new,monospace">(* 1.0 (/ 0 256))<span style="font-family:arial,helvetica,sans-serif"> is</span></span><span style="font-family:courier new,monospace"><span style="font-family:arial,helvetica,sans-serif"> </span>0</span>, not <span style="font-family:courier new,monospace">0.0</span>. For the timing tests above, I worked around this with <span style="font-family:courier new,monospace">real->double-flonum</span> but that seems suboptimal (they types are leaking). Is there something I'm missing there?<br>
<br></div><div><b>3)</b> How do I type a color% / bitmap%?<br><br></div><div>I tried typing noisy-image-test.rkt, but I kept running into this. I can use Any, but it seems like objects should be typeable. No luck finding out how though.<br>
</div><div><br>I'll keep hacking at it, but that's what I have for the moment.<br><br>JP<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 11, 2013 at 3:54 PM, Vincent St-Amour <span dir="ltr"><<a href="mailto:stamourv@ccs.neu.edu" target="_blank">stamourv@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">At Thu, 11 Apr 2013 13:07:27 -0400,<br>
JP Verkamp wrote:<br>
><br>
> [1 <multipart/alternative (7bit)>]<br>
> [1.1 <text/plain; UTF-8 (7bit)>]<br>
<div><div class="h5">> Partially out of curiosity and partially in my ongoing quest to try out<br>
> game development in Racket, I've implemented a pure Racket version each for<br>
> Perlin and simplex noise. It's pretty much a direct translation of the code<br>
> from this PDF, originally in C:<br>
> <a href="http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf" target="_blank">http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf</a><br>
><br>
> Here is a blog post with some pretty pictures but little actual code:<br>
> <a href="http://blog.jverkamp.com/2013/04/11/perlin-and-simplex-noise-in-racket/" target="_blank">http://blog.jverkamp.com/2013/04/11/perlin-and-simplex-noise-in-racket/</a><br>
><br>
> Here's just the code:<br>
> <a href="https://github.com/jpverkamp/noise" target="_blank">https://github.com/jpverkamp/noise</a><br>
><br>
> It's definitely not pure / functional, but I think it's relatively easy to<br>
> read (or as easy as noise functions can be).<br>
><br>
> What I'm wondering though is if someone with a bit more experience in<br>
> optimizing Racket code could take a look at it. I know that it should be<br>
> possible to get a bit more speed; it's almost all number crunching, mostly<br>
> floating point math but with a few integer only bits (those are causing the<br>
> most trouble...). At the moment, I can think of at least three routes for<br>
> optimization although I'm probably missing something:<br>
><br>
> - using (racket/floum) -- I've tried just blindly replacing * + - / with<br>
> fl* fl+ fl- fl/ (and fixing the numerous errors that crop up), but it<br>
> doesn't seem to result in much of a speedup at all. I think that this is a<br>
> combination of still requiring runtime checks on the values and having to<br>
> convert between exact/inexact, but I'm not sure.<br>
><br>
> - using Typed Racket -- Theoretically this will allow the compiler to<br>
> choose the correct functions as above and avoid having to do any runtime<br>
> checks at all, although I'm not sure how much of that has been implemented.<br>
<br>
</div></div>I had a quick look at your code, and I think Typed Racket should be able<br>
to help. The TR optimizer can specialize numeric operations, which<br>
removes runtime checks and allows the Racket compiler to unbox<br>
intermediate results.<br>
<br>
To get the most of the TR optimizer, you can try the Optimization Coach<br>
DrRacket plugin. It reports the specializations that TR is doing and<br>
points out specialization opportunities that would require code/type<br>
changes to be safe.<br>
<span class="HOEnZb"><font color="#888888"><br>
Vincent<br>
</font></span></blockquote></div><br></div>