This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: package tensor


  Hi Jordi, all,

> Looks very nice, and also it seems that using varargs didn't create you 
> trouble to wrap it?! My main concern about varargs was their potentially 
> hard-to-wrap nature. In any case, I guess it would be possible to still use 
> that nice sintax in Ruby if indices were passed as (uint*) instead of 
> varargs in gsl_tensor, right?

  Right. I use code in Ruby/GSL like

size_t
FUNCTION(gsl_tensor, position2)(gsl_vector_uint *v, const 
GSL_TYPE(gsl_tensor) * t)
{
  size_t shift, position;
  unsigned int i;
  shift = t->size/t->dimension;  /* == quick_pow(t->dimension, t->rank 
- 1) */
  position = 0;
  for (i = 0; i < v->size; i++) {
      unsigned int index_i = gsl_vector_uint_get(v, i);
      if (gsl_check_range) if (index_i >= t->dimension) return t->size;
      position += shift * index_i;
      shift /= t->dimension;
  }
  return position;
}
  I have not changed gsl_tensor package itself, but added just 
three functions, gsl_tensor_position2(), get2() and set2(), 
to handle indices via gsl_vector_uint. For each function call, 
gsl_vector_uint is created from Ruby arguments (this is 
somewhat inefficient...). 
  The class GSL::Tensor wraps the struct gsl_tensor, but now 
I am considering to use an "upper" struct, like
  struct rbgsl_tensor {
    gsl_tensor *t;
    gsl_vector_uint *indices;
  };
and to create gsl_tensor and a vector for indices simultaneously
by the constructor GSL::Tensor.alloc(), to prevent from 
allocating/freeing vectors in every call. 

  How do you plan in future development? C varargs would bring some 
troubles, but it is far easy to use in writing C code (not for 
wrappers) as gsl_tensor_get(t, i, j, k, ...), than to give a vector 
storing indices as   
    v->data[0] = i; v->data[1] = j; v->data[2] = k;, .....
    gsl_tensor_get(t, v);
I guess that's why you use varargs, and I prefer to it than uint*.

  Regards,
  Yoshiki


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]