Skip to content

Instantly share code, notes, and snippets.

View wrathematics's full-sized avatar

Drew Schmidt wrathematics

View GitHub Profile
@wrathematics
wrathematics / cor.cpp
Created December 12, 2021 18:31
Amusing bug. This computes the pearson correlation of 2 vectors correctly on a small test case if the omp pragma is present, and incorrectly if it is removed. Do you see why?
template <typename REAL>
REAL cor(const cpuvec<REAL> &x, const cpuvec<REAL> &y)
{
const len_t n = x.size();
if (n != y.size())
throw std::runtime_error("non-conformal arguments");
const REAL *x_d = x.data_ptr();
const REAL *y_d = y.data_ptr();
@wrathematics
wrathematics / generate.cpp
Last active November 30, 2021 12:54
Use the hdfmat package to split an HDF5 matrix generated by armadillo into row chunks
// h5c++ generate.cpp -o generate
#include <string>
#define ARMA_USE_HDF5
#include <armadillo>
static inline void gen(const int m, const int n, std::string fname)
{
arma::fmat x(m, n);
for (int j=0; j<n; j++)
pvt.powscor_mod = function(x, alpha, lambda, w)
{
#### determine correlation shrinkage intensity
if (missing(lambda))
{
lambda = corpcor:::estimate.lambda(x, w, verbose=FALSE)
lambda.estimated=TRUE
}
else
{
pvt.powscor_mod = function(x, alpha, lambda, w)
{
#### determine correlation shrinkage intensity
if (missing(lambda))
{
if (comm.rank() == 0)
lambda = corpcor:::estimate.lambda(x, w, verbose=FALSE)
else
lambda = NULL
@wrathematics
wrathematics / sqlite.r
Created June 15, 2021 17:14
out of core example with sqlite
library(DBI)
library(RSQLite)
# create fake data
set.seed(1234)
n = 100
big_tbl = data.frame(
ind = 1:n,
x = runif(n),
y = rnorm(n)
@wrathematics
wrathematics / ighwsm.r
Created March 1, 2021 15:07
Install (from) GitHub With Sub-Modules
#' ighwsm
#' Install (from) GitHub With Sub-Modules. Use when
#' \code{remotes::install_github()} fails.
#'
#' @details
#' Wrapper around \code{system()}.
#'
#' @param repo
#' GH repo of the usual form: \code{name/project}.
#' @param save_clone
f = function(expr)
{
for (i in 1:2)
print(system.time(eval(expr))[[3]])
}
f(Sys.sleep(.4))
## [1] 0.401
## [1] 0
@wrathematics
wrathematics / nics.csv
Created April 3, 2020 17:07
monthly NICS background checks
Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Totals
1998 871644 892840
1999 591355 696323 753083 646712 576272 569493 589476 703394 808627 945701 1004333 1253354 9138123
2000 639972 707070 736543 617689 538648 550561 542520 682501 782087 845886 898598 1000962 8543037
2001 640528 675156 729332 594723 543501 540491 539498 707288 864038 1029691 983186 1062559 8910191
2002 665803 694668 714665 627745 569247 518351 535594 693139 724123 849281 887647 974059 8454322
2003 653751 708281 736864 622832 567436 529334 533289 683517 738371 856863 842932 1008118 8481588
2004 695000 723654 738298 642589 542456 546847 561773 666598 740260 865741 890754 1073301 8687671
2005 685811 743070 768290 658954 557058 555560 561358 687012 791353 852478 927419 1164382 8952945
2006 775518 820679 845219 700373 626270 616097 631156 833070 919487 970030 1045194 1153840 10036933
@wrathematics
wrathematics / Dockerfile
Created September 4, 2019 19:58
alpine linux + R
FROM alpine:3.10.2
RUN apk add R R-dev bash build-base
CMD ["/bin/bash"]
pbd = c(
"hdfio",
"hpcvis",
"kazaam",
"pbdBASE",
"pbdCS",
"pbdDEMO",
"pbdDMAT",
"pbdIO",
"pbdML",