optimization

Sum of primes below 2,000,000 in python

烂漫一生 提交于 2021-02-04 14:08:24
问题 I am attempting problem 10 of Project Euler, which is the summation of all primes below 2,000,000. I have tried implementing the Sieve of Erasthotenes using Python, and the code I wrote works perfectly for numbers below 10,000. However, when I attempt to find the summation of primes for bigger numbers, the code takes too long to run (finding the sum of primes up to 100,000 took 315 seconds). The algorithm clearly needs optimization. Yes, I have looked at other posts on this website, like

Sum of primes below 2,000,000 in python

╄→гoц情女王★ 提交于 2021-02-04 14:08:12
问题 I am attempting problem 10 of Project Euler, which is the summation of all primes below 2,000,000. I have tried implementing the Sieve of Erasthotenes using Python, and the code I wrote works perfectly for numbers below 10,000. However, when I attempt to find the summation of primes for bigger numbers, the code takes too long to run (finding the sum of primes up to 100,000 took 315 seconds). The algorithm clearly needs optimization. Yes, I have looked at other posts on this website, like

Is a program compiled with -g gcc flag slower than the same program compiled without -g?

你。 提交于 2021-02-04 09:25:52
问题 I'm compiling a program with -O3 for performance and -g for debug symbols (in case of crash I can use the core dump). One thing bothers me a lot, does the -g option results in a performance penalty? When I look on the output of the compilation with and without -g, I see that the output without -g is 80% smaller than the output of the compilation with -g. If the extra space goes for the debug symbols, I don't care about it (I guess) since this part is not used during runtime. But if for each

How could I optimise this simple python pygame code

为君一笑 提交于 2021-02-04 08:14:08
问题 I've been set a challenge to make a game using pygame ( I am making snake so it should be easy... but I've never used pygame) so using a more efficient language isn't an option.So my question is that I updating the snake grid is too slow and I'm not experienced enough in pygame to fix this, can anyone who is help.Also as a note if I only fill the grid it doesn't clear behind the Snake. Using python 3.8 import pygame import time import random pygame.init() display_width = 800 display_height =

Make gcc use conditional moves

家住魔仙堡 提交于 2021-02-04 03:39:58
问题 Is there a gcc pragma or something I can use to force gcc to generate branch-free instructions on a specific section of code? I have a piece of code that I want gcc to compile to branch-free code using cmov instructions: int foo(int *a, int n, int x) { int i = 0, j = n; while (i < n) { #ifdef PREFETCH __builtin_prefetch(a+16*i + 15); #endif /* PREFETCH */ j = (x <= a[i]) ? i : j; i = (x <= a[i]) ? 2*i + 1 : 2*i + 2; } return j; } and, indeed, it does so: morin@soprano$ gcc -O4 -S -c test.c -o

Scipy minimisation optimisation row-wise on DataFrame

不羁岁月 提交于 2021-01-29 18:41:12
问题 TYPO FIXEDD I need to perform a minimization optimisation for each timestep in my timeseries. The optimisation sets the price based on values in different columns across the row and a series of inequality constraints. My Dataframe has the following columns across time series of 48 years: ['CAPEX_TOT', 'CAPEX_R', 'CAPEX_WS', 'debt_BP', 'principal','interest', 'debt_service', 'debt_EP', 'OPEX', 'OPEX_R', 'OPEX_WS', 'DELIVERY_BAWSCA', 'DELIVERY_OTHER_DEMAND', 'DELIVERY_SAN_FRANCISCO_CITY',

SCIP Objective Function quicksum over a exponential term

送分小仙女□ 提交于 2021-01-29 17:22:03
问题 I am having issues summing over an exponential equation and using this as is the objective function. Am I able to use the exponential equation in the objective function? If not, is it possible to put the exponential function in as a constraint? Any help on this would be appreciated. import pandas as pd from pyscipopt import Model, quicksum, multidict, exp num_fac_to_open = 1 order_to_open = [] opened_fac = [] closed_fac = [0, 1, 2] S = [0, 1, 2] R = [10, 11, 12] distance_dict = {(0, 10): 300

fortran matrix vector multiplication optimization

為{幸葍}努か 提交于 2021-01-29 16:30:58
问题 I tried to measure the difference of different matrix-vector-multiplication schemes in Fortran. I have actually written the following code: http://pastebin.com/dmKXdnX6 The 'optimized version' is meant to respect the memory layout of the matrix, by swapping the loops to access the matrix-elements. The provided code should compile with gfortran and it runs with the following rather surprising results: Vectors match! Calculations are OK. Optimized time: 0.34133333333333332 Naive time: 1

Partitioning large dictionary (400k+) for finding words in words in Python 3

依然范特西╮ 提交于 2021-01-29 16:19:38
问题 in my neural network, I want to normalize words of a text. It means words get converted to infinitives and gender independent. Example: "Unternehmensgruppenführer" (german) gets 3 words: unternehmen gruppe fahren. This requires a lot of "startsWith" processing. I built a table that gives me word=>infinitive and loads it into a sorted(!) dictionary of length 400k. However, the processing of that dictionary by finding words in words got very slow. I optimized that with an implementation of

Optimization problem with summation in the objective function using MATLAB linprog() function

流过昼夜 提交于 2021-01-29 15:21:46
问题 I have the following optimization problem (picture). I trying to solve this problem using the MATLAB linprog(f,A,b,....) function, but I don't know how to write the objective function due to the summation term for 'f' in the linprog() function. 来源: https://stackoverflow.com/questions/61745499/optimization-problem-with-summation-in-the-objective-function-using-matlab-linpr