[racket] Optimization; converting 'Float' to 'Fixnum' in Typed Racket

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sat Feb 18 21:18:15 EST 2012

I'm not sure of the precise answer, but I don't think that all floats
(even the integers) have a corresponding fixnum. You could probably
turn it into an integer and then use fixnum? to determine if it is a
fixnum (signalling an error otherwise) and then inside the true branch
of a test, you might find that you're all set.

Meanwhile, I'm really replying because it sounds like your doing
timing tests inside DrRacket. You should probably run your timing
tests from the command-line, and use racket directly. DrRacket is
doing lots of stuff behind the scenes that can mess up timing tests.

Robby

On Sat, Feb 18, 2012 at 8:07 PM, SF <sf.rom17 at gmail.com> wrote:
> I'm trying to optimize some code that processes a bunch of data,
> basically image pixels, which currently takes on the order of several
> seconds and seems like it should be much faster (important because
> it's an interactive application). Coming from C++ I have a good idea
> in my mind of how I'd write it with low-level operations. I read up on
> Racket optimization. It is still somewhat unclear to me how Racket
> deals with fixnums, flonums, unsafe operations, Typed Racket types,
> and how it all fits together. I chose to optimize my program (partly
> to learn how) incrementally, trying all the options, timing at every
> step with debugging info turned off. This worked until I wanted to
> convert Integers to Fixnums in Typed Racket (which has been giving me
> much faster results than anything in untyped Racket).
>
> The problem is that I can't find a way to convert a Float to a Fixnum,
> only to an Integer. None of fl->fx, unsafe-fl->fx, or
> fl->exact-integer work, as Type Checker tells me they're untyped
> identifiers. Strangely, it doesn't complain with other things from
> racket/unsafe/ops and racket/fixnum. Ideally, it'd be nice to have a
> function that works like a cast in C++, rounding down the float to get
> an int efficiently. Should I not be trying to use Fixnums? Are they
> just as efficient as Integers? Using a C module is one possible
> solution, are there any others? Would love some light shed on this
> topic.
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


Posted on the users mailing list.