Skip to content

Commit

Permalink
Better support for non-Cayley types in if_else
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou authored Sep 23, 2023
1 parent e2ce76b commit b16f126
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 66 deletions.
60 changes: 9 additions & 51 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,20 @@ concurrency:
cancel-in-progress: true

jobs:

# windows:
# runs-on: [windows-2022]
# strategy:
# fail-fast: false
# matrix:
# cfg:
# - { tool: "-T ClangCL", config: Debug }
# - { tool: "-T ClangCL", config: Release }
# # - { tool: , config: Debug }
# # - { tool: , config: Release }
# steps:
# - name: Fetch current branch
# uses: actions/checkout@v3
# - name: Running CMake for MSVC
# run: |
# mkdir build && cd build
# cmake -G "Visual Studio 17 2022" ${{ matrix.cfg.tool }} -A x64 ..
# - name: Compiling Unit Tests
# run: |
# cd build
# cmake --build . --target kyosu-test --config ${{ matrix.cfg.config }} --parallel 2
# cmake --build . --target kyosu-test --config Release --parallel 2
# - name: Running Tests
# run: |
# cd build
# ctest -C ${{ matrix.cfg.config }} --output-on-failure

linux:
runs-on: [self-hosted]
strategy:
fail-fast: false
matrix:
cfg:
- { compiler: g++-12 , opts: "-O0 -DEVE_NO_FORCEINLINE" }
- { compiler: g++-12 , opts: "-O3 -DNDEBUG" }
- { compiler: clang++ , opts: "-O0 -DEVE_NO_FORCEINLINE" }
- { compiler: clang++ , opts: "-O3 -DNDEBUG" }
- { compiler: g++-12 , opts: "-O0 -DEVE_NO_FORCEINLINE" }
- { compiler: g++-12 , opts: "-O3 -DNDEBUG" }
- { compiler: clang++ , opts: "-O0 -DEVE_NO_FORCEINLINE" }
- { compiler: clang++ , opts: "-O3 -DNDEBUG" }
- { compiler: g++-12 , opts: "-O0 -DEVE_NO_FORCEINLINE -mavx2" }
- { compiler: g++-12 , opts: "-O3 -DNDEBUG -mavx2" }
- { compiler: clang++ , opts: "-O0 -DEVE_NO_FORCEINLINE -mavx2" }
- { compiler: clang++ , opts: "-O3 -DNDEBUG -mavx2" }
steps:
- name: Fetch current branch
uses: actions/checkout@v3
Expand All @@ -68,7 +44,7 @@ jobs:
fail-fast: false
matrix:
cfg:
- { compiler: g++-12 , opts: "-O0 -DEVE_NO_FORCEINLINE" , linker: }
- { compiler: g++-12 , opts: "-O0 -DEVE_NO_FORCEINLINE", linker: }
# - { compiler: g++-12 , opts: "-O3 -DNDEBUG" , linker: }
# - { compiler: clang++ , opts: "-O0" , linker: }
# - { compiler: clang++ , opts: "-O3 -flto -DNDEBUG" , linker: }
Expand All @@ -83,21 +59,3 @@ jobs:
cmake .. -DCMAKE_CXX_COMPILER=${{ matrix.cfg.compiler }} -DCMAKE_CXX_FLAGS="${{ matrix.cfg.opts }}" -DCMAKE_EXE_LINKER_FLAGS=${{ matrix.cfg.linker }}
- name: Running Unit Tests
run: cd build && make kyosu-test -j 2 && ctest --output-on-failure -j 2

# android:
# runs-on: [macos-12]
# strategy:
# fail-fast: false
# matrix:
# cfg:
# - { opts: -O0 }
# - { opts: "-O3 -flto -DNDEBUG"}
# steps:
# - name: Fetch current branch
# uses: actions/checkout@v3
# - name: Running CMake for ${{ matrix.cfg.compiler }} with ${{ matrix.cfg.opts }}
# run: |
# mkdir build && cd build
# cmake .. -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a
# - name: Compiling Unit Tests
# run: cd build && make kyosu-test -j 2
28 changes: 14 additions & 14 deletions include/kyosu/types/impl/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ namespace kyosu::_
if constexpr(concepts::cayley_dickson<T> && concepts::cayley_dickson<U>)
{
using type = as_cayley_dickson_t<T,U>;
using ret_t = std::conditional_t<eve::simd_value<Mask>, eve::as_wide_as_t<type,Mask>, type>;
constexpr eve::as<eve::element_type_t<type>> tgt = {};
using ret_t = eve::as_wide_as_t<type,Mask>;

return ret_t{ kumi::map ( [&](auto const& v, auto const& w) { return eve::if_else(m, v, w); }
, kyosu::convert(t, tgt), kyosu::convert(f, tgt)
, kyosu::convert(t, eve::as_element<type>{})
, kyosu::convert(f, eve::as_element<type>{})
)
};
}
else if constexpr(concepts::cayley_dickson<T> && !concepts::cayley_dickson<U>)
{
auto parts = kumi::map([&](auto const& v) { return eve::if_else(m, v, f); }, t);

if constexpr(eve::simd_value<Mask>) return eve::as_wide_as_t<T,Mask>{parts};
else return T{parts};
}
else if constexpr(!concepts::cayley_dickson<T> && concepts::cayley_dickson<U>)
else
{
auto parts = kumi::map([&](auto const& w) { return eve::if_else(m, t, w); }, f);
auto parts = [&]()
{
auto cst = []<typename I>(auto x, I const&) { if constexpr(I::value == 0) return x; else return eve::zero; };
if constexpr(!concepts::cayley_dickson<U>)
return kumi::map_index([&](auto i, auto const& e) { return eve::if_else(m, e, cst(f, i)); }, t);
else if constexpr(!concepts::cayley_dickson<T>)
return kumi::map_index([&](auto i, auto const& e) { return eve::if_else(m, cst(t, i), e); }, f);
}();

if constexpr(eve::simd_value<Mask>) return eve::as_wide_as_t<U,Mask>{parts};
else return U{parts};
using type = eve::as_wide_as_t<std::conditional_t<!concepts::cayley_dickson<U>,T,U>,Mask>;
return type{parts};
}
}

Expand Down
24 changes: 23 additions & 1 deletion test/unit/function/if_else.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,32 @@ TTS_CASE_WITH ( "Check behavior of if_else on SIMD cayley-dickson"

for(auto e : a0)
{
auto m = eve::is_odd(e);
auto m = eve::is_lez(e);
TTS_EQUAL(kyosu::if_else(m, wc_t(c_t(0,-e)) , wc_t(c_t(0,e))) , wc_t(c_t(0,m ? -e : e)));
TTS_EQUAL(kyosu::if_else(m, wq_t(q_t(0,-e,1,-2)), wq_t(q_t(0,e,-1,2))), wq_t(q_t(0,m ? -e : e,m ? 1 : -1,m ? -2 : 2)));
TTS_EQUAL(kyosu::if_else(m, wc_t(c_t(0,-e)) , wq_t(q_t(0,e,-1,2))), wq_t(q_t(0,m ? -e : e,m ? 0 : -1,m ? 0 : 2)));
TTS_EQUAL(kyosu::if_else(m, wq_t(q_t(0,-e,1,-2)), wc_t(c_t(0, e))) , wq_t(q_t(0,m ? -e : e,m ? 1 : 0,m ? -2 : 0)));
}
};


TTS_CASE_WITH ( "Check behavior of if_else on cayley-dickson/named constants"
, tts::bunch<kyosu::scalar_real_types>
, tts::generate(tts::randoms(-10,+10))
)
<typename T>(T const& a0 )
{
using e_t = typename T::value_type;
using c_t = kyosu::complex_t<e_t>;
using wc_t = eve::wide<c_t>;

for(auto e : a0)
{
auto m = eve::is_lez(e);

TTS_EQUAL(kyosu::if_else(m, c_t(0,-e) , eve::one) , c_t(m ? 0 : 1, m ? -e : 0) );
TTS_EQUAL(kyosu::if_else(m, wc_t(c_t(0,-e)), eve::one) , wc_t(c_t(m ? 0 : 1, m ? -e : 0)) );
TTS_EQUAL(kyosu::if_else(m, eve::one, c_t(-2,-e) ), c_t(m ? 1 : -2, m ? 0 : -e) );
TTS_EQUAL(kyosu::if_else(m, eve::one, wc_t(c_t(-2,-e))), wc_t(c_t(m ? 1 : -2, m ? 0 : -e)) );
}
};

0 comments on commit b16f126

Please sign in to comment.