Skip to content

Instantly share code, notes, and snippets.

Avatar

Drew Schmidt wrathematics

View GitHub Profile
@wrathematics
wrathematics / cor.cpp
Created Dec 12, 2021
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?
View cor.cpp
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 Nov 30, 2021
Use the hdfmat package to split an HDF5 matrix generated by armadillo into row chunks
View generate.cpp
// 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++)
View shrink_ooc.r
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
{
View shrink.r
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 Jun 15, 2021
out of core example with sqlite
View sqlite.r
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 Mar 1, 2021
Install (from) GitHub With Sub-Modules
View ighwsm.r
#' 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
View eval.r
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 Apr 3, 2020
monthly NICS background checks
View nics.csv
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
View Dockerfile
FROM alpine:3.10.2
RUN apk add R R-dev bash build-base
CMD ["/bin/bash"]
View manifest.r
pbd = c(
"hdfio",
"hpcvis",
"kazaam",
"pbdBASE",
"pbdCS",
"pbdDEMO",
"pbdDMAT",
"pbdIO",
"pbdML",