And finally, a bit of optimisation
This commit is contained in:
parent
3bd422ab9f
commit
9cf197027d
@ -15,9 +15,7 @@
|
|||||||
bool silent;
|
bool silent;
|
||||||
bool test_energy;
|
bool test_energy;
|
||||||
|
|
||||||
int min(int a, int b) {
|
#define min(a, b) { (a < b ? a : b) }
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nearly_equal(float a, float b) {
|
bool nearly_equal(float a, float b) {
|
||||||
return std::nextafter(a, std::numeric_limits<float>::lowest()) <= b
|
return std::nextafter(a, std::numeric_limits<float>::lowest()) <= b
|
||||||
@ -110,9 +108,9 @@ std::vector<int> optimal_vertical_seam(std::vector<float> energy, int width, int
|
|||||||
|
|
||||||
//Idea : float next_energy = min_val - energy[width*i + min_idx];
|
//Idea : float next_energy = min_val - energy[width*i + min_idx];
|
||||||
//! With floats, we don't always have x + y - y == x, so we check is x+y == x+y
|
//! With floats, we don't always have x + y - y == x, so we check is x+y == x+y
|
||||||
auto is_next_idx = [=](int idx) {
|
// This define is a bit ugly but 200x faster than using a lambda function
|
||||||
return nearly_equal(dyn_energy[(i-1)*width + idx]+energy[width*i + min_idx], min_val);
|
#define is_next_idx(idx) \
|
||||||
};
|
(dyn_energy[(i-1)*width + idx]+energy[width*i + min_idx] == min_val)
|
||||||
|
|
||||||
if (is_next_idx(min_idx)) {
|
if (is_next_idx(min_idx)) {
|
||||||
// min_idx does not change
|
// min_idx does not change
|
||||||
|
Loading…
x
Reference in New Issue
Block a user