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!
/* | |
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. |
WIP - There is still much to learn.
################################################################################
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.
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
.
From the Cppreference page:
# 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 |
# 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?) | |
# |
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 |
/// 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 |
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() |