Solving largescale symmetric linear system with matrix inertia (python)
My requirements are to solve the following linear system and determine the LHS matrix inertia using python:
(Matrix Inertia = (p,n,z)  The number of positive, negative and zero eigenvalues of the RHS matrix.)
The solution to this system derives the search direction for a primaldual interior point optimisation.
Each term in this figure has the following properties:
n >> 1000
m < 10
W = [n x n] (Sparse)
Sigma = [n x n] (Sparse)
delta_w_I = [n x n] (Sparse)
A = [n x m]
delta_c = [m x m]
dx = [n x 1]
d_lambda = [m x 1]
delta_phi = [n x 1]
A_lambda = [n x 1]
c = [m x 1]
W represents the hessian and must be approximated using the LBFGS which only computes the inverse W^1.
What steps do I need to take to solve this sparse system efficiently in python whilst also calculating the matrix inertia?
I have read about LDL^T factorisation but it doesn't work as I do not wish to invert my W term as this method requires both W and W^1 to solve and determine the matrix inertia.
(I have tried to install the Harwell subroutine libraries on my machine with the HSL.py wrapper, but I find it impossible to do so.)
See also questions close to this topic

is there a way to define your own failsafe button with pyautogui?
OK so i was using pyautogui and the failsafe and i was wondering if it was possible to assign a key to make the program close when it is pressed? i know that there is a failsafe already by moving the mouse to the top left of the screen but is there a way have a key close the program instead of using the mouse.

Inconsistent dimension after integer array indexing of a matrix
In python, when I was trying to A = something instead of A = A  something, it seems that there are something different if I do integer array indexing after the subtraction. The code is like this:
A = np.array([[1,2,3],[4,5,6]]) B = A  np.matrix(np.sum(A,axis = 1)).T A = np.matrix(np.sum(A,axis = 1)).T
If now I print A and B as a sanity check, they should be the same:
print(A) print(B) #[[ 5 4 3] # [11 10 9]] #[[ 5 4 3] # [11 10 9]]
However, if now I do integer array indexing and print the shape of the result:
y = [0,2] print(B[np.arange(N),y].shape) print(A[np.arange(N),y].shape) # the result is: # (1,2) # (2,)
I don't understand why the shapes of two identical matrices after indexing are different. Can anyone help me with it? Thank you!

Get daily average values from a monthly value in python
I have a metric called "monthly delta" which is a single value for a month. I need to calculate a daily value for delta which is (monthly delta/days of month) Can someone suggest me how to get the number of days of a month in python using a function and get a daily average delta?
Thanks

How to append and prepend 2D arrays in Java without Array copy assuming the column sizes are the same?
I've tried following this one How do you append two 2D array in java properly? removing all of the array copys but something is wrong. I also tried another guide but that only worked if the rows were the same.
public int [][] appendMatrix(int[][]matrix, int [][] matrix2) { this.matrix = new int[matrix.length + matrix2.length][matrix[0].length]; for(int i = 0; i < matrix.length; i++) { for(int j = 0; j < matrix[i].length; j++) { this.matrix[i][j] = matrix[i][j]; } for(int j = matrix.length; j < matrix.length + matrix2.length; j++) { this.matrix[i][j]= matrix2[imatrix.length][j]; } } return this.matrix;**

How to generate upper half of the matrix when digonal is given?
I encounter with this really interesting problem, I need to generate half part of the matrix (Upper part of the diagonal)
how do I approach this problem? any pseudocode would be appreciated

Taking symbolic variables out of txt file and making a matrix in Matlab
I have a txt file containing following characters. theta1 , l1 and others are symbolic variables.( Don't mind about it)
M=[theta1 + (l1^2*m1)/4 + l1^2*m2 (l1*l2*m2*cos(fi1  fi2))/2 ; (l1*l2*m2*cos(fi1  fi2))/2 theta2 + (l2^2*m2)/4 ]
I need to take it out and make it a symbolic matrix. As you can see txt file is already fine for making matrix but I don't want to copy paste the whole thing to script, I rather want to do it automatically.
fid = fopen('a.txt'); MMatrix=textscan(fid,'%s'); fclose(fid);
I tried the code above but it turn out to be not useful. What do you think is the way to copy the whole thing and use it for matrix making?

Reducing WASM filesize (libc, optimization, emscripten)
So, I did a lot of experimentation with Emscripten. And what I noticed pretty much is that the musllibc that is being used is impressively huge...like, really huge. A simple "Hello, World!" printing app is way above the 10kb...which is by far not practical.
Now how can I reduce this? So far, I figured that I could use
Os
andclosure 1
. But the latter only really works over JavaScript, so it does not affect the WASM output.What else can I do? Use a different libc implementation, maybe? I looked at uClibc and dietlibc as well as Metallic. I also thought about looing for a cheap  filesizewise  deflate function so I could transfer a gzipped version of the WASM binary. But so far, that is all I got.
Any suggestions? My last try was:
emcc test.cpp o test.wasm s WASM=1 Os closure 1
where
test.cpp
is just aprintf("Hello, world");
. 
How do I optimize a method that highlights text in richtextbox in WPF?
I have a method that highlights the textRanges that have been found, but it is extremely slow when highlighting some about 10 textRanges and more, and I'm wondering if I did something wrong here that makes this method slow. Or maybe that's the RichTextBox's problem, so how do I fix this?
// TODO: Optimize public void Highlight(IEnumerable<TextRange> textRanges, Regex regex, Brush foreGround, params Brush[] brushes) { if (textRanges?.Count() > 0) { var textRangesArray = textRanges.ToArray(); CircularArray<Brush> backgroundValues = new CircularArray<Brush>(brushes); int index = 0; foreach (TextRange i in textRangesArray) { string regExpression = regex.ToString(); // modify RegExpression, // so that it has ^ in the start and $ in the end regExpression = !regExpression.StartsWith("^") ? '^' + regExpression : regExpression; regExpression = !regExpression.EndsWith("$") ? regExpression + '$' : regExpression; // check if the given textrange matches the regExp if (Regex.IsMatch(i.Text.RemoveAll('\r', '\n'), regExpression)) { // change background and foreground // properties of the current textRange i.ApplyPropertyValue(TextElement.BackgroundProperty, backgroundValues[index++]); i.ApplyPropertyValue(TextElement.ForegroundProperty, foreGround); } } } }
P.S. CircularArray is the data structure I implemented myself in this project and it is simply an array but with a different indexer, the indexer returns n % array.Length element in an array, where n  input in square brackets, so the problem is not about this data structure.
What I need to do is to optimize this method or maybe the whole RichTextBox (I've searched on stackoverflow and found out that RichTextBox is extremely outdated  but it appeared that it was about WinForms whereas my app is being run on WPF, maybe richtextbox on wpf is outdated and unoptimized as well?)

How or can I generalize an Ifstatement for multiple JButtons (color changing)?
So I'm trying to make multiple buttons do the same change in color when they are pressed. Each individual press should cycle through a predetermined cycle of colors (White, Red, Green, Yellow, Blue, Black). I could just make a long ifelsestatement but for I'm pretty sure there's a better way, I just can't come up with one.
I have already tried "getSource().getBackground()" in the second ifstatement but it's not able to get the same variable as the first ifstatement does.
public void actionPerformed(ActionEvent e){ if(e.getSource() == btn1){ if(getSource().getBackground() == Color.white) setBackground(Color.red); else setBackground(Color.white); }
As previously stated I'm trying to minimize the effort here and make it also a bit more organized.

Scipy: Union of sparse boolean matrices
In Scipy, what is the most efficient way to get the union
A+B+C
of multiple boolean sparse (csr
) matricesA,B,C
(with the same shape)?Union means among others:
 sparsity changes
 overlaps are possible

Scipy: Sparse indicator matrix from array(s)
What is the most efficient way to compute a sparse boolean matrix
I
from one or two arraysa,b
, withI[i,j]==True
wherea[i]==b[j]
? The following is fast but memoryinefficient:I = a[:,None]==b
The following is slow and still memoryinefficient during creation:
I = csr((a[:,None]==b),shape=(len(a),len(b)))
The following gives at least the rows,cols for better
csr_matrix
initialization, but it still creates the full dense matrix and is equally slow:z = np.argwhere((a[:,None]==b))
Any ideas?

Writing a very large sparse matrix to file in R
I have a sparse matrix with the dimensions of ~400K x ~8k.
I would like to save this as either a tab delimited or csv file, as I need it as an input to another program.
I used the write.matrix function from the MASS package as suggested from this post: How to save an adjacency matrix as a CSV file?
However, I get the following error:
library(MASS) write.matrix(data,"data_sparseMat.txt",sep="\t") #Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
Looking at the help, I then tried giving the blocksize parameter. I tried 1000, 10000, 100000. All gave me the same error
write.matrix(data,"data_sparseMat.txt",sep="\t", blocksize=1000) Error in asMethod(object) : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
I would appreciate any insight, what am I overlooking?
R version:
R version 3.5.2 (20181220) Platform: x86_64appledarwin15.6.0 (64bit) Running under: macOS High Sierra 10.13.6
Example:
w < data.table( "id" = 1:300000 , "code" = paste(letters,1:9000,sep=""), "measure"=1:3000) w$id < factor(w$id) w$code < factor(w$code) z< sparseMatrix(as.integer(w$id),as.integer(w$code),x=w$measure,dimnames=list(levels(w$id),levels(w$code))) write.matrix(z,"sparseTest.txt",sep="\t") write.matrix(z,"sparseTest.txt",sep="\t",blocksize=100000)
NOTE: when code is just 1000 or 3000 instead of 9000, it appears that it is written to file albeit slowly.
Many Thanks.