Hello Racketeers,
going through some more possible optimizations of my side projects, I
encountered a different behavior of unsafe-flvector-set! between BC and
CS implementations:
==== CUT HERE ====
#lang racket
(require racket/unsafe/ops
racket/flonum)
(define flv (make-flvector 10))
(for ((i (in-range 10)))
(unsafe-flvector-set! flv i i))
(for ((i (in-range 10)))
(display (~a #:width 4 (unsafe-flvector-ref flv i))))
(newline)
==== CUT HERE ====
$ racket test-flvector.rkt
SIGSEGV MAPERR si_code 1 fault on addr 0x9
Aborted (core dumped)
$ racketcs test-flvector.rkt
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
$
The SIGSEGV is expected behavior (although might not get triggered every
time). The latter looks like implicit fx->fl operation.
Changing to safe flvector-set! results in expected contract violation
with both variants:
$ racketcs test-flvector.rkt
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
$ racket test-flvector.rkt
flvector-set!: contract violation
expected: flonum?
given: 0
argument position: 3rd
other arguments...:
(flvector 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0)
0
context...:
"/home/joe/Projects/Programming/TD4/test-flvector.rkt": [running body]
temp35_0
for-loop
run-module-instance!
perform-require!
$ racketcs test-flvector.rkt
flvector-set!: contract violation
expected: flonum?
given: 0
context...:
/home/joe/Projects/Programming/racket-lang/racket/racket/collects/racket/private/for.rkt:1534:9
body of "/home/joe/Projects/Programming/TD4/test-flvector.rkt"
$
I assume that CS' unsafe-flvector-set! is actually pretty safe when it
comes to flonum-convertible numbers. It might be a bit faster because it
lacks the contract, but definitely it is not a "low level" variant.
Also given the fact that unsafe-fl+ and others give no performance
advantage (the opposite is true for well-written algorithms), maybe the
performance guide and unsafe ops documentation should get an update
before CS becomes the default implementation.
Any thoughts?
Cheers,
Dominik
--
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/c39293d0-51fa-41d8-3e0e-1fd99bca59ae%40trustica.cz.