Getting started
Native example
Create a typed VAL value and format it through the polymorphic interface:
#include <iostream>
#include <memory>
#include <vector>
#include <snt/val/values.h>
#include <snt/val/to_string.h>
int main() {
std::vector<double> data = {1.0, 2.0, 3.0, 4.0};
auto matrix = std::make_unique<snt::val::ArrayValueFloat64>(
data, snt::val::Array::ShapeType{2, 2}
);
std::cout << matrix->to_string() << "\n";
std::cout << snt::val::to_string(matrix->get_shape()) << "\n";
return 0;
}
The value owns its flattened data and stores the shape separately. The
convenience type ArrayValueFloat64 is a typed ArrayValue<double> with
the public DataType::Float64 tag.
Build and run
Install the C++ package using Installation with the
VAL module enabled.
Save the example above as main.cpp and create this CMakeLists.txt in
the same directory:
cmake_minimum_required(VERSION 3.22)
project(snt_val_example LANGUAGES C CXX)
find_package(snt CONFIG REQUIRED)
add_executable(application main.cpp)
target_compile_features(application PRIVATE cxx_std_17)
target_link_libraries(application PRIVATE snt-val)
Configure with the installed package prefix, build, and run:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/snt
cmake --build build
./build/application
Expected output:
[[1, 2], [3, 4]]
[2,2]
Replace /path/to/snt with the installation prefix; omit that option if
CMake already finds SNT. C is enabled for discovery of HDF5 in packages built
with DIP support. See Using SciNumTools from CMake for package discovery details.
Continue with Workflows for arithmetic and conversion. The generated declarations are in the C++ API reference.