# Questions tagged [optimization]

15644 questions

1

votes

3

answer

75

Views

### SQL sub-queries and Join Queries

I am working on a project with lots of large SQL requests, I want to know:
what provides a better performance in term of speed between:
Join Queries
Sub-Queries
For example
SELECT artistName FROM artist
JOIN group
On group.location = artist.location
AND group.available = 'true'
SELECT artistName...

1

votes

1

answer

6.7k

Views

### fminsearch multiple parameters matlab

I'm trying to use fminsearch with multiple parameters but I can't seem to even get it working with two. I've also tried using optimization tool in matlab but then I get:
Optimization running.
Error running optimization.
Not enough input arguments.
What i do:
fval = fminsearch(@g,[1 1])
The function...

2

votes

2

answer

56

Views

### How to convert #ffffff to #fff or #fff to #ffffff for Assertion?

How to convert #ffffff to #fff or #fff to #ffffff for Assertion?
I have used getCssValue("background") which returns rgb(255, 255, 255) which I can split into:
r -> 255
g -> 255
b -> 255
The following line of code:
String hex = String.format("#%02x%02x%02x", r, g, b);
Converts rgb to hex and gives a...

1

votes

1

answer

5.5k

Views

### Pass Pandas DataFrame to Scipy.optimize.curve_fit

I'd like to know the best way to use Scipy to fit Pandas DataFrame columns. If I have a data table (Pandas DataFrame) with columns (A, B, C, D and Z_real) where Z depends on A, B, C and D, I want to fit a function of each DataFrame row (Series) which makes a prediction for Z (Z_pred).
The signature...

1

votes

3

answer

99

Views

### Any way to simplify permission checks?

I am currently working with permissions in Android Studio.
I've checked how the tutorial does it, and I've seen that it's really obnoxious and long. The current code is this:
String[] InternetPermission = new String[]{Manifest.permission.INTERNET};
if (ContextCompat.checkSelfPermission(ViewingWindow...

0

votes

1

answer

19

Views

### len() of unsized object - cvxpy - correlation maximization

import numpy as np
import pandas as pd
from scipy.stats.stats import pearsonr
from cvxpy import Variable, Problem, Maximize
X = np.random.rand(1000, 4)
Y = np.random.rand(1000, 4)
weights = Variable(4,)
constraints = []
def get_correlation(a):
return pearsonr(X * a, Y *a)
obj = Maximize(get_correlat...

3

votes

3

answer

57

Views

### How to set up repetitive data so that most can be optimized away?

I need to perform a bitwise AND on 32 kbit-wide data. One of these values is a fixed bitmask.
I'm performing this AND 32 bits at a time. Simplified, my algorithm will look something like this:
(I'm removing memory management, variable scope concerns, etc, from this example)
#include
const uint32_t...

1

votes

1

answer

52

Views

### libsvm compiled with AVX vs no AVX

I compiled a libsvm benchmarking app which does svm_predict() 100 times on the same image using the same model. The libsvm is compiled statically (MSVC 2017) by directly including svm.cpp and svm.h in my project.
EDIT: adding benchmark details
for (int i = 0; i < counter; i++)
{
std::chrono::high_r...

6

votes

2

answer

218

Views

### Why does setting a const variable (which will be stored with the same value) lead to a different result once divided?

Pretty basic code:
#include
int main() {
std::cout.precision(100);
double a = 9.79999999999063220457173883914947509765625;
double b = 0.057762265046662104872599030613855575211346149444580078125;
const double bConst = 0.057762265046662104872599030613855575211346149444580078125;...

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

15

votes

3

answer

595

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

3

answer

177

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...

7

votes

1

answer

80

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...

4

votes

1

answer

56

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

72

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.9k

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

547

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

439

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

115

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

135

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

67

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

174

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...