Skip to content

Commit

Permalink
moved dsga::invoke() into its own example file ,,, made all lambda ca…
Browse files Browse the repository at this point in the history
…ptures specific
  • Loading branch information
davidbrowne committed Jan 20, 2025
1 parent 2425bb1 commit 569fca9
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 131 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
[https://github.com/davidbrowne/dsga](https://github.com/davidbrowne/dsga)

## Current Version
v2.2.4
v2.2.5

## [Latest Major Changes](docs/CHANGELOG.md)
* v2.2.5
* Extracted ```dsga::invoke()``` to its own example header, and modified it to work on a wide range of inputs.
* Made all lambda captures specific.
* v2.2.4
* Added dsga::compXor() to perform xor operations on boolean values (as opposed to bitwise xor ^)
* 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
* Added ```dsga::compXor()``` to perform xor operations on boolean values (as opposed to bitwise xor ^)
* 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
* v2.2.3
* Upgraded to cxcm v1.1.10
* v2.2.1
Expand All @@ -33,9 +36,9 @@ v2.2.4

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

### Minimum Version
Expand Down Expand Up @@ -361,10 +364,10 @@ This is a c++20 library, so that needs to be the minimum standard that you tell
## Status
Current version: `v2.2.4`
Current version: `v2.2.5`
* Everything major has some tests, but code coverage is not 100%.
* [Last Released: v2.0.0](https://github.com/davidbrowne/dsga/releases/tag/v2.0.0)
* [Last Released: v2.2.5](https://github.com/davidbrowne/dsga/releases/tag/v2.2.5)
* [Change Log](docs/CHANGELOG.md)
### The next steps
Expand All @@ -390,7 +393,7 @@ The tests have been most recently run on:
### Windows 11 Native
* **MSVC 2022 - v17.12.3**
* **MSVC 2022 - v17.12.4**
```
[doctest] doctest version is "2.4.11"
Expand All @@ -412,7 +415,7 @@ The tests have been most recently run on:
[doctest] Status: SUCCESS!
```
* **clang 19.1.6** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.6):
* **clang 19.1.7** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.7):
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.
Expand Down
6 changes: 6 additions & 0 deletions VS2022/dsga.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<ControlFlowGuard>Guard</ControlFlowGuard>
<AdditionalOptions>/Ob3 %(AdditionalOptions)</AdditionalOptions>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -161,6 +165,7 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>/Ob3 %(AdditionalOptions)</AdditionalOptions>
<ControlFlowGuard>Guard</ControlFlowGuard>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -180,6 +185,7 @@
<ClInclude Include="..\examples\compare.hxx" />
<ClInclude Include="..\examples\format_output.hxx" />
<ClInclude Include="..\examples\hash.hxx" />
<ClInclude Include="..\examples\invoke.hxx" />
<ClInclude Include="..\examples\ostream_output.hxx" />
<ClInclude Include="..\examples\span_convert.hxx" />
<ClInclude Include="..\examples\stl.hxx" />
Expand Down
3 changes: 3 additions & 0 deletions VS2022/dsga.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<ClInclude Include="..\examples\stl.hxx">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\examples\invoke.hxx">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
Expand Down
8 changes: 6 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Change Log

### v2.2.5
* Extracted ```dsga::invoke()``` to its own example header, and modified it to work on a wide range of inputs.
* Made all lambda captures specific.

### v2.2.4
* Added dsga::compXor() to perform xor operations on boolean values (as opposed to bitwise xor ^)
* 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
* Added ```dsga::compXor()``` to perform xor operations on boolean values (as opposed to bitwise xor ^)
* 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
* Upgraded to cxcm v1.2.0

### v2.2.3
Expand Down
2 changes: 1 addition & 1 deletion examples/angle.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright David Browne 2020-2024.
// Copyright David Browne 2020-2025.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
Expand Down
4 changes: 2 additions & 2 deletions examples/hash.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

x ^= x >> 30;
x *= 0xbf58476d1ce4e5b9;
Expand Down
124 changes: 124 additions & 0 deletions examples/invoke.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

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

#include "dsga.hxx"

//
// invoking lambdas with vector, matrix, and scalar values
//

namespace dsga
{
//
// support for the invoke() function
//
namespace invoke_detail
{
template <typename T>
struct is_dsga_matrix : std::false_type {};

template <typename T, std::size_t C, std::size_t R>
struct is_dsga_matrix<dsga::basic_matrix<T, C, R>> : std::true_type {};

template <typename T>
constexpr bool is_dsga_matrix_v = is_dsga_matrix<T>::value;

template <typename T>
concept can_index = requires(T t, int i)
{
t[i];
t.size();
};

template <typename T>
concept has_at = requires (T t, int i)
{
t.at(i);
};

template <typename T>
struct indexer
{
indexer(const T &val, std::size_t c) noexcept : t(val), C(c)
{
}

auto &operator []([[ maybe_unused ]] std::size_t index)
{
// check for valid index based on return vector size
if (index >= C)
{
throw std::out_of_range("index out of range");
}

// a matrix can technically index, but we want matrices
// to be passed down whole and not just a column of a matrix
if constexpr (can_index<T> && !is_dsga_matrix_v<T>)
{
// check for valid index based on indexable size
if (index >= t.size())
{
throw std::out_of_range("index out of range");
}

if constexpr (has_at<T>)
{
return t.at(index);
}
else
{
return t[index];
}
}
else
{
return t;
}
}

private:
const T &t;
std::size_t C;
};
}

// not in GLSL
// return a vector created by invoking an operation element-wise to a variable number of arguments (there must be at least 1)
// that are either dimensional_scalar or basic_matrix -- if an argument isn't a vector of dimensional_scalars of length C,
// it can be a single scalar that will be used C times (the length of the return vector) -- similarly, if an argument is a
// matrix, it will be used C times (the length of the return vector) -- usually the arguments will be vectors of the same
// length C or a std::array or std::span of matrices of the same length C.
//
// the Op must return a dsga::dimensional_scalar type, since invoke() returns a dsga::basic_vector of the results.
template <std::size_t C, typename Op, typename ...Ts>
requires ((sizeof ...(Ts)) > 0) && (C > 1)
[[nodiscard]] constexpr auto invoke(Op op, const Ts & ...args) noexcept
{
auto op_invoke = [&op, &args...](std::size_t index) { return op(invoke_detail::indexer(args, C)[index] ...); };

return [&op_invoke]<std::size_t ...Is>(std::index_sequence<Is...>)
{
return basic_vector(op_invoke(Is) ...);
}(std::make_index_sequence<C>{});
}

// not in GLSL
// return 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
template <typename Op, std::size_t C, bool ...Ws, dimensional_scalar ...Ts, typename ...Ds>
requires ((sizeof ...(Ts)) > 0) && (C > 1)
[[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
{
return dsga::invoke<C>(op, vectors...);

// auto op_invoke = [&op, &vectors ...](std::size_t index) { return op(vectors[index] ...); };
//
// return [&op_invoke]<std::size_t ...Is>(std::index_sequence<Is...>)
// {
// return basic_vector<std::invoke_result_t<Op, Ts...>, C>{op_invoke(Is) ...};
// }(std::make_index_sequence<C>{});
}
}
2 changes: 1 addition & 1 deletion examples/stl.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright David Browne 2020-2024.
// Copyright David Browne 2020-2025.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
Expand Down
2 changes: 1 addition & 1 deletion examples/stl.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright David Browne 2020-2024.
// Copyright David Browne 2020-2025.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
Expand Down
2 changes: 1 addition & 1 deletion examples/tolerance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

0 comments on commit 569fca9

Please sign in to comment.