diff options
| author | Tyge Løvset <[email protected]> | 2023-02-13 23:01:15 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-13 23:01:15 +0100 |
| commit | c849c2c058bfd8b66ecbd741e49c471773d66dd6 (patch) | |
| tree | 9870dee078b271b198c1fa998fa050295aee04d7 /docs/cspan_api.md | |
| parent | 98f126a304f296dea2517d9e81c7f8e7b3aa80f5 (diff) | |
| download | STC-modified-c849c2c058bfd8b66ecbd741e49c471773d66dd6.tar.gz STC-modified-c849c2c058bfd8b66ecbd741e49c471773d66dd6.zip | |
Improved docs.
Diffstat (limited to 'docs/cspan_api.md')
| -rw-r--r-- | docs/cspan_api.md | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index 1bd36446..1e60a526 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -1,9 +1,9 @@ # STC [cspan](../include/stc/cspan.h): Multi-dimensional Array View  -The **cspan** is templated non-owning *single* and *multi-dimensional* view of an array. It is similar -to Python's numpy array slicing and C++ [std::span](https://en.cppreference.com/w/cpp/container/span) / -[std::mdspan](https://en.cppreference.com/w/cpp/container/mdspan). +The **cspan** is templated non-owning *single* and *multi-dimensional* view of an array. It has similarities +with Python's numpy array slicing and C++ [std::span](https://en.cppreference.com/w/cpp/container/span) / +[std::mdspan](https://en.cppreference.com/w/cpp/container/mdspan), and others. ## Header file and declaration **cspan** types are defined by the *using_cspan()* macro after the header is included. @@ -68,7 +68,7 @@ void SpanType_next(SpanTypeN_iter* it); ## Example 1 -The *cspan_slice()* function is similar to pythons numpy multi-dimensional arrays slicing, e.g.: +Dimension slicing in python, C, and C++: ```py import numpy as np @@ -92,7 +92,7 @@ if __name__ == '__main__': ``` ... can be written in C using cspan: ```c -#include <c11/fmt.h> +#include <stdio.h> #include <stc/cspan.h> using_cspan3(myspan, int); // define myspan, myspan2, myspan3. @@ -105,11 +105,11 @@ int main() { c_forrange (i, ss2.shape[0]) c_forrange (j, ss2.shape[1]) - fmt_print(" {}", *cspan_at(&ss2, i, j)); + printf(" %d", *cspan_at(&ss2, i, j)); puts(""); c_foreach (i, myspan2, ss2) - fmt_print(" {}", *i.ref); + printf(" %d", *i.ref); } ``` ... and (almost) in C++23: @@ -130,11 +130,11 @@ int main() { std::print(" {}", ss2[i, j]); std::println(); - // std::mdspan can't be iterated as a flat container! + // std::mdspan can't be iterated joined/flat! } ``` ## Example 2 -Slicing cspan without and with reducing the rank (like numpy array slicing): +Slicing cspan without and with reducing the rank: ```c #include <c11/fmt.h> #include <stc/cspan.h> |
