Search code examples
carraysstructgsl

Using GSL lib functions on data in a struct C


Many GSl functions take arguments as doubles or arrays of doubles. However much of my data is nested in arrays of structs instead. Say like arrays of:

struct A
{
  double a;
  int b;
};

I could write a wrapper that copies the data into an array of pure doubles or ints. But I was interested in something more elegant to get around this.


Solution

  • Not the answer you want. But since you cant change the GSL interface, if you are looking for performance, I think your best solution is probably to chose data structures that matches the job from the start. So maybe something like a struct containing arrays of doubles.

    If both the GSL interface and your original data structure is out of your control, then your only option is probably going to be the wrapper that you are thinking about.

    If the library functions that you are using could take a 'stride' argument, you could possibly look into structure packing and padding. (But that still wouldn't convert your ints to doubles.)