optimization

Generating LinqToEntities Where statement depending on the user selection

吃可爱长大的小学妹 提交于 2020-01-02 20:14:32
问题 I have user-interface where user can select grid column (like age) and operator (lesser than, equals or greater than) for that column. Grid data is then filtered according to the selection. I have a following classes that are deserialized from the JSON that is coming from the client. /// <summary> /// Filter for reducing grid results /// </summary> public class Filter { /// <summary> /// Name of the column /// </summary> public string name; public string value; public int @operator { private

Numpy fastest 3D to 2D projection

℡╲_俬逩灬. 提交于 2020-01-02 13:58:12
问题 I have a 3D array of binary data. I want to project this to 3 2D images - side on, head on, birds eye. I have written the code: for x in range(data.shape[2]): for y in range(data.shape[0]): val = 0 for z in range(data.shape[1]): if data[y][z][x] > 0: val = 255 break side[y][x] = val But this is horrifically slow (75s!) for a ~700x300x300 matrix. What is the fastest way of achieving this task? EDIT: To save the image, I have used: sideImage = Image.fromarray(side) sideImage.convert('RGB').save

Numpy fastest 3D to 2D projection

喜你入骨 提交于 2020-01-02 13:57:50
问题 I have a 3D array of binary data. I want to project this to 3 2D images - side on, head on, birds eye. I have written the code: for x in range(data.shape[2]): for y in range(data.shape[0]): val = 0 for z in range(data.shape[1]): if data[y][z][x] > 0: val = 255 break side[y][x] = val But this is horrifically slow (75s!) for a ~700x300x300 matrix. What is the fastest way of achieving this task? EDIT: To save the image, I have used: sideImage = Image.fromarray(side) sideImage.convert('RGB').save

Fastest way to write to multiple socket connections

橙三吉。 提交于 2020-01-02 12:04:27
问题 I am using the following class to accept incoming connections from client applications - using the send function I want to write the same UTFBytes to each client at the same time - is this possible? or if not, what would be the fastest way to write to them sequentially. public class ProjectorClients { private var _serverSocket:ServerSocket; private var _clients:Vector.<Socket> = new Vector.<Socket>; private function ProjectorClients():void { _serverSocket = new ServerSocket(); _serverSocket

MySQL: Optimization GROUP BY multiple keys

旧时模样 提交于 2020-01-02 10:26:13
问题 I have a table PAYMENTS in MySql database: CREATE TABLE `PAYMENTS` ( `ID` BIGINT(20) NOT NULL AUTO_INCREMENT, `USER_ID` BIGINT(20) NOT NULL, `CATEGORY_ID` BIGINT(20) NOT NULL, `AMOUNT` DOUBLE NULL DEFAULT NULL, PRIMARY KEY (`ID`), INDEX `PAYMENT_INDEX1` (`USER_ID`), INDEX `PAYMENT_INDEX2` (`CATEGORY_ID`), INDEX `PAYMENT_INDEX3` (`CATEGORY_ID`, `USER_ID`) ) ENGINE=InnoDB; I want to get summary amount for each user in ech category. Here is script: select sum(AMOUNT), USER_ID, CATEGORY_ID from

ZeroMemory in SSE

孤街醉人 提交于 2020-01-02 09:19:32
问题 I need simple ZeroMemory implementation with SSE (SSE2 prefered) Can someone help with that. I was serching thru SO and net but not found direct answer to that. 回答1: Is ZeroMemory() or memset() not good enough? Disclaimer: Some of the following may be SSE3. Fill any unaligned leading bytes by looping until the address is a multiple of 16 push to save an xmm reg pxor to zero the xmm reg While the remaining length >= 16, movdqa or movntdq to do the write pop to restore the xmm reg. Fill any

error message when trying to minimize a function with scipy using jacobian

青春壹個敷衍的年華 提交于 2020-01-02 09:10:58
问题 Using Python 3.6, I am trying to minimize a function using scipy.optimize.minimize . My minimization problem as two constraints, and I can find a solution. So far, I have the following: import numpy as np from scipy.optimize import minimize array = np.array([[3.0, 0.25, 0.75], [0.1, 0.65, 2.50], [0.80, 2.5, 1.20], [0.0, 0.25, 0.15], [1.2, 2.40, 3.60]]) matrix = np.array([[1.0, 1.5, -2.], [0.5, 3.0, 2.5], [1.0, 0.25, 0.75]]) def fct1(x): return -sum(x.dot(array.T)) def fct2(x): return x.dot

How could this Java code be sped up?

半城伤御伤魂 提交于 2020-01-02 07:58:32
问题 I am trying to benchmark how fast can Java do a simple task: read a huge file into memory and then perform some meaningless calculations on the data. All types of optimizations count. Whether it's rewriting the code differently or using a different JVM, tricking JIT .. Input file is a 500 million long list of 32 bit integer pairs separated by a comma. Like this: 44439,5023 33140,22257 ... This file takes 5.5GB on my machine. The program can't use more than 8GB of RAM and can use only a single

C++ Exception Throw/Catch Optimizations

我的未来我决定 提交于 2020-01-02 07:58:07
问题 It seems to me that if you have some C++ code like this: int f() { try { if( do_it() != success ) { throw do_it_failure(); } } catch( const std::exception &e ) { show_error( e.what() ); } } The C++ compiler should be able to optimize the throw and catch into almost a simple goto. However, it seems to me from my experience viewing disassembly and stepping through code that the compilers always jump through the very messy exception handling libraries. Why do they do that? Is there some language

Cache friendly offline random read

一世执手 提交于 2020-01-02 07:51:07
问题 Consider this function in C++: void foo(uint32_t *a1, uint32_t *a2, uint32_t *b1, uint32_t *b2, uint32_t *o) { while (b1 != b2) { // assert(0 <= *b1 && *b1 < a2 - a1) *o++ = a1[*b1++]; } } Its purpose should be clear enough. Unfortunately, b1 contains random data and trash the cache, making foo the bottleneck of my program. Is there anyway I can optimize it? This is an SSCCE that should resemble my actual code: #include <iostream> #include <chrono> #include <algorithm> #include <numeric>