unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* vector typing
@ 2006-05-04 16:57 Dave Griffiths
  2006-05-05  7:59 ` Andy Wingo
  2006-05-29 19:55 ` Marius Vollmer
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Griffiths @ 2006-05-04 16:57 UTC (permalink / raw)


Hi all,

I'm upgrading an application from the old gh interface (yep, about time
too, it's much nicer) and I've noticed a change in the way vectors are
constructed in the api. I used to use gh_doubles2scm to quickly convert a
block of data into a generalised vector. I've moved over to using
scm_take_f32vector, which is just as fast, but creates vectors which have
to be accessed by (f32vector-ref) etc.

I admit I am confused about the typing of vectors - is there a quick way
to create generalised vectors other than using scm_make_vector and adding
each element individually with scm_vector_set_x?

Speed is an issue, as this is a graphics application
(http://www.pawfal.org/fluxus) and I'm doing a lot of things with vectors.
Are f32 better for speed reasons anyway? Why can't I access them with the
vanilla vector-ref/vector-set! etc?

cheers,

dave



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: vector typing
  2006-05-04 16:57 vector typing Dave Griffiths
@ 2006-05-05  7:59 ` Andy Wingo
  2006-05-05  9:28   ` Dave Griffiths
  2006-05-29 19:55 ` Marius Vollmer
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2006-05-05  7:59 UTC (permalink / raw)


Hi Dave,

On Thu, 2006-05-04 at 17:57 +0100, Dave Griffiths wrote:
> I admit I am confused about the typing of vectors - is there a quick way
> to create generalised vectors other than using scm_make_vector and adding
> each element individually with scm_vector_set_x?

According to the docs, uniform numeric vectors are generalized vectors,
and can be accessed via the americanly-spelled generalized-vector-ref
function. See:
http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Generalized-Vectors.html#Generalized-Vectors

> Speed is an issue, as this is a graphics application
> (http://www.pawfal.org/fluxus) and I'm doing a lot of things with vectors.
> Are f32 better for speed reasons anyway?

1) uniform numeric vectors use less memory (32 bits versus a pointer to
a double-cell (2*sizeof(void*)) on the heap)

2) therefore, from C you don't need to be dereferencing pointers and
checking types in inner loops

3) also, you can get the contiguous array of f32 values, which you can't
do with a normal vector

So yes, for speed a uniform vector is a big win. If you can refactor
algorithms to deal in uniform vectors, with the actual operations
implemented in C, you can approach the speed of a C-only solution I
think.

Cheers,
-- 
Andy Wingo
http://wingolog.org/



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: vector typing
  2006-05-05  7:59 ` Andy Wingo
@ 2006-05-05  9:28   ` Dave Griffiths
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Griffiths @ 2006-05-05  9:28 UTC (permalink / raw)
  Cc: guile-user

> Hi Dave,
>
> On Thu, 2006-05-04 at 17:57 +0100, Dave Griffiths wrote:
>> I admit I am confused about the typing of vectors - is there a quick way
>> to create generalised vectors other than using scm_make_vector and
>> adding
>> each element individually with scm_vector_set_x?
>
> According to the docs, uniform numeric vectors are generalized vectors,
> and can be accessed via the americanly-spelled generalized-vector-ref
> function. See:
> http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Generalized-Vectors.html#Generalized-Vectors
>> Speed is an issue, as this is a graphics application
>> (http://www.pawfal.org/fluxus) and I'm doing a lot of things with
>> vectors.
>> Are f32 better for speed reasons anyway?
>
> 1) uniform numeric vectors use less memory (32 bits versus a pointer to
> a double-cell (2*sizeof(void*)) on the heap)
>
> 2) therefore, from C you don't need to be dereferencing pointers and
> checking types in inner loops
>
> 3) also, you can get the contiguous array of f32 values, which you can't
> do with a normal vector
>
> So yes, for speed a uniform vector is a big win. If you can refactor
> algorithms to deal in uniform vectors, with the actual operations
> implemented in C, you can approach the speed of a C-only solution I
> think.

Thanks Andy, I suppose my main confusion is why you can't use the normal
vector-ref commands with uniform vectors any more.

But yup - I've been using guile for the sort of things you should really
use a gpu for these days (texture coordinate manipulation for reflection
mapping, toon shading etc) in realtime - and it copes surprisingly well.
http://www.pawfal.org/nebogeo/images/fluxref2.png

cheers,

dave



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: vector typing
  2006-05-04 16:57 vector typing Dave Griffiths
  2006-05-05  7:59 ` Andy Wingo
@ 2006-05-29 19:55 ` Marius Vollmer
  1 sibling, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2006-05-29 19:55 UTC (permalink / raw)
  Cc: guile-user

"Dave Griffiths" <dave@pawfal.org> writes:

> Are f32 better for speed reasons anyway?

Depends.  If your inner loops are written in C, then using f32 or f64
vectors should be faster, as fast as C float or double arrays.  If you
use them from Scheme, then every f32vector-ref will have to box the
element (i.e., it has to alloc from the cell heap), which is likely
slower than using a normal vector, since normal vectors store their
elements in boxed form.

> Why can't I access them with the vanilla vector-ref/vector-set! etc?

Good question. :-) One possible answer is: for the same reason that
you can't access strings with vector-ref, and vectors not with
list-ref.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2006-05-29 19:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-04 16:57 vector typing Dave Griffiths
2006-05-05  7:59 ` Andy Wingo
2006-05-05  9:28   ` Dave Griffiths
2006-05-29 19:55 ` Marius Vollmer

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).