optimization

Optimising an 1D heat equation using SIMD

久未见 提交于 2020-01-13 05:35:11
问题 I am using a CFD code (for computational fluid dynamic). I recently had the chance to see Intel Compiler using SSE in one of my loops, adding a nearly 2x factor to computation performances in this loop. However, the use of SSE and SIMD instructions seems more like luck. Most of the time, the compiler do nothing. I am then trying to force the use of SSE, considering that AVX instructions will reinforce this aspect in the near future. I made a simple 1D heat transfer code. It consist of two

Super Ugly Number

五迷三道 提交于 2020-01-13 05:25:27
问题 So the problem is: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4. So my algorithm basically finds all possible factors using the pattern they follow, pushes them to an array, sorts that array and then returns the nth value in the

subset of data.frame columns to maximize “complete” observations

自作多情 提交于 2020-01-13 05:17:27
问题 I have a data frame with on the order of 20 numeric columns, each containing significant amounts of NA values. I would like to select a subset of these columns that will give me the most rows containing zero NA values. An exhaustive search would take a lot of computing time--is there a better way to get an approximation? Here is an example with a smaller data frame (completely arbitrary): set.seed(2) foo = as.data.frame(matrix(rnorm(200), nr = 20)) foo[sapply(foo, function(x) x > abs(x[1]))]

Efficiently counting numbers falling within each range of numbers

最后都变了- 提交于 2020-01-13 03:44:47
问题 I'm looking for a faster solution to the problem below. I'll illustrate the problem with a small example and then provide the code to simulate a large data as that's the point of this question. My actual problem size is of list length = 1 million entries. Say, I've two lists as shown below: x <- list(c(82, 18), c(35, 50, 15)) y <- list(c(1,2,3,55,90), c(37,38,95)) Properties of x and y: Each element of the list x always sums up to 100. Each element of y will always be sorted and will be

Optimization problem - finding a maximum

别来无恙 提交于 2020-01-13 03:37:48
问题 I have a problem at hand which can be reduced to something like this : Assume a bunch of random points in a two-dimension plane X-Y where for each Y, there could be multiple points on X and for each X, there could be multiple points on Y. Whenever a point (Xi,Yi) is chosen, no other point with X = Xi OR Y = Yi can be chosen. We have to choose the maximum number of points. 回答1: This can be reduced to simple maximum flow problem. If you have a point (xi, yi), in graph it should be represented

Two-letter Variable Names in Javascript?

◇◆丶佛笑我妖孽 提交于 2020-01-13 03:20:13
问题 I was looking at an answer to an SO question today where the variable names are ua, rv, etc. And I thought, "Man, when will people learn to use full-size variable names, memory is not a problem any more" but then, it is Javascript so it has to come across the wire and perhaps long variable names even slow down interpretation. Is using short variable names in Javascript premature optimization? While I'm here, are there any libraries for Rails or PHP that will compress Javscript on the fly, so

what is the importance of crossing over in Differential Evolution Algorithm?

梦想的初衷 提交于 2020-01-13 02:43:15
问题 In Differential Evolution Algorithm for optimization problems. There are three evolutionary processes involved, that is mutation crossing over and selection I am just a beginner but I have tried removing the crossing over process and there is no significant difference result from the original algorithm. So what is the importance of crossing over in Differential Evolution Algorithm? 回答1: If you don't use crossover may be your algorithm just explore the problem search space and doesn't exploit

C coding practices for performance or code size - beyond what a compiler does

我的梦境 提交于 2020-01-13 01:30:02
问题 I'm looking to see what can a programmer do in C, that can determine the performance and/or the size of the generated object file. For e.g, 1. Declaring simple get/set functions as inline may increase performance (at the cost of a larger footprint) 2. For loops that do not use the value of the loop variable itself, count down to zero instead of counting up to a certain value etc. It looks like compilers now have advanced to a level where "simple" tricks (like the two points above) are not

C coding practices for performance or code size - beyond what a compiler does

别说谁变了你拦得住时间么 提交于 2020-01-13 01:29:13
问题 I'm looking to see what can a programmer do in C, that can determine the performance and/or the size of the generated object file. For e.g, 1. Declaring simple get/set functions as inline may increase performance (at the cost of a larger footprint) 2. For loops that do not use the value of the loop variable itself, count down to zero instead of counting up to a certain value etc. It looks like compilers now have advanced to a level where "simple" tricks (like the two points above) are not

Most efficient way to find if a string is mixedCase

≡放荡痞女 提交于 2020-01-12 21:56:12
问题 Suppose I have very long strings and I want to see if a column is allLower, allUpper, or mixedCase. For example with the following column text "hello" "New" "items" "iTem12" "-3nXy" The text would be mixedCase . A naive algorithm to determine this might be: int is_mixed_case, is_all_lower, is_all_upper; int has_lower = 0; int has_upper = 0; // for each row...for each column... for (int i = 0; (c=s[i]) != '\0'; i++) { if (c >='a' && c <= 'z') { has_lower = 1; if (has_upper) break; } else if (c