Skip to content

Commit be9bbba

Browse files
committed
Fix small spelling mistakes in the documentation
1 parent 2851957 commit be9bbba

File tree

7 files changed

+98
-29
lines changed

7 files changed

+98
-29
lines changed

docs/guides/constant.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
Using `kernel_float::constant`
22
===
33

4-
When working with mixed precision types, you will find that working with constants presents a bit a challenge.
4+
When working with mixed precision types, you will find that working with constants presents a bit of a challenge.
55

66
For example, a simple expression such as `3.14 * x` where `x` is of type `vec<float, 2>` will NOT be performed
77
in `float` precision as you might expect, but instead in `double` precision.
88
This happens since the left-hand side of this expression
99
(a constant) is a `double` and thus `kernel_float` will also cast the right-hand side to `double`.
1010

11-
To solve this problem, `kernel_float` offers a type called `constant<T>` that can be used to represents
11+
To solve this problem, `kernel_float` offers a type called `constant<T>` that can be used to represent
1212
constants. Any binary operations between a value of type `U` and a `constant<T>` will result in both
1313
operands being cast to type `U` and the operation is performed in the precision of type `U`. This makes
14-
`constant<T>` useful for representing constant in your code.
15-
14+
`constant<T>` useful for representing constants in your code.
1615

1716
For example, consider the following code:
1817

include/kernel_float/constant.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,44 @@
66

77
namespace kernel_float {
88

9+
/**
10+
* `constant<T>` represents a constant value of type `T`.
11+
*
12+
* The object has the property that for any binary operation involving
13+
* a `constant<T>` and a value of type `U`, the constant is automatically
14+
* cast to also be of type `U`.
15+
*
16+
* For example:
17+
* ```
18+
* float a = 5;
19+
* constant<double> b = 3;
20+
*
21+
* auto c = a + b; // The result will be of type `float`
22+
* ```
23+
*/
924
template<typename T = double>
1025
struct constant {
26+
/**
27+
* Create a new constant from the given value.
28+
*/
29+
KERNEL_FLOAT_INLINE
30+
constexpr constant(T value = {}) : value_(value) {}
31+
32+
KERNEL_FLOAT_INLINE
33+
constexpr constant(const constant<T>& that) : value_(that.value) {}
34+
35+
/**
36+
* Create a new constant from another constant of type `R`.
37+
*/
1138
template<typename R>
1239
KERNEL_FLOAT_INLINE explicit constexpr constant(const constant<R>& that) {
1340
auto f = ops::cast<R, T>();
1441
value_ = f(that.get());
1542
}
1643

17-
KERNEL_FLOAT_INLINE
18-
constexpr constant(T value = {}) : value_(value) {}
19-
44+
/**
45+
* Return the value of the constant
46+
*/
2047
KERNEL_FLOAT_INLINE
2148
constexpr T get() const {
2249
return value_;

include/kernel_float/conversion.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ struct AssignConversionProxy {
215215
};
216216

217217
/**
218-
* Takes a vector reference and gives back a helper object. This object helps when you want to assign one vector to another
219-
* vector of a different type. It's a way to enable implicit type conversion.
218+
* Takes a vector reference and gives back a helper object. This object allows you to assign
219+
* a vector of a different type to another vector while perofrming implicit type converion.
220220
*
221-
* For example, if `x = expression;` does not compile because `x` and `expression` are different vector types, you can use
222-
* `cast_to(x) = expression;` to make it work.
221+
* For example, if `x = expression;` does not compile because `x` and `expression` are
222+
* different vector types, you can use `cast_to(x) = expression;` to make it work.
223223
*
224224
* Example
225225
* =======
@@ -240,7 +240,7 @@ KERNEL_FLOAT_INLINE AssignConversionProxy<T, M> cast_to(T& input) {
240240
* Example
241241
* =======
242242
* ```
243-
* vec<int, 3> a = fill<3>(42); // return [42, 42, 42]
243+
* vec<int, 3> a = fill<3>(42); // returns [42, 42, 42]
244244
* ```
245245
*/
246246
template<size_t N, typename T>
@@ -255,7 +255,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> fill(T value = {}, extent<N> = {}) {
255255
* Example
256256
* =======
257257
* ```
258-
* vec<int, 3> a = zeros<int, 3>(); // return [0, 0, 0]
258+
* vec<int, 3> a = zeros<int, 3>(); // returns [0, 0, 0]
259259
* ```
260260
*/
261261
template<typename T, size_t N>
@@ -270,7 +270,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> zeros(extent<N> = {}) {
270270
* Example
271271
* =======
272272
* ```
273-
* vec<int, 3> a = ones<int, 3>(); // return [1, 1, 1]
273+
* vec<int, 3> a = ones<int, 3>(); // returns [1, 1, 1]
274274
* ```
275275
*/
276276
template<typename T, size_t N>
@@ -286,7 +286,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> ones(extent<N> = {}) {
286286
* =======
287287
* ```
288288
* vec<int, 3> a = {1, 2, 3};
289-
* vec<int, 3> b = fill_like(a, 42); // return [42, 42, 42]
289+
* vec<int, 3> b = fill_like(a, 42); // returns [42, 42, 42]
290290
* ```
291291
*/
292292
template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>
@@ -301,7 +301,7 @@ KERNEL_FLOAT_INLINE vector<T, E> fill_like(const V&, T value) {
301301
* =======
302302
* ```
303303
* vec<int, 3> a = {1, 2, 3};
304-
* vec<int, 3> b = zeros_like(a); // return [0, 0, 0]
304+
* vec<int, 3> b = zeros_like(a); // returns [0, 0, 0]
305305
* ```
306306
*/
307307
template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>
@@ -316,7 +316,7 @@ KERNEL_FLOAT_INLINE vector<T, E> zeros_like(const V& = {}) {
316316
* =======
317317
* ```
318318
* vec<int, 3> a = {1, 2, 3};
319-
* vec<int, 3> b = ones_like(a); // return [1, 1, 1]
319+
* vec<int, 3> b = ones_like(a); // returns [1, 1, 1]
320320
* ```
321321
*/
322322
template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>

include/kernel_float/iterate.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct range_impl {
4545
} // namespace detail
4646

4747
/**
48-
* Generate vector consisting of the result `fun(0)...fun(N-1)`
48+
* Generate vector consisting of the result `fun(0), ..., fun(N-1)`
4949
*
5050
* Example
5151
* =======
@@ -60,7 +60,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> range(F fun) {
6060
}
6161

6262
/**
63-
* Generate vector consisting of the numbers `0...N-1` of type `T`
63+
* Generate vector consisting of the numbers `0, ..., N-1` of type `T`
6464
*
6565
* Example
6666
* =======
@@ -75,7 +75,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> range() {
7575
}
7676

7777
/**
78-
* Takes a vector `vec<T, N>` and returns a new vector consisting of the numbers ``0...N-1`` of type ``T``
78+
* Takes a vector `vec<T, N>` and returns a new vector consisting of the numbers ``0, ..., N-1`` of type ``T``
7979
*
8080
* Example
8181
* =======
@@ -90,7 +90,7 @@ KERNEL_FLOAT_INLINE into_vector_type<V> range_like(const V& = {}) {
9090
}
9191

9292
/**
93-
* Takes a vector of size ``N`` and returns a new vector consisting of the numbers ``0...N-1``. The data type used
93+
* Takes a vector of size ``N`` and returns a new vector consisting of the numbers ``0, ..., N-1``. The data type used
9494
* for the indices is given by the first template argument, which is `size_t` by default. This function is useful when
9595
* needing to iterate over the indices of a vector.
9696
*
@@ -258,14 +258,14 @@ using concat_type = vector<concat_value_type<Vs...>, extent<concat_size<Vs...>>>
258258
* =======
259259
* ```
260260
* double vec1 = 1.0;
261-
* double3 vec2 = {3.0, 4.0, 5.0);
262-
* double4 vec3 = {6.0, 7.0, 8.0, 9.0};
263-
* vec<double, 9> concatenated = concat(vec1, vec2, vec3); // contains [1, 2, 3, 4, 5, 6, 7, 8, 9]
261+
* double3 vec2 = {2.0, 3.0, 4.0);
262+
* double4 vec3 = {5.0, 6.0, 7.0, 8.0};
263+
* vec<double, 8> concatenated = concat(vec1, vec2, vec3); // contains [1, 2, 3, 4, 5, 6, 7, 8]
264264
*
265265
* int num1 = 42;
266266
* float num2 = 3.14159;
267267
* int2 num3 = {-10, 10};
268-
* vec<float, 3> concatenated = concat(num1, num2, num3); // contains [42, 3.14159, -10, 10]
268+
* vec<float, 4> concatenated = concat(num1, num2, num3); // contains [42, 3.14159, -10, 10]
269269
* ```
270270
*/
271271
template<typename... Vs>

include/kernel_float/reduce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ KERNEL_FLOAT_INLINE T sum(const V& input) {
9797
* =======
9898
* ```
9999
* vec<int, 5> x = {5, 0, 2, 1, 0};
100-
* int y = sum(x); // Returns 5*0*2*1*0 = 0
100+
* int y = product(x); // Returns 5*0*2*1*0 = 0
101101
* ```
102102
*/
103103
template<typename V, typename T = vector_value_type<V>>

include/kernel_float/tiling.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ struct tiling_impl<TileDim, BlockDim, Distributions, index_sequence<Is...>> {
227227
template<typename T>
228228
struct tiling_iterator;
229229

230+
/**
231+
* Represents a tiling where the elements given by `TileDim` are distributed over the
232+
* threads given by `BlockDim` according to the distributions given by `Distributions`.
233+
*
234+
* The template parameters should be the following:
235+
*
236+
* * ``TileDim``: Should be an instance of ``tile_size<...>``. For example,
237+
* ``tile_size<16, 16>`` represents a 2-dimensional 16x16 tile.
238+
* * ``BlockDim``: Should be an instance of ``block_dim<...>``. For example,
239+
* ``block_dim<16, 4>`` represents a thread block having X dimension 16
240+
* and Y-dimension 4 for a total of 64 threads per block.
241+
* * ``Distributions``: Should be an instance of ``distributions<...>``. For example,
242+
* ``distributions<dist::cyclic, dist::blocked>`` will distribute elements in
243+
* cyclic fashion along the X-axis and blocked fashion along the Y-axis.
244+
* * ``IndexType``: The type used for index values (``int`` by default)
245+
*/
230246
template<
231247
typename TileDim,
232248
typename BlockDim,
@@ -516,10 +532,31 @@ using tiling_1d = tiling<tile_size<TileDim>, block_size<BlockDim>, distributions
516532
#define KERNEL_FLOAT_TILING_FOR_IMPL(ITER_VAR, TILING, A, B, N, ...) \
517533
KERNEL_FLOAT_CALL(KERNEL_FLOAT_CONCAT(KERNEL_FLOAT_TILING_FOR_IMPL, N), ITER_VAR, TILING, A, B)
518534

535+
/**
536+
* Iterate over the points in a ``tiling<...>`` using a for loop.
537+
*
538+
* There are two ways to use this macro. Using the 1 variable form:
539+
* ```
540+
* auto t = tiling<tile_size<16, 16>, block_size<4, 4>>;
541+
*
542+
* KERNEL_FLOAT_TILING_FOR(t, auto point) {
543+
* printf("%d,%d\n", point[0], point[1]);
544+
* }
545+
* ```
546+
*
547+
* Or using the 2 variables form:
548+
* ```
549+
* auto t = tiling<tile_size<16, 16>, block_size<4, 4>>;
550+
*
551+
* KERNEL_FLOAT_TILING_FOR(t, auto index, auto point) {
552+
* printf("%d] %d,%d\n", index, point[0], point[1]);
553+
* }
554+
* ```
555+
*/
519556
#define KERNEL_FLOAT_TILING_FOR(...) \
520557
KERNEL_FLOAT_TILING_FOR_IMPL(KERNEL_FLOAT_CONCAT(__tiling_index_variable__, __LINE__), __VA_ARGS__, 2, 1)
521558
// clang-format on
522559

523560
} // namespace kernel_float
524561

525-
#endif // KERNEL_FLOAT_TILING_H
562+
#endif // KERNEL_FLOAT_TILING_H

include/kernel_float/vector.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
namespace kernel_float {
1212

1313
/**
14-
* Container that stores ``N`` elements of type ``T``.
14+
* Container that store fixed number of elements of type ``T``.
1515
*
16-
* It is not recommended to use this class directly, but instead, use the type `vec<T, N>` which is an alias for
16+
* It is not recommended to use this class directly, instead, use the type `vec<T, N>` which is an alias for
1717
* `vector<T, extent<N>, vector_storage<T, E>>`.
1818
*
1919
* @tparam T The type of the values stored within the vector.
@@ -64,11 +64,17 @@ struct vector: public S {
6464
return E::size;
6565
}
6666

67+
/**
68+
* Returns a reference to the underlying storage type.
69+
*/
6770
KERNEL_FLOAT_INLINE
6871
storage_type& storage() {
6972
return *this;
7073
}
7174

75+
/**
76+
* Returns a reference to the underlying storage type.
77+
*/
7278
KERNEL_FLOAT_INLINE
7379
const storage_type& storage() const {
7480
return *this;

0 commit comments

Comments
 (0)