C++ quick matrix calculation of XDX^T for X fixed, D diagonal and changing
Take a fixed n by m matrix X. I am interested in creating a function which takes in an m dimensional vector v, and outputs XDX^T where D is a diagonal matrix with entries of v along its diagonals. For fast calculation (here n is around 2000, m can be from 10000 to 100000), my idea is based on one observation.
Note that XDX^T = sum_{i=1,...,m} (Y_i Y_i^T)*v_i where Y_i are the columns of X (so X = [Y_1 Y_2 .... Y_m].
So initially we precaculate and save the n by n matrices (Y_i Y_i^T) for i=1,...,m. This will be saved as an array of m matrices. Then we create a function which takes this array of matrices and v as input, applies element wise multiplication behind v and the array, then returns the sum of the m matrices.
However, I am very new to C++, and efficiently writing this program is difficult. Any help on doing this quickly, and whether this is a good idea? At the moment I am calculate XDX^T using crossproduct function in the Eigen library. My intuition is the above method should be much faster (we are trading off memory for speed). Thanks.
See also questions close to this topic

What is the complexity of reverse() function in c++?
I guess it's complexity maybe o(nlogn) but i am confused. so, I want to know it
reverse(v.begin(), v.begin());

I'm trying to Dequeue. It works! But is it the right way to do it?
I wrote the following code in C++ to for deQueue function. My professor used two new nodes in his dequeue function for some reason. This code works just fine, but i need to know if something is wrong at the back.
#include<iostream> using namespace std; class node{ public: node *nxt; int data; }; class queue{ node *head, *tail; public: queue(){ head=tail=NULL; } void q(int var) { node *n=new node(); n>data=var; n>nxt=NULL; if(head==NULL) { head=tail=n; } else{ tail>nxt=n; tail=n; } } void dQ() { node *tmp=new node; tmp=head; cout<<tmp>data<<" Deleted"<<endl; head=head>nxt; } }; int main() { queue obj; obj.q(13); obj.q(14); obj.q(18); obj.display(); obj.dQ(); cout<<"After DQ"<<endl; obj.display(); return 0; }

How to convert old connect syntax
I can't convert QEventLoop connect statement to a new syntax... Compile error: no matching member function to call 'connect'
QNetworkAccessManager manager; QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("request"))); QEventLoop loop; loop.connect(&manager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); //loop.connect(&manager, &QNetworkReply::finished, &QEventLoop::quit); //ERROR loop.exec();

Trying to find # duplicates in array  my function returns 0?
The goal is to find number of duplicate values in array.
What I'm doing: for each item in array, if not in temp array, add it, or else count +=1.
function find_duplicate_in_array(arra1) { var temp=[]; let count = 0; arra1.forEach(function (item) { if(!temp[item]) { temp.push(item); } else { count=count+1; } }); console.log(temp); return count; } let result=find_duplicate_in_array(["sam", "bob", "sam"]); console.log(result);
Actaul Result: 0; Expected result:1 (TYPO, # of duplicated would be one);
Why?

How to filter array of object based on another array values using javascript?
I have a simple array of numbers (which for my app represents user Id's). For example...
[1, 2, 3]
I also have an array of objects such as
[ {Id: 1, FirstName: "Bob", LastName: "Jones", EmailAddress: "bob@bob.com"}, {Id: 2, FirstName: "Tessa", LastName: "Wong", EmailAddress: "tes@wong.com"}, {Id: 3, FirstName: "Craig", LastName: "Murray", EmailAddress: "Craig@muz.com"}, {Id: 4, FirstName: "Bryce", LastName: "Willamson", EmailAddress: "email@me.com"}, {Id: 5, FirstName: "Tony", LastName: "Ocka", EmailAddress: "toni@oz.com"} ]
What I need to do is match any values that appear in the initial array with they key
Id
in the second array of objects (and return a new full array of objects containing only matches). So for example in this case, the result I'm looking for is:[ {Id: 1, FirstName: "Bob", LastName: "Jones", EmailAddress: "bob@bob.com"}, {Id: 2, FirstName: "Tessa", LastName: "Wong", EmailAddress: "tes@wong.com"}, {Id: 3, FirstName: "Craig", LastName: "Murray", EmailAddress: "Craig@muz.com"}, ]
Any help would be really appreciated.

Foreach for arrays inside of an array in controller Codeigniter
I have array of array and I did a
print_r
of it and it returned this...Array ( [0] => Array ( [0] => Array ( [cust_id] => xl [project_id] => central [tot_ticket] => 1 [person] => jamesbay@example.com ) [1] => Array ( [cust_id] => tsel [project_id] => jabo1 [tot_ticket] => 1 [person] => jamesbay@example.com ) [2] => Array ( [cust_id] => isat [project_id] => jabo2 [tot_ticket] => 1 [person] => jamesbay@example.com ) ) )
I write this in my controller right now:
for ($i=0; $i<count($customerField); $i++) { for ($j=0; $j<count($activityField); $j++) { for ($k=0; $k<count($userIdField); $k++) { array_push($data, $this>queries_trend>fetch_ajax($customerField[$i], $activityField[$j], $userIdField[$k])); foreach ($data as $value) { $test .= ' <tr> <td>' . $value[$i][$j]['cust_id']>cust_id . '</td> <td>' . $value[$i][$j]['project_id'] >project_id. '</td> <td>' . $value[$i][$j]['tot_ticket']>tot_ticket . '</td> <td>' . $value[$i][$j]['person']>person . '</td> </tr>'; } } } }
I have problem to get the value of each array, anyone here can help me to find the solution?

Finalize method causing performance overhead
Why is it that implementing finalize method causes performance overhead in Java?

impala distinct count performance issue
i am using hive 1.1 with impala 2.2 , Got performance issue with select count(distinct field) from largetable group by x; I saw hive 1.2 resolve this issue. This will resolve performance issie with impala 2.2? or issue purely related with impala?
If it is impala issue which version impala will resolve this issue ?

summation of XOR of X with each of the array element from range L to R both
I trying to solve this problem i demand a trial by combat in hackerearth and i mostly solve but i get TLE in testcase after 3 My solutions take time complexity
O(Q*R+L1) which mean O(N^2) Is there any way to solve this problem In O(N) or less time Here is my solution
#include <stdio.h> #include <stdlib.h> #define ll long long int main(){ ll q,x,n,r,l; scanf("%lld %lld",&n,&q); ll arr[n]; for(ll i=0; i<n; i++){ scanf("%lld",&arr[i]); } while(q){ scanf("%lld %lld %lld",&l,&r,&x); ll sum = 0; for(ll i=l1; i<r; i++){ sum += arr[i]^x; } printf("%lld\n",sum); } }
Problem:
You are given an array of integers A of size N. Now you are given Q queries to be performed over this array.
In each of the query, you are given 3 space separated integers L, R and X, you need to output the summation of XOR of X with each of the array element from range L to R both inclusive ( 1based indexing ).
sum (i=l to r) of A[i] XOR X In simple terms
Constraints:
1 <= N,Q <= 10^5
1 <= A[i] <= 10^9
1 <= L,R <= N
1 <= X <= 10^9

multiplication of data from different csv files based on same 'label'
I have two .csv files of row length 256 and 16. Each row has a 'label' making row length to 257 and 17 respectively.
csv 1 with 257 columns with 'label' as first column
csv 2 with 17 columns with 'label' as first column
Now, i want to convert each row of csv1 into a 4x64 numpy matrix and each row of csv 2 into a 4x4 numpy matrix and perform matrix multiplication if the labels are same in both files. So, each row with label 39 from the first csv file needs to be multiplied to the values corresponding to label 39 in second csv file. I then want to store the result into another .csv file with corresponding labels. Any help is very much appreciated. Thank you.
My jupyter notebook commands are below. (this works when I multiply all the rows of csv 1 to a specific matrix m defined by me). I actually need to multiply each row of csv1 to the row in csv2 corresponding to the same label.
dataset_new = pd.read_csv('file1.csv') T_train = dataset_new.drop(labels = ["label"],axis = 1) del dataset_new T_train = T_train.values.reshape(1,4,64) test = [] for feature_matrix in T_train: template=m.dot(feature_matrix) test.append(template) print(test) t = np.array(test) final_template = open('final_template.csv','a') for i in t: i = i.flatten() print(i) np.savetxt(final_template, [i], delimiter=',')

Speed up sparse matrix multiplication in R
I am trying to multiply a matrix (made up of few 1's and majority O's) with a vector using %*% function in R, this process is taking huge amount of time. Is there a way I can make this faster??
Thanks

Why is this line printing twice?
So I help tutor an Algebra 2 class at my local high school, and the class is currently looking over matrices. Though not there, they will eventually get to multiplication of matrices. After taking Computer Science last year and learning Java, the teacher I help thought I should try to write a program to multiple matrices.
At the moment, I have up to defining the numbers for the first array that holds the information for the first matrix. However, I have a small issue. As represented by this picture:
the line asking for the index integers is being repeated after already recording the integers. I assume this is due to my layered for loops, but I can't be for certain. Usually new eyes see problems clearer. Any who could help me would be appreciated.
Code:
package matrixmultiplication; import java.util.*; public class MatrixMultiplication { public static void main(String[] args) { System.out.println("What is the size of the first matrix?"); int matrix1Rows = matrixRows(); int matrix1Columns = matrixColumns(); int[] matrix1 = new int[matrix1Rows * matrix1Columns]; doubleSpace(); System.out.println("What is the size of the second matrix?"); int matrix2Rows = matrixRows(); int matrix2Columns = matrixColumns(); int[] matrix2 = new int[matrix2Rows * matrix2Columns]; doubleSpace(); if (matrix1Columns != matrix2Rows){ System.out.println("These cannot be multiplied!"); System.exit(0); } else { matrix1Numbers(matrix1Rows, matrix1Columns); } } public static int matrixRows(){ System.out.print("Rows:"); Scanner rowSc = new Scanner(System.in); int rows = rowSc.nextInt(); return rows; } public static int matrixColumns(){ System.out.print("Columns:"); Scanner colSc = new Scanner(System.in); int cols = colSc.nextInt(); return cols; } public static int[] matrix1Numbers(int rows, int cols){ int[] numb = new int[rows * cols]; for (int j = 0; j <= numb.length; j += rows){ for (int i = 1; i <= cols; i++){ for (int k = 1; k <= rows; k++){ System.out.println("What is the value for index (" + k + "," + i + ")?"); Scanner inp = new Scanner(System.in); if (j + k <= numb.length){ numb[j + k  1] = inp.nextInt(); } } } } for (int i = 0; i < numb.length; i++){ System.out.println(numb[i]); } return numb; } public static void doubleSpace(){ System.out.println(); System.out.println(); } }
I use NetBeans 8.2 and the latest working version of Java for NetBeans.