Skip to content

Instantly share code, notes, and snippets.

@rpgoldman
rpgoldman / gist:1152035
Created August 17, 2011 17:07
First shot at an &rest arguments function
(defrecord complex [real imag])
(defn add [c1 c2 & x]
(if (nil? x)
(complex. (+ (:real c1) (:real c2))
(+ (:imag c1) (:imag c2)))
(add (add c1 c2) (first x) (rest x))))
;; probably this last line is buggy --- there's almost certainly an idiomatic way to do
;; what I would do as (apply ADD (add c1 c2) (first x) (rest x))
@rpgoldman
rpgoldman / bug.clj
Created August 18, 2011 02:03
Problem with protocol implementation...
(ns rpg.bug
(:require clojure.contrib.math))
(defprotocol CPARTS
(real [c])
(imag [c])
(modulus [c])
(phase [c]))
(defrecord complex [real imag]
@rpgoldman
rpgoldman / python-profile-after.txt
Last active December 30, 2020 18:44
Python profile from successful and unsuccessful vectorized posterior predictive sampling
Vectorized sample posterior predictive took 590.47s
273802490 function calls (273799694 primitive calls) in 590.469 seconds
This is from a very slow run of `pm.fast_sample_posterior_predictive` -- it generated 1/40 the samples in 50x the time.
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
176 0.000 0.000 0.012 0.000 <__array_function__ internals>:2(all)
7200000 7.833 0.000 90.115 0.000 <__array_function__ internals>:2(any)
@rpgoldman
rpgoldman / python-profile-before.txt
Last active December 30, 2020 18:42
Profile output from successful vectorized posterior predictive sampling.
Vectorized sample posterior predictive took 11.62 seconds
2259149 function calls (2258633 primitive calls) in 11.615 seconds
This is for a successful, quick run of `pm.fast_sample_posterior_predictive`
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
2 0.000 0.000 0.000 0.000 <__array_function__ internals>:2(all)
48000 0.128 0.000 1.304 0.000 <__array_function__ internals>:2(any)
@rpgoldman
rpgoldman / Dask column assignment snippet.py
Last active January 7, 2021 16:36
Problems computing a new column value from an existing dask dataframe column
# Here's what I do to get my background data (sorry, not public)
df = dd.read_csv('r1c5va879uaex_r1c639xp952g4.csv', assume_missing=True)
# Now, in order to add a column, I need to be able to add metadata --
# if I don't, I get mysterious errors about failing to infer types
newmeta = df._meta.copy() # get the original metadata
# add new column to metadata
newmeta.insert(len(newmeta.columns), 'well', 'foo')
# specify the dtype of the new column
newmeta = newmeta.astype({'well': str})
@rpgoldman
rpgoldman / Xarray indexing.ipynb
Last active April 10, 2021 00:42
Attempt to get and use xarray coordinates
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rpgoldman
rpgoldman / aaai21.sty
Last active May 12, 2021 18:59
Problem with typesetting math symbols
\def\year{2021}
%
%Filename: aaai21-mod.sty
%
\typeout{Conference Style for AAAI for LaTeX 2e -- version for the AAAI-21 conference - MODIFIED}
% WARNING: IF YOU ARE USING THIS STYLE SHEET FOR AN AAAI PUBLICATION, YOU
% MAY NOT MODIFY IT FOR ANY REASON. MODIFICATIONS (IN YOUR SOURCE
% OR IN THIS STYLE SHEET WILL RESULT IN REJECTION OF YOUR PAPER).
%
% WARNING: This style is NOT guaranteed to work. It is provided in the
@rpgoldman
rpgoldman / README.md
Last active June 13, 2021 01:05
PyMC3 seg fault replication data

The python script triggered the segmentation fault that is summarized in the gdb backtrace. Python provided no information beyond "Segmentation fault".

The two data files should be placed in a directory named ap as a sibling of the python script. These files are taken from the lda-c repository of the Blei lab.

import argparse
import os
from rdflib import Graph
from sys import stdout
def JSON_prefixes(g: Graph, stream):
"""
Extract prefix definitions from `g` `and write them to `stream`.
openapi: 3.0.0
info:
description: 'Owlery provides a web API for an [OWL API](http://owlapi.sourceforge.net)-based
reasoner containing a configurable set of ontologies (a "knowledgebase"). '
version: 1.0.0
title: Owlery API
contact:
email: [email protected]
license:
name: MIT