Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Element-wise vector comparison

$
0
0

Hi,

I have a huge mxn matrix A where I need to compute A(i,j) > 0, ie. 1 for all values which are positive, and 0 otherwise

I would be better off writing it in C++, but let's assume I'm in a situation where I don't have admin rights and cannot install/compile anything. I'm using a single-threaded scripting language (VBA) to wrap calls to mkl_rt.dll, and any combination of MKL functions is still faster.

One way to solve this is to compute 1-0^(x+abs(x)), ie something like

    vdabs m*n, A(1, 1), temp(1, 1)
    vdadd m*n, A(1, 1), temp(1, 1), temp(1, 1)
    vdpow m*n, res(1, 1), temp(1, 1), res(1, 1)  /***** (res() is an array full of zeros)
    vdlinearfrac m*n, res(1, 1), res(1, 1), 0, -1, 0, 1, res(1, 1)

But the vdpow function is quite costly computation-wise (overall speed difference is ca x4 in favor of mkl, but I expect more from one single thread in VBA vs compiled multi-threaded code)

Another solution is to find the maximum value in the array, divide by max+1 to force all values into <-1, 1> and apply vdceil, <-1, 0] becomes 0, and <0, 1> becomes 1, but there can be some problems if the numbers are huge and end up as [-1, 1]

Can anyone think of a simpler way to do it?


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>