# Questions tagged [optimization]

15635 questions

1

votes

1

answer

277

Views

### Selecting Pareto-Dominant Vector

I want to compare two vector. This vector represents two alternative:
def select_dominant(a,b):
comp=a>b
if(comp):
return a
elif(a

13

votes

3

answer

240

Views

### How can modern compiler optimization convert recursion into returning a constant?

When I compile the following simple recursion code with g++, the assembly code simply returns i, as if g++ can do some algebra tricks as humans can.
int Identity(int i) {
if (i == 1)
return 1;
else
return Identity(i-1)+1;
}
I don't think this optimization is about tail recursion,
and apparently, g++...

6

votes

2

answer

144

Views

### Does stack space required by a function affect inlining decisions in C/C++?

Would a large amount of stack space required by a function prevent it from being inlined? Such as if I had a 10k automatic buffer on the stack, would that make the function less likely to be inlined?
int inlineme(int args) {
char svar[10000];
return stringyfunc(args, svar);
}
I'm more concerned abou...

0

votes

1

answer

51

Views

### Webpack4: Two vendor libraries based on entry points

So, I've been hunting and I can't seem to find anything unless my searching skills have gotten worse lately. But, what I'm looking for is to be able to generate two vendor bundles based on the entry point.
For example, I have 3 entry points:
Editor
Public
Auth
When a user is logged in, it'll include...

3

votes

1

answer

41

Views

### Need help understanding PySpark explain output

My query is timing out and I want to understand the output of the explain command to better understand whats the problem.
First my query looks like:
WITH f (
SELECT
/*+ BROADCAST(h) */
/*+ COALESCE(36) */
CONCAT(f.outboundlegid, '-', f.inboundlegid, '-', f.agent) AS key,
f.querydatetime,
f.outbo...

0

votes

0

answer

5

Views

### How to do batching without UBOs?

I'm trying to implement batching for a WebGL renderer which is struggling with lots of small objects due to too many draw calls. What I thought is I'd batch them all by the kind of shader they use, then draw a few at a time, uploading material parameters and the model matrix for each object once in...

0

votes

0

answer

12

Views

### Error in nls: number of iterations exceeded maximum of 100

My model: beta1+sin(beta2*time*pi) +error
I used nls function in r :
nlm.1

1

votes

1

answer

69

Views

### Athena: Query exhausted resources at scale factor

I am running a query like:
SELECT f.*, p.countryName, p.airportName, a.name AS agentName
FROM (
SELECT
f.outboundlegid,
f.inboundlegid,
f.querydatetime,
cast(f.agent as bigint) as agent,
cast(f.querydestinationplace as bigint) as querydestinationplace,
f.queryoutbounddate,
f.queryinbounddate,
f.q...

1

votes

2

answer

59

Views

### Add step size to a linear optimization

I'm working on a blending problem similar to the pulp example
I have this constrain to make sure the quantity produced is the desired one
prob += lpSum([KG[i] * deposit_vars[i] for i in deposit]) == 64, "KGRequirement"
But I also need to add another constraint for the minimun value different than ze...

0

votes

0

answer

7

Views

### Why globals and locals affect while judgement in C?

I get confuse when I test volatile:
Firstly I tested:
int main()
{
int status = 0;
while (status == 0)
{
}
}
the while tests if status==0 at every cycle (setting breakpoint)
Then I set status as a global:
int status = 0;
int main()
{
while (status == 0)
{
}
}
Then the while never s...

1

votes

3

answer

1.2k

Views

### Optimizing the Verhoeff Algorithm in R

I have written the following function to calculate a check digit in R.
verhoeffCheck

1

votes

1

answer

22

Views

### generate a special matrix (max value of column sum is minimum) with given number of column from a vector

Recently I come across such as a question: given a vector, one need generate a special matrix with given number of column. It should be pointed out that if the elements in the vector is not enough to fill in the generated matrix, then put 0 in the last row in the generated matrix. For the generated...

0

votes

1

answer

22

Views

### MYSQL lot's of update on 40 million record table wih 128GB ram dedicated server take long time

We are having trouble with updates on a single table taking a long time. The table contains ~30 Million rows.
The job runs every day that truncates the table and inserts new data from other other sources in that table.
Here is the table:
CREATE TABLE tempportfolio1 (
SR_NO int(4) NOT NULL AUTO_INCRE...

0

votes

0

answer

7

Views

### Why are FIFO One-quarter full, Half-full, three-quarter full interrupts provided in a UART RX FIFO? What are their use cases?

I am implementing a protocol decoder which receives bytes through UART of a microcontroller. The ISR takes bytes from the UART peripheral and puts it in a ring buffer. The main loop reads from the ring buffer and runs a state machine to decode it.
The UART internally has a 32-byte receive FIFO, and...

23

votes

6

answer

1.5k

Views

### Does the Java compiler optimize an unnecessary ternary operator?

I’ve been reviewing code where some coders have been using redundant ternary operators “for readability.” Such as:
boolean val = (foo == bar && foo1 != bar) ? true : false;
Obviously it would be better to just assign the statement’s result to the boolean variable, but does the compiler care?

5

votes

3

answer

96

Views

### Perl optimizer question: Will the perl compiler optimize away all of these temporary variables?

I've got a pretty simple piece of arithmetic, but for readability and correctness, I've expanded it out into a bunch of temporary variables. It's easier to read, change, and examine partial pieces of the expression.
My question is, will this code take a run-time beating just because it's expanded?...

0

votes

0

answer

4

Views

### Several Questions to get a code on CPLEX IBM ILOG

My dear readers.
I am a super beginner of computer coding.
Now I am trying to build a code by using CPLEX IBM ILOG.
There are some Questions. ;)
Every time I run my solver, I got a message with sudden stop, "OplRun is not responding, you must relaunch the RunConfig"
So, I find IBM homepage and I did...

1

votes

0

answer

13

Views

### How to use of nloptr library to maximize Spearman correlation between two arrays

I have two arrays. For example the first one is A and the second B:
A

0

votes

0

answer

5

Views

### How can I move an existing index on a normal table to a memory optimized file group?

How can I move an existing index on a normal table to a memory optimized file group in sql server?

1

votes

1

answer

44

Views

### Optimising a MySQL Full-Text Query

I have a table of medical diagnostic codes that users are able to perform a keyword search against. I have a column of descriptive text as well as a column of synonyms, both of which are considered. Results are presented in an auto-suggest format and the current implementation of the query is too sl...

0

votes

0

answer

5

Views

### Do I have to type the formula code in scipy optimize if the cells in excel already have formula inside?

I'm currently trying to solve an optimization problem using python scipy optimize. The data I need is in an excel file and the formulas of the variables are already in the cells. I already linked the excel file to python using openpyxl.
My question is that do I have to type in the formula once agai...

1

votes

1

answer

1.8k

Views

### Constraints do not follow DCP rules in CVXPY

I want to solve this problem using CVXPY but I don't know why I get the following error message:
DCPError: Problem does not follow DCP rules.
I guess my constraints are not DCP. Is there any way to model this in DCP?
n_k = [10000, 20000]
request_rate = [15, 10]
p_k_1 = np.random.rand(n_k[0])
p_k_2...

1

votes

1

answer

540

Views

### Does MySQL block nested loop optimizer switch affect query results?

If I set set optimizer_switch='block_nested_loop=off' as suggested here, can i get 100% certainty the same result for option on and off ?
I want to change this option to off, because it increases query performance in my case from 56s to 1s.
What are the pros and cons for this optimizer switch, is it...

1

votes

1

answer

429

Views

### sqlalchemy bulk_insert_mappings generates a large number of insert batches, is this avoidable?

I have a large number of objects that need to be inserted into an Oracle database via sqlalchemy.
Using individual inserts took quite a while to execute. After searching around it became obvious that there are more efficient bulk insert methods, bulk_insert_mappings, bulk_save_objects, etc. These me...

1

votes

1

answer

112

Views

### Oracle Parameterized Query Performance

Execution time differs too much between the queries below. These are the generated queries from an app using Entity Framework.
The first one is non-parameterized query that takes 0,559 seconds.
SELECT
"Project1"."C2" AS "C1",
"Project1"."C1" AS "C2",
"Project1"."KEYFIELD" AS "KEYFIELD"
FROM ( SE...

1

votes

2

answer

71

Views

### What is the difference between Early inliner and IPA inliner in GCC?

Reading through GCC code comments and online documentation, it seems there are two types of inliners - Early inliner and the IPA inliner.
For example, in gcc/ipa-fnsummary.c
/* When optimizing and analyzing for IPA inliner, initialize loop
optimizer so we can produce proper inline hints.
When optim...

1

votes

1

answer

132

Views

### Convert Constant Integer to Value* LLVM

I am trying to create an IR instruction
store i32 0, i32* %3, align 4
I am using the method
StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile = false)
to create the instruction. Since the first argument takes a Value*, somehow I need to convert 0 to Value*.
Ca...

1

votes

1

answer

66

Views

### problem with constraints in minimize from scipy.optimize

I have searched about this a bit, and couldn't solve this problem. I am working with the minimize function from scipy.optimize, and keep getting the error:
'str' object not callable.
My code is complicated, so I looked up an easy example online to make sure I was inputting everything correctly, and...

1

votes

1

answer

74

Views

### Optimization: Oj algorithms (java) versus SCIP (python)

Does anybody know how these 2 solvers, (Oj algorithms) from Java and SCIP for Python, relate to each other performance wise (as in: which one is the fastest), when dealing with a typical MILP (Mixed Integer Linear Programming) problem? On first sight, I can't seem to find anything online that can po...

1

votes

4

answer

172

Views

### Algorithm to find prime numbers with odd digits in large range

Given a range of [1, 1000000000] we need to find prime numbers and all the digits of the prime number must be odd. (Example: 23 is not okay, 31 is okay)
If we go on by looping through each number and checking if it is prime etc, it is very slow. Is there a way to make this close to O(N) ?
I tried to...

1

votes

1

answer

39

Views

### Java - Cassandra with plenty of parameters in “IN”

I'm writing a Java application with Cassandra DB. I'm making a request with plenty (more than 100,000) parameters in my 'IN' clause :
SELECT country, gender FROM persons WHERE person_id IN (1,7,18, 34,...,)
But putting some many parameters in "IN" looks bad I think.
I can also make plenty of request...

1

votes

1

answer

55

Views

### Are these compiler optimisations from a CppCon example allowed to be made?

I'm watching a CppCon video, which shows this code:
void foo(const int&);
bool bar(int x)
{
const int y = x + 1;
foo(y);
return y > x;
}
First of all the speaker says that since the foo() function takes 'y' by const reference, and 'y' is actually a const int, then changing the value in foo() is unde...

1

votes

1

answer

114

Views

### Optimizing .txt files creation speed

I've written the following simple testing code, that creates 10 000 empty .txt files in a subdirectory.
#include
#include
#include
#include
void CreateFiles()
{
int i = 1;
while (i

1

votes

2

answer

67

Views

### Operating on two shorts at once by combining them into an integer

I'm using the following code to map two signed 16-bit integers to the upper and lower 16 bits of an unsigned 32 bit integer.
inline uint32_t to_score(int16_t mg, int16_t eg) {
return ((1u * mg) > 16);
}
inline int16_t extract_eg(uint32_t score) {
return int16_t(score & 0xFFFF);
}
I need to perform v...

1

votes

3

answer

42

Views

### How to optimize a delete query with a subselect?

This query needs to delete over 17 million rows, from a table containing 20 million.
DELETE
FROM statements
WHERE agreement_id IN
(SELECT id
FROM agreements
WHERE created < DATE_SUB(CURDATE(), INTERVAL 6 MONTH));
DELETE
FROM agreements
WHERE created < DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
It takes h...

1

votes

2

answer

41

Views

### Bad query performance. Where do I need to create the indexes?

I have a relativelly simple query, but it's performance is really bad.
I'm currently at something like 0.800 sec. per query.
Is there anything that I could change to make it faster?
I've already tried indexing the columns, used in where statement and join, but nothing works.
Here's the query that I...

1

votes

2

answer

46

Views

### Spark map with many String concatenation

I am looking for a way to optimize a code like this one:
// for each line do many string concatenations
myRdd.map{x => "some_text" + x._1 + "some_other_text" + x._4 + ...}
I just read that use a
s"some_text${x._1}..."
will be replaced by a basic string concatenation like in my map.
So my first tho...

1

votes

1

answer

46

Views

### Why does the rowsize of A matter in fmincon

I have a Matlab code, which use fmincon with some constraints. So that I am able to modify the code I have thought about whether the line position within the condition matrix A makes a difference
I set up a test file so I can change some variables. It turns out that the position of the condition is...

0

votes

0

answer

9

Views

### Mathematical constrained optimization in R

I have a mathematical optimization which I wish to solve in R. consider this system/problem:
How Can I solve this problem in R? I have looked into constrOptim but I don't have the imagination to implement the constraints.
In this model Budget and mu_target is fixed constants while muis a given m-dim...

1

votes

3

answer

1.4k

Views

### Call method/function twice Vs. Saving into a variable and call once

I often come to this question when coding.
Which of the following examples is a better practice? I am aware that other factors will influence whether one or the other one is better. But in general, what are the advantages of one over the other.
if(object.getA().Value != null) {
return object.getA(...