Skip to content

Instantly share code, notes, and snippets.

View cswiercz's full-sized avatar

Chris Swierczewski cswiercz

View GitHub Profile
@cswiercz
cswiercz / gist:066cec5f23ecc2b889bb06bdac8f2a94
Created August 23, 2022 17:11
Abelfunctions Performance Profile
Performance profile on the following Python script:
from sage.all_cmdline import * # import sage library
_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_7 = Integer(7)
from abelfunctions import *
R = QQ['x, y']; (x, y,) = R._first_ngens(2)
X = RiemannSurface(y**_sage_const_3 + _sage_const_2 *x**_sage_const_3 *y - x**_sage_const_7 )
X.riemann_matrix()
@cswiercz
cswiercz / main.rs
Created March 7, 2021 21:25
Shared memory access in random cut trees
/// A forest contains a collection of trees and a shared storage for
/// points in the tree. However, each of the trees need to mutably access
/// the point store. For convenience, the trees are initialized using a
/// pointer to the shared point store.
///
/// This code shows one way to perform this two-way mutable share where the
/// forest owns all of the constituent data structures.
///
/// * Rc: allows multiple (reference counted) pointers to a type
/// * RefCell: wraps the type in a mechanism that allows mutation through
@cswiercz
cswiercz / plotting_example.py
Created March 23, 2020 20:51
Example pandas plotting by label
import pandas as pd
import matplotlib.pyplot as plt
# obtain example dataset
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
# get the matplotlib default color cycle
cycle = iter(plt.rcParams['axes.prop_cycle'].by_key()['color'])
# use pandas to plot by label
@cswiercz
cswiercz / .bashrc_ps1
Created December 19, 2019 21:26
Custom Bash Prompt
# A custom prompt that looks like this:
#
# <NEWLINE>
# (conda-environment) (current-datetime) [current-full-directory]
# username@host $
#
# First clear the PS1 variable. This allows conda setup to populate the PS1 with
# the current anaconda environment before we create a custom prompt. Necessary
# because I want a newline before each prompt. (Maybe better way?)
#
@cswiercz
cswiercz / mnuk_conditions_fraction_fields.py
Created February 23, 2018 01:10
mnuk_conditions() Fraction Field Timing Test
# coding: utf-8
# In[1]:
R = QQbar['x,y']
x,y = R.gens()
g1 = x^4 + x^2*y^2 + (-2)*x^2*y - x*y^2 + y^2
g2 = -x^7 + 2*x^3*y + y^3
@cswiercz
cswiercz / reference_wrappers.md
Last active May 11, 2020 21:13
C++11 Reference Wrappers

My Problems (There Are Many)

The C++ standard library containers are nice. Like, really nice. As the kind of person who worries about performance to the point that they were shy of anything other than a raw data array I've come to appreciate the usability (and speed!) of ye olde std::vector. Does that many me sound like a wannabe oldie?

Recently I came across a situation where I had, say, a vector [a, b, c, d] and wanted to create the vectors [a, b, c], [a, b, d], [a, c, d], and [b, c, d]. I didn't want to actually allocate O(N(N-1)) additional memory but learned that std::vector didn't support holding references. That's when I came across std::reference_wrapper.

Reference Wrappers

From the Cppreference page:

@cswiercz
cswiercz / introduction-to-new-operators.md
Last active July 6, 2017 15:42
Introduction to Creating a New MXNet Operator

WIP - There is still much to learn.

Creating a New MXNet Operator

################################################################################ Let's begin by creating a simple, near-minimal working example. I'll start with the code and then walk through each component. We will create an operator, add_one() which will take a vector as input, add one to each element, and return the result.

@cswiercz
cswiercz / cached_factory.cpp
Last active June 15, 2022 03:04
Herb Sutter's favorite sub-10 line C++ snippet: Factory w/Cache
/*
Cached Factory
Sometimes you want to make objects with a lifetime managed
by their target owner but you also want to hold reference
to them in a custom cache. The target owner, naturally, will
be given a shared_ptr to the output object. However, we don't
want the lifetime of the output object to be tied to the
internal cache. I.e. if the owner dies then the object should
die even if referenced in the cache.
@cswiercz
cswiercz / diagram.md
Created July 27, 2016 23:00
Testing sequence diagrams in GitHub.

Sequence Diagrams in GitHub

js-sequence-diagrams turns text into UML sequence diagrams. However, jsseq and sequence code blocks do not automatically render in GitHub. A Google Chrome plugin Github sequence diagrams allows rendering of sequence diagrams within GitHub!

An Example Sequence Diagram