chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Returning f32vectors in C for Chicken's FFI


From: Pierre-Alexandre Fournier
Subject: [Chicken-users] Returning f32vectors in C for Chicken's FFI
Date: Sun, 02 Jan 2005 03:05:17 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031030

Hi,

I'm new to Chicken and its FFI. I'm trying to make a C function return a f32vector when called in Scheme. A f32vector is translated in float* when passed to C. I would like to know how to cast this float* in f32vector.

For example:

C code (test_ffi3.h):
--------------
___declare(prefix, "mylib:")

float * f32add(float * v1, float * v2, int len)
{
  int i;
  float * v3;
  v3 = (float *) malloc (sizeof(float) * len);

  for (i=0; i<len; i++){
    v3[i] = v1[i] + v2[i];
    printf("%d:%f\n",i,v3[i]); //debugging.
  }
  return v3;
}
--------------

Scheme code:
--------------
(require-extension srfi-4)

#>!
#include "test-ffi3.h"
<#

(define va (f32vector 1.1 2.2 3.3 4.4 5.5 6.6))
(define vb (f32vector 2 2 2 2 2 2))
(define vc (mylib:f32add va vb (f32vector-length va)))
(display vc)
(newline)
--------------

Currently (display vc) prints something like:
#<pointer 9445f38>
and I would to have a #f32(...) instead. Is there any documentation on that subject?

I read that functions in blas.egg mutates vectors and doesn't need to return the f32vector (and therefore avoid that problem). I don't want to do that because I would like to keep a functional style when I write my algorithms.


Thanks for helping,

Pierre-Alexandre







reply via email to

[Prev in Thread] Current Thread [Next in Thread]