[Top][All Lists]

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

Re: [Help-gsl] Resizing vectors and matrices

From: ake
Subject: Re: [Help-gsl] Resizing vectors and matrices
Date: Wed, 15 Sep 2004 09:39:42 +0200

At 06:52 PM 9/14/2004, JDL wrote:
You could look at how the C++ standard template library allows you to increase the size of a vector. This uses two numbers: the size is what you use and the capacity is what you have available. You can resize (change the size) whenever you want. If the new size exceeds the capacity, you create new vectors with capacity the first power of two bigger than the new size, copy and reassign.

I have looked briefly at init_source.c in the block and vector directory of gsl-1.5, and it seems to me that all one needs to do is to add functions gsl_vector_realloc and gsl_block_realloc. The latter function should reallocate space for block->data and update block->size. Then gsl_vector_realloc calls gsl_block_realloc and makes appropriate changes if need to vector->data, vector->size and vector->block. That should be all, or have I missed something of importance?

Matrices seem more difficult since element (i,j) of an (m,n) matrix is identified from a vector as matrix->data[i * m + j], ignoring the fact that the physical size may differ from the actual size. Thus, increasing n to n + k is straigtforward, just allocate k * m additional slots at the end of matrix->data, but increasing m is not trivial. It may be that the matrix has to be copied onto a new one of the appropriate size.

Ake Brannstrom

reply via email to

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