Skip to content

Instantly share code, notes, and snippets.

@geraintluff
Last active July 20, 2021 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraintluff/663e42e2519465e8b94df47793076f23 to your computer and use it in GitHub Desktop.
Save geraintluff/663e42e2519465e8b94df47793076f23 to your computer and use it in GitHub Desktop.
/// Example code for in-place multiplcation by a Householder matrix
void inPlaceHouseholder(double *arr, int size) {
// Division is slower, so compute this statically if you can
const double factor = -2.0/size;
double sum = 0;
for (int i = 0; i < size; ++i) {
sum += arr[i];
}
sum *= factor;
for (int i = 0; i < size; ++i) {
arr[i] += sum;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment