RSSAmplifier

Blog

Zhéyuán Chén

Zhéyuán Chén's homepage

czheo.github.ioRSS feed ↗10 posts

Latest posts

Model Training Memory Simulator

What This Visualizes This simulator models a simplified training input pipeline as three stages: Data loading into a CPU-side prefetch queue (often pinned host memory). Host-to-device transfer into a GPU-side VRAM backlog queue. GPU compute consuming queued batches. Each stage has a throughput and each queue has a capacity. The key idea is that memory pressure is created by mismatch between rates…

Park construction observation journal

Recently, construction started at a park near my home. It has presented me with a unique opportunity to observe the intricacies of a construction site up close. Having majored in urban planning, I find it especially enlightening to witness these procedures firsthand. Just today, I noticed a new addition to the site – straw wattles. They were installed along the edges. A shallow trench was dug…

Humbled by Fork

Luckily, I have never had to use fork() in my everyday work. Otherwise, I guess I would produce 10x more bugs. Here is an example why I think so. In a nutshell, fork() creates a child process who copies the parent’s current status, including the instruction pointer, data/stack/heap space and etc. Here’s a short example. // test.c #include <stdio.h> #include <unistd.h> int main () { int x = 42 ; if…

Combinatorics is Fun

I did some fun combinatorial exercises to reach an optimal O(n) solution for an “easy” level leetcode problem (LeetCode 1588) . Look at the problem and think for 5 minutes. It is relatively easy to reach this approach: For each element \(a_i\), if you can find the count of odd-length sub-arrays containing it, denoted as \(n_i\), the sum of all odd-length sub-arrays will be equal to \(\sum a_i…

Java Duck Typing without Reflection

Can we implement duck typing in Java without using reflection? Consider there are 2 classes defined by an external library that is out of our control. class Duck { void swim () {...} } class Whale { void swim () {...} } We cannot do below. Stream . of ( new Duck (), new Whale ()). forEach ( obj -> { obj . swim (); // Compilation error since obj is of type `Object` which has no swim() method });…

Streaming birds using Raspberry Pi

最近几天,我家阳台经常出现了一只哀鸽(mourning dove)。 这是北美常见的一种鸟,它一大早就来,停在那里像是观察什么。 前天,忽然出现了两只鸽子,一只趴在壁灯上,另一只衔来树枝给它,想必是要筑巢。 然而一天下来再去观察,由于壁灯上空间太小,树枝一根不剩全掉落在地上。 于是昨天一大早,我用包装鸡蛋的纸盒,给它们搭了一个宽敞些的台子。 它们看起来甚是喜欢,雄鸟不断衔来新的树枝,雌鸟负责做窝,一整天下来鸟巢有了不少起色。 可是好景不长,傍晚时分我再去看时,地上树枝散落一地,还有一个碎掉的鸟蛋。 鸟巢还没造好,就失去一个未出世的孩子,想必非常可怜。 晚上,雌鸟在那里一动不动地趴了一夜。 今天一大早,我早早起床,看那雌鸟还在那里趴着。 不久,雄鸟飞来把它接走,我开始担心它们不会回来了。 不过趁它们不在,我又稍微加固了平台。 把原先三面围合的平台,做成了四面围合,希望这样鸟蛋不要再掉下来了。…

Name of my son

Our newborn son just arrived in the early morning on July 26, Sunday. My wife and I decided to name him “Luke”. According to Wikipedia , The name Luke is the English form of the Latin name Lucas. It is derived from the Latin name Lucius, and it either means “the great Lucius”, or it is a shortened form of the Latin name. Lucius means “the bright one” or “the one born at dawn” Meanwhile, Luke is…

The first argument of Stream::reduce does not need to be an identity in Java

The official documentation of Java claims that the first argument of T Stream::reduce(T identity, BinaryOperator<T> accumulator) must be an identity. The identity value must be an identity for the accumulator function. This means that for all t, accumulator.apply(identity, t) is equal to t. The accumulator function must be an associative function. Stream::reduce works almost identically to foldl…

Yet Another e Explained

不尽人意的例子 虽然有不少关于自然常数e的解释,浏览下来不少都从复利计算的例子展开。 其中的逻辑是,如果年利率是100%,如果按每年计算利息,一年后获得的财富将是200%; 如果按每半年,一年后获得\((1 + \frac{100\%}{2})^2 = 225\%\); 如果按每月,一年后获得\((1 + \frac{100\%}{12})^{12} = 261.3\%\); 如果按无限小的时间单位计算,一年后获得\(\underbrace{(1 + \frac{1}{N})^N}_{N \rightarrow \infty}\),而这个数就是e。…

One-liner curry decorator in Python

I discovered the following trick. from functools import partial curry = lambda n : partial ( * [ partial ] * n ) Usage: @ curry ( 3 ) def add ( x , y , z ): return x + y + z print ( add ( 2 )( 3 )( 4 )) # output = 9 A more obfuscated way will be: from functools import partial curry = lambda f : partial ( * [ partial ] * f . __code__ . co_argcount )( f ) Usage @ curry def add ( x , y , z ): return…