Share Your Experience: Take the 2024 Developer Survey

# Questions tagged [vectorization]

For questions about converting multiple operations a single "vectorized" operation. Example questions might include how to alter code to ensure certain "vectorized" instructions are used.

22 questions
Filter by
Sorted by
Tagged with
12k views

### Octave: calculate distance between two matrices of vectors

Suppose I have two matrices Nx2, Mx2 representing N, M 2d vectors respectively. Is there a simple and good way to calculate distances between each vector pair (n, m)? The easy but inefficient way is ...
5k views

### How do I know if my code is being vectorized by the compiler?

As exemplified by Jed Brown's answer to Costs of lookups versus calculations, using vectorized vs non-vectorized floating point operations results in much faster code. Many modern compilers claim ...
• 2,076
1k views

### How do I vectorize this 4-D matrix operation in Matlab?

I need to do a large number of matrix operations in Matlab, but one of the matrices is 4-D and my normal instincts for correct vectorization are failing me. Right now I'm using a loop. Maybe somebody ...
• 285
1k views

### Why do libraries need hand-vectorized code instead of compiler auto vectorization

C++ eigen library does vectorization for different architecture, like SSE, NEON etc. In their documentation they mentioned that, Eigen vectorization is not compiler dependent. But most modern ...
• 153
1k views

### Compiled c++ code runs much faster with double than float. Explanation?

I am still rather new on here and I hope question is suitable for this forum otherwise please help me migrate it to greener pastures. I am an electrical engineer specializing in applying mathematics ...
• 380
598 views

### Manipulating Matrices in Matlab

Suppose I have a matrix $A$ of size $n_1 \times n_2 \times n_3$ Now, I have another matrix $B$ of size $n_1 \times n_2 \times n_3 \times N$ where $N<n_3$ I'd like to create the following matrix ...
403 views

### Fast way to repeatedly solve a small nonlinear equation system

A small nonlinear equation system (sizes around 12 ✕ 12) needs to be solved repeatedly (millions of times); each time with some variation in parameters/coefficients (although the equation set is ...
• 149
1k views

### Why is SIMD programming on such a low level in CPU's compared to GPU's?

Just speaking from my experience in c++ - Its really tricky to take advantage of the SIMD capabilities of modern CPU's for more complex algorithms. If I see an opportunity from a high level OO ...
2k views

### integral including a vector

I need to calculate the integral of this function def f(z): return ((1-2*z)*np.exp(-d/z))/(((1-z)**(2+d))*(z**(2-d))) Here d is a constant. I am using this ...
• 163
2k views

### Vectorize a part of a huge matrix in C++

I have a large matrix, side-length is about $n\geq 1000$. I need to do element-wise multiplication of this matrix with another matrix many, many times. I make this process by: Vectorizing (through ...
2k views

### Vectorised second order ode solving in python

I am trying to write a python program that simulates the motion of a large number of particles by numerically integrating a second order ordinary differential equation. I first split the ODE into two ...
81 views

### Solving tridiagonal Toeplitz system using SIMD instructions

I need to solve many small Toeplitz systems that fit entirely in cache, meaning the computation is compute bound. Are there vectorizable algorithms for this? I found a few older articles: (https://www....
• 21
1 vote
278 views

### How to vectorize 2 nested for loop with one complex condition in the inner loop?

Octave calculations is too slow specially when you deal with scientific calculations that can span a very very large matrix, even just iterating. I have to vectorize it to speed up the calculation. ...
• 113
1 vote
129 views

### What exactly is Hardware Acceleration?

I'm able to find many definitions and notions to this term including, Implementing the algorithm (or part of it) in hardware :- Instructions like FMAD; FPGAs Parallelizing the algorithm at the ...
• 287
1 vote
47 views

### Converting an expression into an einsum

I have the following expression that I need to calculate for some matrices: $$\sum_{k}c_{t,i,k}\sigma^\prime\left(w_tX_t+b_t\right)_k\left(\sum_\ell w_{t,k,\ell}\tilde{X}_t^{w,\ell}\right)$$ I could,...
• 111
1 vote
66 views

### Help with vectorized computation where vector multiplication would need to create an additional dimension

I want to use vectorized computation (with python and numpy) to do some calculation involving bessel functions. As is often the case, I need to calculate the sums of bessel functions of (infinit) ...
1 vote
347 views

### Vectorize function integration

I need to implement the following in python: For a given discrete time series $Z_t$ ($t={0...T}$), find the smallest $t$ such that: $$c\sum_{s=0}^t e^{[k(Z_t-Z_s)+m(t-s)]} \geq \frac{p^*}{1-p^*}$$ ...
• 163
356 views

### How to compare 2D vector fields and minimize the difference?

I want to compare the field of two electrical currents and compare the resulting field to a magnetic dipol field and find magnetic momentum that minimizes the difference of the two fields. My current ...
56 views

### Vectorization Algorithm using only rectangle

As stated in the title I have a raster image (black or white) with no complex or fuzzied components (only horizontal or vertical text, italic or bold are allowed). I need to express that raster image ...
• 101
336 views

### quiver3 gives non-conformant arguments?

Does anyone know why I'm seeing these errors? I'm not giving it a matrix. ...
• 101