Skip to content

Commit ba14d8a

Browse files
committed
Improve readme
1 parent 4ce4a47 commit ba14d8a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ where:
1818
* `strideN` are the distances in the flat offsets between elements in each dimension.
1919

2020
Arrays efficiently support advanced manipulations like [cropping, slicing, and splitting](#slicing-cropping-and-splitting) arrays and loops, all while preserving compile-time constant parameters when possible.
21-
Although it is a heavily templated library, most features do not have significant code size or compile time implications, and incorrect usage generates informative and helpful error messages.
21+
Although it is a heavily templated library, incorrect usage generates informative and helpful error messages.
2222
Typically, an issue will result in only one error message, located at the site of the problem in user code.
23+
This is something [we test for](https://github.com/dsharlet/array/blob/master/test/errors.cpp#L18-L19).
2324

2425
Many other libraries offering multi-dimensional arrays or tensors allow compile-time constant shapes.
2526
*However*, most if not all of them only allow either all of the shape parameters to be compile-time constant, or none of them.
@@ -293,8 +294,8 @@ We can use arbitrary functions as expression operands:
293294
```
294295

295296
These operations generally produce loop nests that are as readily optimized by the compiler as hand-written loops.
296-
For example, consider the cross product: `crosses`, `xs`, and `ys` have shape `shape<dim<0, 3>, dense_dim<>>`, so the compiler will see small constant-range loops and likely be able to optimize this to similar efficiency as hand-written code, by unrolling and evaluating the function at compile time.
297-
The compiler will also likely be able to efficiently vectorize the `l` dimension of the `ein_reduce`, because that dimension has a constant stride 1.
297+
In this example, `crosses`, `xs`, and `ys` have shape `shape<dim<0, 3>, dense_dim<>>`, so the compiler will see small constant loops and likely be able to optimize this to similar efficiency as hand-written code, by unrolling and evaluating the function at compile time.
298+
The compiler also should be able to efficiently vectorize the `l` dimension of the `ein_reduce`, because that dimension has a constant stride 1.
298299

299300
The expression can be another kind of reduction, or not a reduction at all:
300301
```c++
@@ -303,10 +304,10 @@ The expression can be another kind of reduction, or not a reduction at all:
303304
ein_reduce(ein<i, j>(AT) = ein<j, i>(A));
304305

305306
// Maximum of each x-y plane of a 3D volume:
306-
dense_array<float, 3> T({8, 12, 20});
307+
dense_array<float, 3> volume({8, 12, 20});
307308
dense_array<float, 1> max_xy({20});
308309
auto r = ein<k>(max_xy);
309-
ein_reduce(r = max(r, ein<i, j, k>(T)));
310+
ein_reduce(r = max(r, ein<i, j, k>(volume)));
310311
```
311312
312313
Reductions can have a mix of result and operand types:
@@ -317,7 +318,9 @@ Reductions can have a mix of result and operand types:
317318
for_all_indices(W.shape(), [&](int j, int k) {
318319
W(j, k) = exp(-2.0f * pi * complex(0, 1) * (static_cast<float>(j * k) / 10));
319320
});
321+
// Using `make_ein_sum`, returning the result:
320322
auto X1 = make_ein_sum<complex, j>(ein<j, k>(W) * ein<k>(x));
323+
// Using `ein_reduce`, computing the result in place:
321324
vector<complex> X2({10}, 0.0f);
322325
ein_reduce(ein<j>(X2) += ein<j, k>(W) * ein<k>(x));
323326
```

test/readme.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ TEST(readme_ein_reduce) {
183183
ein_reduce(ein<i, j>(AT) = ein<j, i>(A));
184184

185185
// Maximum of each x-y plane of a 3D volume:
186-
dense_array<float, 3> T({8, 12, 20});
186+
dense_array<float, 3> volume({8, 12, 20});
187187
dense_array<float, 1> max_xy({20}, 0.0f);
188188
auto r = ein<k>(max_xy);
189-
ein_reduce(r = max(r, ein<i, j, k>(T)));
189+
ein_reduce(r = max(r, ein<i, j, k>(volume)));
190190

191191
const float pi = std::acos(-1.0f);
192192

@@ -196,7 +196,9 @@ TEST(readme_ein_reduce) {
196196
for_all_indices(W.shape(), [&](int j, int k) {
197197
W(j, k) = exp(-2.0f * pi * complex(0, 1) * (static_cast<float>(j * k) / 10));
198198
});
199+
// Using `make_ein_sum`, returning the result:
199200
auto X1 = make_ein_sum<complex, j>(ein<j, k>(W) * ein<k>(x));
201+
// Using `ein_reduce`, computing the result in place:
200202
vector<complex> X2({10}, 0.0f);
201203
ein_reduce(ein<j>(X2) += ein<j, k>(W) * ein<k>(x));
202204

0 commit comments

Comments
 (0)