I'm not a programmer by any stretch of the imagination - I'm mainly an applied R user, working with various statistical models. That being said, I have a project for which moving some of my code to C++ would be very useful in the long term; right now it takes me four+ days to run my unoptimized model, using R's slow-as-Christmas loops.
I apologize if this is a very basic question, but I'm wondering how I might do the following in C++ (perhaps using the Armadillo templates) as part of the algorithm I'm working with: Given a numeric matrix X with i rows and j columns, how can I best get the sum of certain elementwise sums/products across the matrix, for example, sum(X_ij) for all i != j, or sum(X_ij*X_ji) for all i !=j? If it weren't for the i != j bit, I could just use some nested "for" loops, but I'm not sure of the best way to do it given that restriction. I'd ultimately like to be able to work with 3 or 4-way numeric arrays, not just a simple square matrix.
Any thoughts/pseudocode would be appreciated!
I apologize if this is a very basic question, but I'm wondering how I might do the following in C++ (perhaps using the Armadillo templates) as part of the algorithm I'm working with: Given a numeric matrix X with i rows and j columns, how can I best get the sum of certain elementwise sums/products across the matrix, for example, sum(X_ij) for all i != j, or sum(X_ij*X_ji) for all i !=j? If it weren't for the i != j bit, I could just use some nested "for" loops, but I'm not sure of the best way to do it given that restriction. I'd ultimately like to be able to work with 3 or 4-way numeric arrays, not just a simple square matrix.
Any thoughts/pseudocode would be appreciated!