Easy, robust, and fast numerics in C++
vif is a C++ library built to provide user friendly data manipulation as offered in interpreted languages like Python, IDL, GDL, but with the added benefit of C++, namely, increased robustness and speed. The library offers the following features:
It relies only on standard C++11, and a couple of well-known libraries (see INSTALL). Some features can optionally use compile-time reflection, which is not yet part of the C++ standard, so a small tool ('refgen') is used to fill the gap. These features are non-essential though, and reflection can be completely disabled if not needed.
The library was designed following three core principles:
The first principle requires that the most easily accessible interface is the safest to use, meaning that the library will perform, by default, some basic checks on the data before processing it (bounds checking, etc.). The second principle requires the existence of mechanisms to bypass these safety checks, such that it is always possible to write optimal code when checks are not needed. The third and last principle requires that both interfaces are as simple to use as possible, to minimize the amount of code the user has to write to reach their goal.
Thus far, vif has been a one-man project. Development started in 2013 during my PhD, and has continued until today. The library is now mature and fully functional; all that remains to be done before a version 1.0 is a final review of the code before API freeze, and wrapping up the documentation (see roadmap).
// Include the vif headers
#include <vif.hpp>
// Declare the main function, entry point of the program
int vif_main(int argc, char* argv[]) {
// Read some arguments from the command line
vif::uint_t n = 10;
vif::read_args(argc, argv, arg_list(n));
// Create a vector containing 1, 2, ..., n-1
vif::vec1d v = vif::indgen<double>(n);
// Print the square root of each element
vif::print(sqrt(v));
return 0;
}
g++ -std=c++11 foobar.cpp -o foobar
./foobar n=20
cvif foobar.cpp
./foobar n=20
# bonus: compile with full optimizations
cvif optimize foobar.cpp
./foobar n=20
Simply download the code, either by cloning the git repository:
git clone https://github.com/cschreib/vif.git
or by downloading .tgz or .zip archives from this page (see buttons at the top of the page). The library itself depends on several other libraries, all of which are fairly common and should be provided in your distribution's repositories (or in MacPorts if you are a MacOS user). Please refer to the