cbkiyanda / cspl

Common Scientific Programming Library
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Data structures? #9

Open balarsen opened 10 years ago

balarsen commented 10 years ago

All, it occurs to me that lots of data that we might want to play with falls into one of a few categories.

Do we want to make structures that one puts data into and then have the routines we write operate on the structure? One could make routines to operate on the structures as well, for example with a t,x,y,z a return_x function could then operate on a part of the data.

One concrete example we currently have, CSPL_Stats_mean(double inval, long n) which would be then CSPL_Stats_mean(cspl_1d_struct inval)

Thoughts?

balarsen commented 10 years ago

A couple of examples of the kind of thing: https://github.com/drsteve/LANLGeoMag/blob/master/libLanlGeoMag/Lgm/Lgm_DynamicMemory.h https://github.com/drsteve/LANLGeoMag/blob/master/libLanlGeoMag/Lgm/Lgm_LstarInfo.h

cbkiyanda commented 9 years ago

Seems to me what's missing is a bunch of basic object types: vectors and arrays (maybe dates) etc. In a sense, this is what boost is about at the core? We could provide bindings to fortran types and leverage that, though I guess that means we'd have to write a bunch of fortran routines. I agree that creating such classes is necessary. I'm just afrait we're reinventing the wheel.

balarsen commented 9 years ago

Charles, boost is of no use here, it is all C++ and highly templated therefore almost impossible to make a good shared library out of. If we are trying to be C and general than to be the best of my knowledge nothing exists outside of GSL (and CSPL). If we can make use of FORTRAN in a useful and gcc way I don't have an issue there but am totally ignorant on such things. If it can do all teh array stuff we want to do then we should try it, I am skeptical that it will actaully work to C in a really easy fashon.

However if F does all the array stuff we want to do already then a C Init funciton to a CSPLA (array type in CSPL?) that is handles in F then useful in C routines that would be good. I have no concept on the possibility of this.

If you make a simple prototype in some brach then I can play with how to use it in C. I can imaging a F class called CSPLA that has to1D_C_pointer(), to2D_C()_pointer, ... method calls to make it useable around the rest of the C.

nicolasbock commented 9 years ago

Charles, let's summarize what Fortran brings to the table in terms of vector types. Here are the things that I can think of off of the top of my head:

  1. Bounds checking
  2. User defined lower and upper index values
  3. Slices

Is there something I forgot? All of those are very straight forward to implement in C. The GSL for instance does this through very thin wrappers around a struct, and allows the user to strip away the stuff that slows it down if error checking is not wanted. I would prefer is we could leave the library in one language.

balarsen commented 9 years ago

Here is one cut at an array type: f6276c9d296514462948479b85b77bd40354ff9c. In the CSPLA branch.

One thing that makes a wrapper hard to create is that the variable[][] notiation can only be used if you know the last size. Otheriwise pointer math... we will need a function to pass in [i][j][k] and get out a number. This owuld work just fine but would likely be slow.