vectorization

Is it possible that F# will be optimized more than other .Net languages in the future?

Is it possible that Microsoft will be able to make F# programs, either at VM execution time, or more likely at compile time, detect that a program was built with a functional language and automatically parallelize it better? Right now I believe there is no such effort to try and execute a program that was built as single threaded prog...

Turning a matlab binary matrix into a vector of the last nonzero index in a fast, vectorized fashion

Suppose, in Matlab, that I have a matrix, A, whose elements are either 0 or 1. How do I get a vector of the index of the last non-zero element of each column in a faster, vectorized way? I could do [B, I] = max(cumsum(A)); and use I, but is there a faster way? (I'm assuming cumsum would cost a bit of time even suming 0's and 1's). ...

matlab Bucketing Algorithm Help

I've got some code that works, but is a bit of a bottleneck, and I'm stuck trying to figure out how to speed it up. It's in a loop, and I can't figure how to vectorize it. I've got a 2D array, vals, that represents timeseries data. Rows are dates, columns are different series. I'm trying to bucket the data by months to perform variou...

Resources for (Manual and Automatic) Loop Vectorization

I see some resources for gcc, but not for Visual Studio. Anyone have a treasure trove of references, examples and tricks? ...

MATLAB: split long 2D matrix into the third dimension

Say I have the following matrix: A = randi(10, [6 3]) 7 10 3 5 5 7 10 5 1 6 5 10 4 9 1 4 10 1 And I would like to extract each 2 rows and put them into the third dimension, so the result would be like: B(:,:,1) = 7 10 3 5 5 7 B(:,:,2) =...

What is "vectorization" ?

Several times now, I've encountered this term in matlab, fortran ... some other ... but I've never found an explanation what does it mean, and what it does? So I'm asking here, what is vectorization, and what does it mean for example, that "a loop is vectorized" ? ...

What is the maximum theoretical speed-up due to SSE for a simple binary subtraction?

In trying to figure out whether or not my code's inner loop is hitting a hardware design barrier or a lack of understanding on my part barrier. There's a bit more to it, but the simplest question I can come up with to answer is as follows: If I have the following code: float px[32768],py[32768],pz[32768]; float xref, yref, zref, delta...

What does vectorization mean?

Is it a good idea to vectorize the code? What are good practices in terms of when to do it? What happens underneath? ...

MATLAB: vectorized assignment from double array to cell array

I have three arrays, all the same size: xout % cell array xin % numeric array of doubles b % logical array How can I take the elements of xin that correspond to the indices where b is true, and assign them to the corresponding places in xout? >> xout = {'foo', 'bar', 'baz', 'quux'}; >> xin = [1, 2, 3, 4]; >> ...

Loop versioning with GCC

I am working on auto vectorization with GCC. I am not in a position to use intrinsics or attributes due to customer requirement. (I cannot get user input to support vectorization) If the alignment information of the array that can be vectorized is unknown, GCC invokes a pass for 'loop versioning'. Loop versioning will be performed when ...

How to generate a function of two variables in matlab without using any loop?

Suppose I have a function y(t,x) = exp(-t)*sin(x) In Matlab, I define t = [0: 0.5: 5]; x = [0: 0.1: 10*2*pi]; y = zeros(length(t), length(x)); % empty matrix init Now, how do I define matrix y without using any loop, such that each element y(i,j) contains the value of desired function y at (t(i), x(j))? Below is how I did it using a ...

C++ STL data structure alignment, algorithm vectorization.

Hello Is there a way to enforce STL container alignment to specific byte, using attribute((aligned))perhaps? the target compilers are not Microsoft Visual C++. What libraries, if any, provide specialized templates of STL algorithms which have specific explicit vectorization, e.g. SSE. My compilers of interest are g++, Intel, and IBM X...

MATLAB: convert vector to cell array

I have a column vector I want to convert to a cell array such as: A = rand(10,1); B = cell(10,1); for i=1:10 B{i} = A(i); end B = [0.6221] [0.3510] [0.5132] [0.4018] [0.0760] [0.2399] [0.1233] [0.1839] [0.2400] [0.4173] How can I do this without an explicit for loop? I tried: B{:} = A(:)...

Mapping 2 vectors - help to vectorize

Working in Matlab I have 2 vectors of x coordinate with different length. For example: xm = [15 20 24 25 26 35 81 84 93]; xn = [14 22 26 51 55 59 70 75 89 96]; I need to map xm to xn, or in other words to find which coordinates in xn are closest to xm. So if I have values associated with those coordinates, I can use this map as index ...

How do I compare all elements of two arrays in MATLAB?

I have two big arrays with about 1000 rows and 1000 columns. I need to compare each element of these arrays and store 1 in another array if the corresponding elements are equal. I can do this with for loops but that takes a long time. How can I do this faster? ...

MATLAB: comparing all elements of two arrays

I have two matrices in MATLAB lets say arr1 and arr2 of size 1000*1000 each. I want to compare their elements and save the comparison in a result matrix resarr which is also 1000*1000 such that for each element: if the element in arr1 is bigger than the one in arr2, place the value 1 in the result if the element in arr2 is bigger, stor...

Vectorizing for loops in Matlab

I'm not too sure if this is possible, but my understanding of Matlab could certainly be better. I have some code I wish to vectorize as it's causing quite a bottleneck in my program. It's part of an optimisation routine which has many possible configurations of Short Term Average (STA), Long Term Average (LTA) and Sensitivity (OnSense) ...

What's the correct syntax for applying a function to sub elements of a matrix without using a loop?

I have a defined a function (GetDepth) which does something fairly trivial, eg takes in a 2x4 matrix and outputs a 2x1 matrix. I then have an 2x4xn matrix I want to apply it to, and I'm expecting an 2x1xn matrix result. What is the correct syntax to apply my function to the matrix without resorting to using a loop? ed. As requested, h...

MATLAB: compute mean of each 1-minute interval of a time-series

I have a bunch of times-series each described by two components, a timestamp vector (in seconds), and a vector of values measured. The time vector is non-uniform (i.e. sampled at non-regular intervals) I am trying to compute the mean/SD of each 1-minutes interval of values (take X minute interval, compute its mean, take the next interva...

Mean filter in MATLAB without loops or signal processing toolbox

I need to implement a mean filter on a data set, but I don't have access to the signal processing toolbox. Is there a way to do this without using a for loop? Here's the code I've got working: x=0:.1:10*pi; noise=0.5*(rand(1,length(x))-0.5); y=sin(x)+noise; %generate noisy signal a=10; %specify moving window siz...