Den lør. 15. feb. 2020 kl. 13.44 skrev greadey <[email protected]>:
> I have written a programme to compute a bootstrapped mean etc. I
> successfully wrote it using lists both untyped and in typed/racket.
> I am interested in optimising the code and having seen that typed racket
> performs faster (for lists) I am interested in seeing if I get a
> performance increase using vectors in both typed and untyped code.
> In order to compute the median value as well as certain percentiles it is
> necessary to sort the samples. My specific problem is using vector-sort.
> I have got round it by using vector->list and list->vector functions and
> using the list sort function.
> If I use vector-sort typed racket keeps telling me to use
> "require/typed". I got a function definition to compile (:sort-myvector :
> (Vectorof Flonum) (Flonum Flonum -> Boolean) -> (Vectorof Flonum))
> I'm not sure if that is exactly right but it was something similar,
> however it did not work. I did add a "require/typed racket/vector" to the
> expression.
> So, how can I use vector-sort in typed racket code, and can anyone tell me
> if translating vectors to lists and back again actually introduces a
> performance hit?
>
Here is an example of how to use `vector-sort` from a typed/racket program:
#lang typed/racket
(require/typed racket/vector
[vector-sort (-> (Vectorof Any) (-> Any Any Boolean) (Vectorof Any))])
(define (compare x y)
(if (and (real? x) (real? y))
(< x y)
(error 'compare "expected two real numbers, got: ~a ~a" x y)))
(vector-sort (vector 3 1 5 2) compare)
/Jens Axel
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CABefVgzOSTZJs%2BaZADFxe8oPJ%2BNx4ihvjHjJ19BcqhF2oKkayQ%40mail.gmail.com.