unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
[parent not found: <mailman.197.1365782461.8676.guile-devel@gnu.org>]
[parent not found: <mailman.1287634.1365761713.854.guile-devel@gnu.org>]
* vectors are something else
@ 2013-04-10 23:07 Daniel Llorens
  2013-04-11  7:29 ` Daniel Llorens
  2013-04-11 23:53 ` Daniel Hartwig
  0 siblings, 2 replies; 26+ messages in thread
From: Daniel Llorens @ 2013-04-10 23:07 UTC (permalink / raw)
  To: guile-devel


After the array-map patches, I've gone through the vector/array implementation and there's some stuff I'd like to fix. In stable-2.0 today:

(define a (make-typed-array ''f64 0 '(1 2))
a
=> #1f64@1(0.0 0.0)

so far so good.

(uniform-vector? a)
=> #t

(f64vector-ref? a)
=> #t

so far so good.

(uniform-vector-ref a 0)
=> 0.0

This is a bug, since the valid indices are 1 and 2. This bug is in scm_c_generalized_vector_ref (and elsewhere):

pos = h.base + h.dims[0].lbnd + idx * h.dims[0].inc

this should be (to fix the bug: it shouldn't be written like this, but let's leave that aside for now)

pos = h.base + (idx - h.dims[0].lnbd) * h.dims[0].inc

Cf.

(vector-ref #@1(1 2 3 4) 1)
=> 2 (wrong)

but

(array-ref #@1(1 2 3 4) 1)
=> 1 (right)

I have patches for the above; however, the problems go well beyond.

(bitvector? (make-typed-array 'b #t 2))) => #t
(bitvector? (make-typed-array 'b #t '(1 2))) => #f
(bitvector-ref (make-typed-array 'b #t '(1 2))) => type error (consistent with #f)

(bytevector? (make-typed-array 's8 0 2))) => #t
(bytevector? (make-typed-array 's8 0 '(1 2))) => #f
(bytevector-ref (make-typed-array 's8 0 '(1 2))) => type error (consistent with #f)

(s8vector? (make-typed-array 's8 0 2))) => #t
(s8vector? (make-typed-array 's8 0 '(1 2))) => #t
(s8vector-ref (make-typed-array 's8 0 '(1 2))) => type error (inconsistent with #t)

(uniform-vector? (make-typed-array 's8 0 2))) => #t
(uniform-vector? (make-typed-array 's8 0 '(1 2))) => #t
(uniform-vector-ref (make-typed-array 's8 0 '(1 2))) => 0 (consistent with #t, but wrong)

(vector? (make-typed-array #t 0 2))) => #t
(vector? (make-typed-array #t 0 '(1 2))) => #f
(vector-ref (make-typed-array #t 0 '(1 2)) 0) => 0 (inconsistent with #f *and* wrong)

This is what I would like to do:

Force, and assume, inc and base to be 1 & 0 for uniform-vector / [srfi4type]vector / vector. That is, make all of the above behave as bitvector and bytevector. The advantanges are

a. the array implementation can rely on all these types having known base=0 and inc=1.
b. consistency.

Some programs may break, but they can't have relied on the behavior above without being broken already. Nobody has reported these bugs for a long time and the tests don't see them, I say we're good to go. 

Thoughts?

	Daniel

--

PS Some other, clearly worse, options:

1. Fix the bug above in uniform-vector-ref, etc. by having all the uniform-vector functions be aliases for array-ref. For consistency, do the same for bitvector- and bytevector- and srfi4vector- . Then all those functions pay the abstraction cost of using array- (which is not so much the rank as the type). It's also a fair amount of work. For example, the printer for uniform vectors depends on the first valid index being 0, so just fixing the buggy line above breaks the printer. The documentation does say that uniform-vectors are indexed from 0...

2. Fix the bug above in uniform-vector-ref, etc. by allowing inc!=1 and base!=0 for non-array objects. This will push some of the array functionality into bitvector, bytevector, etc (where inc=1 and base=0 are hardcoded) and generally complicate the code. Ditto for fixes required in other places.

3. Do 0, 1, or 2 differently for each of the vector types, e.g. Having srfi4vector- and uniform-vector- behave like bytevector-, but vector- behave like array-. Besides not making much sense, it would complicate the implementation of arrays (by which I mean, it wouldn't allow simplification that is sorely needed).










^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-04-20 14:00 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1288755.1365813667.854.guile-devel@gnu.org>
2013-04-15 11:29 ` vectors are something else Daniel Llorens
2013-04-15 12:28   ` Daniel Hartwig
2013-04-15 14:08     ` Daniel Llorens
2013-04-15 14:17       ` Daniel Hartwig
2013-04-15 14:10     ` vector types poll Daniel Llorens
2013-04-15 22:47       ` Daniel Hartwig
2013-04-16  0:16         ` Daniel Llorens
2013-04-16  2:00   ` vectors are something else Mark H Weaver
2013-04-16  4:10     ` Daniel Llorens
2013-04-16  6:19       ` Mark H Weaver
2013-04-16  8:31         ` Daniel Llorens
2013-04-17 15:29     ` Mutable top-level bindings (was: vectors are something else) Chris K. Jester-Young
2013-04-17 17:53       ` Mutable top-level bindings Mark H Weaver
2013-04-17 20:25       ` Ian Price
2013-04-20 14:00       ` Ludovic Courtès
     [not found] <mailman.197.1365782461.8676.guile-devel@gnu.org>
2013-04-12 23:12 ` vectors are something else Daniel Llorens
     [not found] <mailman.1287634.1365761713.854.guile-devel@gnu.org>
2013-04-12 12:37 ` Daniel Llorens
2013-04-12 14:06   ` Daniel Hartwig
2013-04-13  0:40   ` Daniel Llorens
2013-04-10 23:07 Daniel Llorens
2013-04-11  7:29 ` Daniel Llorens
2013-04-11 23:53 ` Daniel Hartwig
2013-04-12  7:23   ` Daniel Llorens
2013-04-12 10:15     ` Daniel Hartwig
2013-04-12 10:41       ` Daniel Hartwig
2013-04-12 21:43       ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).