Skip to content

Commit 569fca9

Browse files
committed
moved dsga::invoke() into its own example file ,,, made all lambda captures specific
1 parent 2425bb1 commit 569fca9

20 files changed

+264
-131
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
[https://github.com/davidbrowne/dsga](https://github.com/davidbrowne/dsga)
77

88
## Current Version
9-
v2.2.4
9+
v2.2.5
1010

1111
## [Latest Major Changes](docs/CHANGELOG.md)
12+
* v2.2.5
13+
* Extracted ```dsga::invoke()``` to its own example header, and modified it to work on a wide range of inputs.
14+
* Made all lambda captures specific.
1215
* v2.2.4
13-
* Added dsga::compXor() to perform xor operations on boolean values (as opposed to bitwise xor ^)
14-
* Added dsga::invoke() which returns a vector created by invoking an operation element-wise to a variable number of vectors (there must be at least 1) that are all the same size, but might be of different types
16+
* Added ```dsga::compXor()``` to perform xor operations on boolean values (as opposed to bitwise xor ^)
17+
* Added ```dsga::invoke()``` which returns a vector created by invoking an operation element-wise to a variable number of vectors (there must be at least 1) that are all the same size, but might be of different types
1518
* v2.2.3
1619
* Upgraded to cxcm v1.1.10
1720
* v2.2.1
@@ -33,9 +36,9 @@ v2.2.4
3336

3437
## Tested Compilers
3538
### Regularly Tested
36-
* Microsoft Visual Studio 2022 v17.12.3
39+
* Microsoft Visual Studio 2022 v17.12.4
3740
* gcc v14.2.0
38-
* clang v19.1.6
41+
* clang v19.1.7
3942
* icx v2024.1.0 - Must set "precise" floating-point model since default is "fast" and the "float_control" #pragma doesn't seem to work.
4043

4144
### Minimum Version
@@ -361,10 +364,10 @@ This is a c++20 library, so that needs to be the minimum standard that you tell
361364
362365
## Status
363366
364-
Current version: `v2.2.4`
367+
Current version: `v2.2.5`
365368
366369
* Everything major has some tests, but code coverage is not 100%.
367-
* [Last Released: v2.0.0](https://github.com/davidbrowne/dsga/releases/tag/v2.0.0)
370+
* [Last Released: v2.2.5](https://github.com/davidbrowne/dsga/releases/tag/v2.2.5)
368371
* [Change Log](docs/CHANGELOG.md)
369372
370373
### The next steps
@@ -390,7 +393,7 @@ The tests have been most recently run on:
390393
391394
### Windows 11 Native
392395
393-
* **MSVC 2022 - v17.12.3**
396+
* **MSVC 2022 - v17.12.4**
394397
395398
```
396399
[doctest] doctest version is "2.4.11"
@@ -412,7 +415,7 @@ The tests have been most recently run on:
412415
[doctest] Status: SUCCESS!
413416
```
414417
415-
* **clang 19.1.6** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.6):
418+
* **clang 19.1.7** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.7):
416419
417420
Performs all the unit tests except where there is lack of support for ```std::is_corresponding_member<>```, and this is protected with a feature test macro.
418421

VS2022/dsga.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
<MultiProcessorCompilation>true</MultiProcessorCompilation>
143143
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
144144
<ControlFlowGuard>Guard</ControlFlowGuard>
145+
<AdditionalOptions>/Ob3 %(AdditionalOptions)</AdditionalOptions>
146+
<IntrinsicFunctions>true</IntrinsicFunctions>
147+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
148+
<Optimization>Disabled</Optimization>
145149
</ClCompile>
146150
<Link>
147151
<SubSystem>Console</SubSystem>
@@ -161,6 +165,7 @@
161165
<MultiProcessorCompilation>true</MultiProcessorCompilation>
162166
<AdditionalOptions>/Ob3 %(AdditionalOptions)</AdditionalOptions>
163167
<ControlFlowGuard>Guard</ControlFlowGuard>
168+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
164169
</ClCompile>
165170
<Link>
166171
<SubSystem>Console</SubSystem>
@@ -180,6 +185,7 @@
180185
<ClInclude Include="..\examples\compare.hxx" />
181186
<ClInclude Include="..\examples\format_output.hxx" />
182187
<ClInclude Include="..\examples\hash.hxx" />
188+
<ClInclude Include="..\examples\invoke.hxx" />
183189
<ClInclude Include="..\examples\ostream_output.hxx" />
184190
<ClInclude Include="..\examples\span_convert.hxx" />
185191
<ClInclude Include="..\examples\stl.hxx" />

VS2022/dsga.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
<ClInclude Include="..\examples\stl.hxx">
5858
<Filter>Header Files</Filter>
5959
</ClInclude>
60+
<ClInclude Include="..\examples\invoke.hxx">
61+
<Filter>Header Files</Filter>
62+
</ClInclude>
6063
</ItemGroup>
6164
<ItemGroup>
6265
<None Include="..\README.md" />

docs/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Change Log
22

3+
### v2.2.5
4+
* Extracted ```dsga::invoke()``` to its own example header, and modified it to work on a wide range of inputs.
5+
* Made all lambda captures specific.
6+
37
### v2.2.4
4-
* Added dsga::compXor() to perform xor operations on boolean values (as opposed to bitwise xor ^)
5-
* Added dsga::invoke() which returns a vector created by invoking an operation element-wise to a variable number of vectors (there must be at least 1) that are all the same size, but might be of different types
8+
* Added ```dsga::compXor()``` to perform xor operations on boolean values (as opposed to bitwise xor ^)
9+
* Added ```dsga::invoke()``` which returns a vector created by invoking an operation element-wise to a variable number of vectors (there must be at least 1) that are all the same size, but might be of different types
610
* Upgraded to cxcm v1.2.0
711

812
### v2.2.3

examples/angle.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright David Browne 2020-2024.
2+
// Copyright David Browne 2020-2025.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// https://www.boost.org/LICENSE_1_0.txt)

examples/hash.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright David Browne 2020-2024.
2+
// Copyright David Browne 2020-2025.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// https://www.boost.org/LICENSE_1_0.txt)
@@ -14,7 +14,7 @@
1414
template <typename T>
1515
constexpr std::size_t hash_combine(std::size_t seed, const T &t) noexcept
1616
{
17-
std::size_t x = seed + 0x9e3779b9 + std::hash<T>{}(t);
17+
std::size_t x = seed + 0x9e3779b97f4a7c15 + std::hash<T>{}(t);
1818

1919
x ^= x >> 30;
2020
x *= 0xbf58476d1ce4e5b9;

examples/invoke.hxx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
// Copyright David Browne 2024-2025.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// https://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include "dsga.hxx"
8+
9+
//
10+
// invoking lambdas with vector, matrix, and scalar values
11+
//
12+
13+
namespace dsga
14+
{
15+
//
16+
// support for the invoke() function
17+
//
18+
namespace invoke_detail
19+
{
20+
template <typename T>
21+
struct is_dsga_matrix : std::false_type {};
22+
23+
template <typename T, std::size_t C, std::size_t R>
24+
struct is_dsga_matrix<dsga::basic_matrix<T, C, R>> : std::true_type {};
25+
26+
template <typename T>
27+
constexpr bool is_dsga_matrix_v = is_dsga_matrix<T>::value;
28+
29+
template <typename T>
30+
concept can_index = requires(T t, int i)
31+
{
32+
t[i];
33+
t.size();
34+
};
35+
36+
template <typename T>
37+
concept has_at = requires (T t, int i)
38+
{
39+
t.at(i);
40+
};
41+
42+
template <typename T>
43+
struct indexer
44+
{
45+
indexer(const T &val, std::size_t c) noexcept : t(val), C(c)
46+
{
47+
}
48+
49+
auto &operator []([[ maybe_unused ]] std::size_t index)
50+
{
51+
// check for valid index based on return vector size
52+
if (index >= C)
53+
{
54+
throw std::out_of_range("index out of range");
55+
}
56+
57+
// a matrix can technically index, but we want matrices
58+
// to be passed down whole and not just a column of a matrix
59+
if constexpr (can_index<T> && !is_dsga_matrix_v<T>)
60+
{
61+
// check for valid index based on indexable size
62+
if (index >= t.size())
63+
{
64+
throw std::out_of_range("index out of range");
65+
}
66+
67+
if constexpr (has_at<T>)
68+
{
69+
return t.at(index);
70+
}
71+
else
72+
{
73+
return t[index];
74+
}
75+
}
76+
else
77+
{
78+
return t;
79+
}
80+
}
81+
82+
private:
83+
const T &t;
84+
std::size_t C;
85+
};
86+
}
87+
88+
// not in GLSL
89+
// return a vector created by invoking an operation element-wise to a variable number of arguments (there must be at least 1)
90+
// that are either dimensional_scalar or basic_matrix -- if an argument isn't a vector of dimensional_scalars of length C,
91+
// it can be a single scalar that will be used C times (the length of the return vector) -- similarly, if an argument is a
92+
// matrix, it will be used C times (the length of the return vector) -- usually the arguments will be vectors of the same
93+
// length C or a std::array or std::span of matrices of the same length C.
94+
//
95+
// the Op must return a dsga::dimensional_scalar type, since invoke() returns a dsga::basic_vector of the results.
96+
template <std::size_t C, typename Op, typename ...Ts>
97+
requires ((sizeof ...(Ts)) > 0) && (C > 1)
98+
[[nodiscard]] constexpr auto invoke(Op op, const Ts & ...args) noexcept
99+
{
100+
auto op_invoke = [&op, &args...](std::size_t index) { return op(invoke_detail::indexer(args, C)[index] ...); };
101+
102+
return [&op_invoke]<std::size_t ...Is>(std::index_sequence<Is...>)
103+
{
104+
return basic_vector(op_invoke(Is) ...);
105+
}(std::make_index_sequence<C>{});
106+
}
107+
108+
// not in GLSL
109+
// return a vector created by invoking an operation element-wise to a variable number of vectors (there must be at least 1)
110+
// that are all the same size, but might be of different types
111+
template <typename Op, std::size_t C, bool ...Ws, dimensional_scalar ...Ts, typename ...Ds>
112+
requires ((sizeof ...(Ts)) > 0) && (C > 1)
113+
[[nodiscard]] constexpr basic_vector<std::invoke_result_t<Op, Ts...>, C> invoke_on_vectors(Op op, const vector_base<Ws, Ts, C, Ds> & ...vectors) noexcept
114+
{
115+
return dsga::invoke<C>(op, vectors...);
116+
117+
// auto op_invoke = [&op, &vectors ...](std::size_t index) { return op(vectors[index] ...); };
118+
//
119+
// return [&op_invoke]<std::size_t ...Is>(std::index_sequence<Is...>)
120+
// {
121+
// return basic_vector<std::invoke_result_t<Op, Ts...>, C>{op_invoke(Is) ...};
122+
// }(std::make_index_sequence<C>{});
123+
}
124+
}

examples/stl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright David Browne 2020-2024.
2+
// Copyright David Browne 2020-2025.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// https://www.boost.org/LICENSE_1_0.txt)

examples/stl.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright David Browne 2020-2024.
2+
// Copyright David Browne 2020-2025.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// https://www.boost.org/LICENSE_1_0.txt)

examples/tolerance.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// Copyright David Browne 2020-2024.
2+
// Copyright David Browne 2020-2025.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// https://www.boost.org/LICENSE_1_0.txt)

0 commit comments

Comments
 (0)