Kiwaku 0.1-beta
Containers Well Made
 
Loading...
Searching...
No Matches
Multi-dimensional views

Introduction

The first container proposed by KIWAKU is kwk::view. kwk::view is a non-owning adapter that can be constructed from various type of data sources so you can manipulate them as a nD array-like entity. This page will go over the basic of constructing, configuring, accessing and computing over views

A Quick Example

Let's start with a simple example:

#include <kwk/kwk.hpp>
#include <iostream>
#include <vector>
int main()
{
// 1/ defines some data in memory
std::vector<double> data = {1.2,3.4,5.6,7.8,9.10,11.12};
// 2/ take a view over data as a 2 x 3 array
auto v = kwk::view{ kwk::source = data // select the data source
, kwk::of_size(2,3) // specify the extents of the view
};
std::cout << v << "\n";
}
constexpr __::source_ source
Data source setting for kwk::table and kwk::view.
Definition source.hpp:61
constexpr auto of_size(D... d)
Generates a kwk::shape from a list of Extent.
Definition shape.hpp:339
Non-owning, contiguous multi-dimensional container.
Definition view.hpp:25

After constructing a std::vector to holds some data, we can take a view over its data. To do so, we create a view instance. The definition of our view may look strange for multiple reasons:

  • kwk::view is a template class but no template parameter is used because we use the CTAD (Constructor Template Argument Deduction) feature of C++17.
  • v is constructed from named parameters instead of more traditional, positional parameters. The two parameters we use here are kwk::source to specify where the data are stored and kwk::of_size to specify the size of each dimensions of the view.

Those API choices are very important for KIWAKU as we want to make the mental burden of remembering which parameter (type or value alike) come after which other or if any parameter has a potentially non-trivial default value. We'll go over each parameters as we continue this serie of tutorials.

Once done, we can just print the contents of the view. The result here should be:

[ 1.2 3.4 5.6 ]
[ 7.8 9.1 11.12 ]

Working with Views

Displaying data on the standard output is fine but, maybe, we want to do some actual work with our view.

Conclusion

In this first tutorial, we managed to:

  • get familiar with kwk::view, the abstraction for non-owning container
  • learn about the named parameter interface of KIWAKU containers
  • worked with the data through a view

In the next tutorial, we will take a look at kwk::table, the owning multi-dimensional container.