## Can we use Base R to find the 95% of the area under a curve?

Using Base R, I was wondering if I could determine the 95% area under the curve denoted as posterior below? More specifically, I want to move from the mode (the green dashed line) toward the tails and then stop when I have covered 95% of the curve a...
more »

## Optimal value is outside range when doing bruteforce optimization using Scipy

I'm following the example given in scipy's optimize documentation to do brute-force optimization on a function with 3 parameters. This is the function I wish to optimize: def entropy_of_hyperplane(z): w0, w1, b = z # do some calculations.. ...
more »

## Solving for two parameters using `optim()` in R?

I'm trying to find shape1 and shape2 in dbeta() such that the answer from dbeta() for the two input values: .6 and .8 become 3. I'm using the below optim() but don't get exact result, that is I expect getting values for shape1 and shape2 that when u...
more »

## Trying to optimize this algorithm/code to compute the largest subset of mutually coprime integers between a and b

I'm writing a function in Haskell that takes in two integers a and b and computes the length of the largest subset(s) of [a,b] such that all the elements are mutually coprime. Now, the reason for this is because I believe investigating such values mi...
more »

## Using texture cache versus coalesced global memory with low cache hit rate?

In the processus of optimizing and profiling a kernel, I noticed that it's L2 and global cache hit frequency was very low (~1.2 % avg.). My kernel typically reads 4 full cache lines per pass per warp, with 3 blocks per SM (So 4 * 32 * 2 = 256 lines o...
more »

## Haskell: speed difference between two versions of code

I've started diving into Haskell by trying to solve some small problems. I've stumbled upon a big performance difference(~100-200x) between the "standard haskell-friendly" solution and my "very-ugly and haskell-unfriendly" version. I'm sure for fel...
more »

## Why do some C compilers set the return value of a function in weird places?

I wrote this snippet in a recent argument over the supposed speed of array[i++] vs array[i]; i++. int array[10]; int main(){ int i=0; while(i < 10){ array[i] = 0; i++; } return 0; } Snippet at the compiler expl...
more »

## Faster alternative to numpy for manual element-wise operations on large arrays?

I have some code that was originally written in C (by someone else) using C-style malloc arrays. I later converted a lot of it to C++ style, using vector<vector<vector<complex>>> arrays for consistency with the rest of my project. I...
more »

## Generic and non-generic method with similar body

I have a method called ExecuteAsyncServiceRequest with an overload, you'll notice that the body of the both methods are similar. I find myself wondering is there a more concise way of writing these methods? Specifically, to not have to repeat myself ...
more »

## How to optimize the unused space in the Java heap

Do not take my word on this. I am just repeating what I have pieced together from different sources. HotSpot JVM uses Thread Local Allocation Buffers (TLABs). TLABs can be synchronized or not. Most of the time the TLABs are not synchronized and h...
more »

## What is an efficient data structure to read/write IPv6 address ranges into for quick lookup times?

I'm trying to think of an efficient data structure which I can use to store IPv6 address ranges into. The lookup time should be quick. That is, given an IPv6 address, I should be able to quickly determine which interval it's from. In my case here, ad...
more »

## Rolling window count for a date interval in pandas

I have a history of projects and their associated planned beginning and end times: id planned_start planned_end 1 2017-09-12 2017-09-13 2 2017-09-12 2017-09-14 3 2017-09-12 2017-09-13 4 2017-09-13 2017-09-13 5 2017-09-12...
more »

## An efficient method for calculating log base 2 of a number between 1 and 2

I am working on a fixed-point platform (floating-point arithmetic not supported). I represent any rational number q as the floor value of q * (1 << precision). I need an efficient method for calculating log base 2 of x, where 1 < x < 2....
more »

## Python How to improve numpy array performance?

I have a global numpy.array data which is a 200*200*3 3d-array containing 40000 points in the 3d-space. My goal is to calculate the distance from each point to the four corners of the unit cube ((0, 0, 0),(1, 0, 0),(0, 1, 0),(0, 0, 1)),so I can dete...
more »

## Optimized computation of pairwise correlations in Python

Given a set of discrete locations (e.g. "sites") that are pairwise related in some categorical ways (e.g. general proximity) and contains local level data (e.g. population size), I wish to efficiently compute the mean correlation coefficients between...
more »

## Optimized way to partition a class of objects based on an attribute in C++

I have a class that has million of items and each item has a label of type int. I need to partition items based on their similar labels, so at the end I return a vector<MyClass>. First, I sort all items based on their label. Then, in a for loop...
more »

## How to clear Thumbor cache?

Is there any way to do it like Redis for example: redis-cli flushall ? I did not find anything about clearing cache at Thumbor's official documentation. The only useful thing i found was this parameter: MAX_AGE, but it's not good enough for me, caus...
more »

## Which would yield better performance in general?

I have a small dilemma. As we all know, defining variables by types and avoiding the usage of variants is the most obvious performance trick. The problem is I'm trying to write a library of routines that would work with implicitly-typed arguments (ba...
more »

## Optimizing SQL by using temporary table in Oracle

I have a data cleanup-er procedure which deletes the same data from the card rows of two tables. Both of these update statement use the same subQuery for detecting which rows should be updated. UPDATE table_1 SET card = NULL WHERE id in ...
more »

## String.replace and same method call mutliple times

I and my friend has written below code to prevent code injection in injection in CSV files. (written in java) For big CSV files (say 400 columns, 10000 rows), the code is taking ~15 seconds in the worst case (all columns and rows are bad). Can anybo...
more »

## Migrating old table to new table in laravel

I have a problem where i need to migrate old table to new table. The old table data example like this: Old table(Leave table) Id   User_id    Reason    Date 1    100        ...
more »

## How to optimize/simplify heapsorting django objects? (can't use modules and db sorts)

I have to ask for some help with an assignment I got as a test for a django internship. I had to make and imaginary api with rabbits and their carrots. Each rabbit was supposed to have a number of carrots, but the api had to be designed to allow for ...
more »

## Why do I see a performance drop when using row-major order?

I have got a piece of code which runs over a large matrix and computes column-wise binned statistics, where the bins are given in a vector b. The code goes (something) like this: for (item = 0; item < items; item++) { uint8 bin = binvec[item...
more »

## Optimizing Memory in Haskell, pipes, attoparsec, and containers

I'm trying to further optimize my pipes-attoparsec parser and storage, but having trouble getting memory usage any lower. Given account-parser.hs {-# LANGUAGE RankNTypes #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NoImplicitPrelude #-} imp...
more »

## How to optimize c# code requesting JSON using REST api

I have to make a c# application which uses REST api to fetch JIRA issues. After I run the tool I am getting the correct output but it is taking a lot of time to display the output. Below is the part of code which is taking the maximum time var clien...
more »

## MATLAB Optimization - how to move on to next possible solution if a condition is not satisfied?

I am using the fmincon optimization to find parameters that fit constraints. It is currently set up like: constraints = [1 2 3]; interval = 100; time_start = [2500]; time_boundary = [500 5000]; param2_start = [0.5]; param2_boundary = [0 1]; op...
more »

## SciPy portfolio optimization with grouped by industry bounds

Trying to optimize a portfolio weight allocation here which maximize my return function by limit risk. I have no problem to find the optimized weight that yields to my return function by simple constraint that the sum of all weight equals to 1, and m...
more »

## Is there value in generating boolean arrays prior to sub-selection with Pandas?

Curious if, when making a sub-selection in Pandas, pre-generating the boolean Numpy array is in any way advantageous. Without being very familiar with how Pandas and Numpy handle these kinds of queries, I wonder if calculating them all at once (exa...
more »

## Ways to optimise this code

I am exploring ways to optimise the code that follows. The code loops over a string. For the ith character in the string, the code increments one entry in a 2D array at the ith column. The exact entry at the ith column that is incremented depends on...
more »

## How to generate a list of palindromes without a check

I'm working on a problem where I'm required to manipulate large lists of palindromes up to a certain number of digits. This should work with numbers up 15 digits. The most common method I've seen for this is iterating through each number and checking...
more »

## How to randomly shift rows of a numpy array

I am looking for a more pythonic way of randomly shifting rows of a numpy array. The idea is that I have an array of data, and I want to left-shift each row of the array by a random amount. My solution, which works, but I feel is a bit un-pythonic: ...
more »

## Can I further simplify this code/expression?

I'm in a DSP context, which I need to speed-up some operations. Here's a formula I have and I execute often: unsigned int pos0 = (unsigned int)round((envelope.mLengths[sectionIndex] * mSampleRate) / gBlockSize) * gBlockSize; unsigned int pos1 = (un...
more »

## Optimizing adding dashes to a long Swift String

I am trying to take a hex string and insert dashes between every other character (e.g. "b201a968" to "b2-01-a9-68"). I have found several ways to do it, but the problem is my string is fairly large (8066 characters) and the fastest I can get it to w...
more »

## Which one is better to use in C and C++ programming?

Is there any difference between the following two code snippets? Which one is better to use? Is one of them faster? case 1: int f(int x) { int a; if(x) a = 42; else a = 0; return a; } case 2: int f(int x) { ...
more »