-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedicated a lot of time but still does not work.
- Loading branch information
1 parent
c97e05c
commit 579560d
Showing
4 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
#pragma once | ||
#include <cmath> | ||
#include <type_traits> | ||
#include <complex> | ||
|
||
|
||
|
||
|
||
|
||
namespace viltrum { | ||
struct NormDefault { | ||
float operator()(float v) const { return std::abs(v); } | ||
double operator()(double v) const { return std::abs(v); } | ||
template<typename N> | ||
auto operator()(const std::complex<N>& c) const { | ||
return (*this)(c.real()) + (*this)(c.imag()); | ||
} | ||
template<typename V> | ||
auto operator()(const V& v) const { | ||
auto i = v.begin(); | ||
using S = decltype((*this)(*i)); | ||
S s; bool first = true; | ||
if (i != v.end()) { s = (*this)(*i); ++i; } | ||
while (i != v.end()) { s += (*this)(*i); ++i; } | ||
return s; | ||
} | ||
//These sign functions are for when the sign matters (intermediate calculations) | ||
float sign(float v) const { return v; } | ||
float sign(double v) const { return v; } | ||
template<typename N> | ||
auto sign(const std::complex<N>& c) const { | ||
return sign(c.real()) + sign(c.imag()); | ||
} | ||
template<typename V> | ||
auto operator()(const V& v, typename std::enable_if_t<std::is_arithmetic_v<typename V::value_type>, int> = 0) const { | ||
auto sign(const V& v) const { | ||
auto i = v.begin(); | ||
using S = decltype(norm(*i)); | ||
using S = decltype(sign(*i)); | ||
S s; bool first = true; | ||
if (i != v.end()) { s = norm(*i); ++i; } | ||
while (i != v.end()) { s += norm(*i); ++i; } | ||
if (i != v.end()) { s = sign(*i); ++i; } | ||
while (i != v.end()) { s += sign(*i); ++i; } | ||
return s; | ||
} | ||
}; | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters