Multiple Exposure Implementation

Does anyone know about the implemented multi-exposure algorithm? I am looking for something that the given vectors A, B compute the product A [i] ^ B [i] using some of the fast algorithms there.

Thanks!

+4
source share
3 answers

The following assumes your data is a floating point. If you have integers with multiple dots, indicate your requirements.

The pure numerical way is, of course, to take the magazine first. In fact, partial works can easily be under / overflowed, even if the result is finite.

Idiomatic corresponding program in C ++:

#include <cmath> #include <functional> #include <numeric> double f(double x, double y) { return y * std::log(x); } template <typename I, typename J> double multi_exponentiation(I a0, I an, J b0) { return std::exp(std::inner_product(a0, an, b0, 0., std::plus<double>(), f)); } // Example program int main() { std::vector<double> a, b; ... double e = multi_exponentiation(a.begin(), a.end(), b.begin()); } 

Using inner_product instead of writing a loop in itself has the advantage that as soon as you know that performance is a problem, you can replace the inner_product algorithm with the parallel_inner_product algorithm provided by a third-party library (or write one yourself).

+2
source

How fast should it be? Depending on the size of your algorithm, the power function should not be too bottleneck.

You should write a simple function such as:

 Vector VectorPower( Vector vec1, Vector vec2 ) { assert(vec1.length() == vec2.length()); Vector vecAns( vec1.length() ); for( unsigned int i = 0; i < vec1.length(); i++ ) { vecAns[i] = pow( vec1[i], vec2[i] ); } return vecAns; } 

In most cases, this will be effective enough for your application. If you were to implement a square root or some other transcendental function, you would also look at optimization.

In addition, some processors are optimized for arbitrary integrated capacities, and, of course, GPUs (although this helps a little if it is not a graphic-related record and is not marked as such).

Hope this answers your question :)

0
source

Have you tried tommath (not sure if it meets your performance requirements)? Its a multi-purpose integer arithmetic library!

0
source

All Articles