This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: Reading and writing GSL random number generators
Dear All,
I know that if I don't implement things into the GSL myself, I shouldn't
open my mouth <grin>, but nevertheless, eventually, I would like for
that feature to be added (the gsl_*_snprintf) functions. I've had to
write several ad-hoc routines to write small vectors to libxml nodes,
that I could probably have written very easily, if there was a snprintf
function for writing vectors, matrices, and rng states (as I was
suggesting to Olaf).
One might argue that starting to print to strings can open a whole issue
of memory leaks, but that is why I was suggesting a snprintf approach.
There could be a two-tier approach for writing to a string:
With some prototypes like
size_t gsl_vector_get_string_size(gsl_vector *v, char * format);
and
gsl_vector_snprintf (char *string, gsl_vector *v, size_t size, char *
format);
So one could do something like:
static char * format my_format = "%.10f";
size_t string_size;
string_size = gsl_vector_get_string_size(vector,my_format);
//allocate your string here...
gsl_vector_snprintf(my_string,
vector,
string_size,
my_format);
What is wrong with this? Would this bloat the library too much?
Alan
On Mon, 2003-06-02 at 02:24, Brian Gough wrote:
> Olaf Lenz writes:
> > On Thu, May 29, 2003 at 08:11:38AM -0700, Alan Aspuru-Guzik wrote:
> > > Now that you are at it, wouldn't a gsl_rng_snprintf be useful? In my
> > > case, I am using XML as I/O, and therefore, I would need to write to
> > > a string, and then write the string itself to an XML node.
> >
> > I think the idea is good and I suppose that I will add it. Probably it
> > would be useful to add an snprinft-function for all GSL data
> > structures, like histograms, vectors, and matrices.
>
> I would prefer that GSL only write to files -- the user can create an
> in-memory file with fmemopen().