blitzpp / blitz

Blitz++ Multi-Dimensional Array Library for C++
https://github.com/blitzpp/blitz/wiki
Other
404 stars 83 forks source link

Add option to zero-initialize new elements created by resizeAndPreserve. #90

Open aaronmswan opened 5 years ago

aaronmswan commented 5 years ago

I found it useful to have new elements of an array created by resizeAndPreserve zero-initialize on request. For example when performing FFT interpolation. This can be a bit of a pain to do after the fact because multiple regions could need to be zeroed. I suppose this behavior could also be achieved externally to the library by re-implementing most of what resizeAndPreserve currently does.

Testing: passes "make check-testsuite".

Updated documentation.

Grateful for any feedback.

slayoo commented 5 years ago

Thank you! Let me though suggest adding a test program so that the new functionality will be covered.

Also, thinking out loud, I'm wondering if we could make the API more general by e.g. making the new argument an element-type pointer: if ==null nothing happens, while non-null value gives the user the option to provide a non-zero value for initialisation? @citibeth - any comments?

citibeth commented 5 years ago

Not sure what I think of it in the current context... This is the kind of change that could have unintended consequences. For example, what if someone wants to make blitz::Array<MyStruct,1>???