# stdtensor

## Overview

The goal of stdtensor is to provide a C++ library for tensors in STL style.
It will allow user to write program in a type safe and generic way.

## Components

### generic container data types

```cpp
template <typename R, rank_t r>
tensor<R, r>;  // the data owner type

template <typename R, rank_t r>
tensor_ref<R, r>; // the reference type

template <typename R, rank_t r>
tensor_view<R, r>; // the read only reference type, like https://en.cppreference.com/w/cpp/header/string_view
```

All the 3 kinds of data types should have the following methods:
They should be as consist as https://en.cppreference.com/w/cpp/container/vector

```cpp
R* data();
const R* data();

R &at(...);
const R at();

rank_t rank();
std::array<dim_t, r> dims();

size_t size(); // the product of all dims
```

### generic algorithms for tensors

TODO

### advanced features

- allow memory to be allocated on GPU via [`thrust::device_vector`](https://github.com/thrust/thrust)
- small tensors with constexpr shape

## Potential usages

- type safe memory buffer
- the tensor counter part of [`std::vector`](https://en.cppreference.com/w/cpp/container/vector)
- the C++ port of [`np.array`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html)
- build deep neural network framework (like http://github.com/lgarithm/crystalnet)
- as a wrapper interface to other linear algebra libraries, including the Blas family, Eigen, OpenCV, thrust, etc.