vectorization

Vectorizing NumPy covariance for 3D array

最后都变了- 提交于 2020-06-06 08:12:08
问题 I have a 3D numpy array of shape (t, n1, n2) : x = np.random.rand(10, 2, 4) I need to calculate another 3D array y which is of shape (t, n1, n1) such that: y[0] = np.cov(x[0,:,:]) ...and so on for all slices along the first axis. So, a loopy implementation would be: y = np.zeros((10,2,2)) for i in np.arange(x.shape[0]): y[i] = np.cov(x[i, :, :]) Is there any way to vectorize this so I can calculate all covariance matrices in one go? I tried doing: x1 = x.swapaxes(1, 2) y = np.dot(x, x1) But

Compare multiple pandas columns (1st and 2nd, after 3rd and 4rth, after etc) with vectorization (better) or other method

牧云@^-^@ 提交于 2020-05-17 07:41:08
问题 This code compares based on condition the var1 and var2 and creates Results1 based on choices (this code works well): # from: https://stackoverflow.com/questions/27474921/compare-two-columns-using-pandas?answertab=oldest#tab-top # from: https://stackoverflow.com/questions/60099141/negation-in-np-select-condition import pandas as pd import numpy as np # Creating one column from two columns. We asume that in every row there is one NaN and one value and that value fills new column. df = pd

Can't use jdk.incubator.vector classes in BigInteger

[亡魂溺海] 提交于 2020-05-15 07:44:42
问题 I'm trying to use the Java Vector API from the Panama project to add some SIMD code to the java.math.BigInteger class. I cloned the Panama repo and built a JDK: hg clone http://hg.openjdk.java.net/panama/dev/ cd dev/ hg checkout vectorIntrinsics hg branch vectorIntrinsics bash configure make images I was able to compile and run a simple little program that uses the vector API: import static jdk.incubator.vector.Vector.Shape.S_256_BIT; import jdk.incubator.vector.IntVector; import static jdk

Can't use jdk.incubator.vector classes in BigInteger

隐身守侯 提交于 2020-05-15 07:44:25
问题 I'm trying to use the Java Vector API from the Panama project to add some SIMD code to the java.math.BigInteger class. I cloned the Panama repo and built a JDK: hg clone http://hg.openjdk.java.net/panama/dev/ cd dev/ hg checkout vectorIntrinsics hg branch vectorIntrinsics bash configure make images I was able to compile and run a simple little program that uses the vector API: import static jdk.incubator.vector.Vector.Shape.S_256_BIT; import jdk.incubator.vector.IntVector; import static jdk

How to vectorize and optimize this functions in C?

十年热恋 提交于 2020-05-09 09:56:58
问题 I have this functions, the result is correct but the compiler don't vectorize this. How can I achive that the compiler vectorize this and how can I optimize this codes? void LongNumSet( char *L, unsigned N, char digit ) { for (int i = 0; i < N; ++i){ L[i] = digit; } } void LongNumCopy( char *Vin, char *Vout, unsigned N ) { for ( int i=0; i< N; ++i ) { Vout[i] = Vin[i]; } } char LongNumAddition( char *__restrict Vin1, char * __restrict Vin2, char * __restrict Vout, unsigned N ) { char CARRY =

How to vectorize and optimize this functions in C?

淺唱寂寞╮ 提交于 2020-05-09 09:55:28
问题 I have this functions, the result is correct but the compiler don't vectorize this. How can I achive that the compiler vectorize this and how can I optimize this codes? void LongNumSet( char *L, unsigned N, char digit ) { for (int i = 0; i < N; ++i){ L[i] = digit; } } void LongNumCopy( char *Vin, char *Vout, unsigned N ) { for ( int i=0; i< N; ++i ) { Vout[i] = Vin[i]; } } char LongNumAddition( char *__restrict Vin1, char * __restrict Vin2, char * __restrict Vout, unsigned N ) { char CARRY =

How to vectorize a function that uses both row and column elements of a dataframe

拜拜、爱过 提交于 2020-04-30 11:24:44
问题 I have two inputs in a dataframe, and I need to create an output that depends on both inputs (same row, different columns), but also on its previous value (same column, previous row). This dataframe command will create an example of what I need: df=pd.DataFrame([[0,0,0], [0,1,0], [0,0,0], [1,1,1], [0,1,1], [0,1,1], [0,0,0], [0,1,0], [0,1,0], [1,1,1], [1,1,1], [0,1,1], [0,1,1], [1,1,1], [0,1,1], [0,1,1], [0,0,0], [0,1,0]], columns=['input_1', 'input_2', 'output']) The rules are simple: If

How to vectorize a function that uses both row and column elements of a dataframe

戏子无情 提交于 2020-04-30 11:23:49
问题 I have two inputs in a dataframe, and I need to create an output that depends on both inputs (same row, different columns), but also on its previous value (same column, previous row). This dataframe command will create an example of what I need: df=pd.DataFrame([[0,0,0], [0,1,0], [0,0,0], [1,1,1], [0,1,1], [0,1,1], [0,0,0], [0,1,0], [0,1,0], [1,1,1], [1,1,1], [0,1,1], [0,1,1], [1,1,1], [0,1,1], [0,1,1], [0,0,0], [0,1,0]], columns=['input_1', 'input_2', 'output']) The rules are simple: If

How do I efficiently lookup 16bits in a 128bit SIMD vector? [duplicate]

耗尽温柔 提交于 2020-04-30 06:29:30
问题 This question already has answers here : SSE/SIMD shift with one-byte element size / granularity? (2 answers) How do I vectorize data_i16[0 to 15]? (1 answer) Closed 3 days ago . I'm trying to implement the strategy described in an answer to How do I vectorize data_i16[0 to 15]? Code below. The spot I'd like to fix is the for(int i=0; i<ALIGN; i++) loop I'm new to SIMD. From what I can tell I'd load the high/low nibble table by writing const auto HI_TBL = _mm_load_si128((__m128i*)HighNibble)

Vectorize/accelerate numpy function with two arguments of different dimensions

ⅰ亾dé卋堺 提交于 2020-04-22 02:15:48
问题 I am not sure if this has been asked before. I couldn't find many relevant results on SO or Google. Anyway, here is what I am trying to do. I have a function that is created at runtime which takes in 4 parameters. my_func(t, x, p, a) t is a scalar float. x is a 1D numpy array of floats. p and a are dictionaries. I have a numpy array T and a 2D numpy array X. I want to call the function with each element of T and each column of X and store the result in another numpy array. The function