# Questions tagged [vectorization]

Use this tag if your code contains vectorized operations - where functions operate on whole arrays in one go. If it doesn't, but you want it to, then you should make those changes (perhaps with help from elsewhere) before presenting code for review.

101 questions
Filter by
Sorted by
Tagged with
2k views

### My blit function for my own graphics library

Here is a blit function for a graphics library I made. I've built a small graphics library that uses an palette-indexed spritesheet to hold all of the game's sprites. The blit function copies parts of ...
580 views

### AVX Vectorized Multi-threaded Mandelbrot Renderer

I wrote a Mandelbrot renderer in C++ that uses AVX intrinsics to calculate 8 pixels per thread in parallel. It can compute 1080p frames with 256 max iterations in about 40 milliseconds on a 2 core 4 ...
• 211
320 views

### Calculate the closest point to many hyperbolic paraboloids

In this question I asked for a way to compute the closest projected point to a hyperbolic paraboloid using python. Using the iterative approximation answer, I'm able to use the code below to ...
• 383
2k views

### Vectorized and Multi Threaded Image Convolution

I created code for Image Convolution. The code is in my Image Convolution GitHub Repository. It includes the case for arbitrary Image Convolution and for Separable Kernel Convolution. The code is a ...
• 582
370 views

### N-Body Optimization

I've created a serial C++ code for gravitational N-Body calculation. Because I expect to have upwards of 8-71 sparse bodies (ie, where Barnes-Hut is not necessarily practical) and running for long ...
615 views

### Vectorizing the product of an array of complex numbers

I am trying to write fast/optimal code to vectorize the product of an array of complex numbers. In simple C this would be: ...
• 191
19k views

### Efficient element-wise function computation in Python

I have the following optimization problem: Given two np.arrays X,Y and a function K I ...
• 91
163 views

### Matlab Computer Vision

The code below takes a video as input (a drop onto a fabric surface) and I want it to return the area of the drop. Currently the code works, but I'm no Matlab expert, and wrote it entirely through ...
2k views

### Vectorized numpy version of arange with multiple start stop

Given a single start and stop, numpy.arange is a good solution for building a NumPy array of evenly spaced values. However, given an array of start and an array of ...
• 215
344 views

### Improving Matlab function within big simulation

I have a very big Matlab simulation project in my hands, which I wanted to optimize, since I'm running it many times to tune parameters and the like. Using Matlab's ...
4k views

### Rolling regressions in R

I want to run rolling regressions over each group and store the coefficient. The following works, but it's slow, since I have too many series and I want to run too many regressions for each group. ...
• 173
954 views

### Implementation of linear regression in Python

I wrote an implementation for multivariate linear regression in Python, for data in this link: http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv My main focus is to avoid loops as much as possible ...
• 339
3k views

### Converting Array of Floats to UINT8 (char) or UINT16 (unsigned short) Using SSE4

The problem is given image in 32 Bit Floating Point Format (float) how to convert it to UINT8 (char) or UNIT16 (...
• 582
8k views

### Remove duplicates in list of lists where an item in each list is ignored when determining duplicity

I have lines_list_copy of the form: [['a1', 'b1', 'c1', 'd1', 'e1'], ['a2', 'b2', 'c2', 'd2', 'e2'], ... ] I needed to ...
• 203
156 views

### Catalogue manipulation

I have a catalogue of 56000 objects and I want to replace some columns with new values for instance replace NaN with -99 and <...
• 133
2k views

### Merging overlapping/intersecting string vectors

I am trying to merge overlapping/intersecting sets given as a list of string vectors below in R (my actual data set has thousands of such sets). The overlap/intersection is based on the ...
• 173
8k views

### Compute a numerical derivative

Since I could not get numpy.gradient() to compute a derivative successfully, I wrote a script to compute it manually. Running the script below will output a plot of ...
3k views

### Remove outliers from a point cloud

This function accepts a cloud of points, and returns those points that are within delta distance of the average (mean) position. ...
293 views

### How to make my groupby and transpose operations efficient?

I have a DataFrame of size 3,745,802 rows and 30 columns. I would like to perform certain groupby and ...
• 237
121 views

### Calculating parking and charging statistics for a car-sharing service

I am looking for help in designing my code more efficiently and also in keeping the slope of my personal learning curve steep: For a research project I have per car data from two different car ...
• 61
389 views

### C# Generic high performance vectorized math operations

I'm writing a library which simplifies the usage of intrinsics in C#. It's a generic library which supports all numeric types. The goal of this library is to perform these operations at the highest ...
492 views

### Vectorize Matlab sum

I have the following Matlab function: function [res] = a3_funct(x) res = 0; for i = 1:size(x,1) res = res + abs(x(i))^(i+1); end end It's ...
• 1,527
560 views

### Jacobian product

Do you have in mind a way to compute the following sum $$R_{i,j,k} = \sum_{l=0}^{2} J_{i,j,l+3k} v_{i,j,l}$$ obviously in a vectorised fashion? This may sound like an equivalent of: ...
144 views

### Vector comparison inside for-loop

The following code finds no-rain periods in a time series that were preceded by rain over a threshold (e.g. 10mm in 2 days [k=48]). ...
• 153
97 views

### Extract the largest value for each day from a matrix

I have a matrix in which the right-most elements are repeated YYYYMMDD dates in descending order, for example: ...
• 2,057
2k views

• 197
68 views

### Determining whether a list of pathways and its genes are all included in another list

I am evaluating if a list of pathways and its genes has pathways included in another pathways. So the way I thought about it is to create a function that does just a single comparison. ...
• 281