Taggar » Matrix

The Matrix - Final Explicit Disclosure

First lets take a last look at this phenomena of agents in our lives we are battling with due to duality.

Everyone has at least one of these agents in their lives, you can deny it as much as you like, the truth of the matter is that your denial is proof of your ignorance. 2 173 fler ord

Matrix

DeGrasse Tyson pushes Matrix-like theory of reality, still mocks Christians

Your friendly neighborhood blogger is always perusing the internet for science-related news. Given that fact, it did not go unnoticed that two stories pushing the idea that reality is all an illusion gained widespread media attention over the past month. 651 fler ord

Culture

More Drake Reference Tracks Leak

Talk about timing. On the heels of Drake’s biggest first week sales with VIEWS, reference tracks come out the woodworks. 189 fler ord

Matrix

[LeetCode] Game of Life

题目:
实现game of life演变的函数
https://leetcode.com/problems/game-of-life/

解法:
1)开一个新的矩阵,算好了再copy回去
2)不用额外空间,因为矩阵元素是int类型,但是每个cell的状态只有两种可能,所以可以用int的别的bit来存新的状态。算好了在把原来的状态覆盖过去

如果要性能的进一步优化:
1)可以把八个方向的check展开成八个statement,然后让编译器去优化,这是loop unrolling
2)多核机器的话,可以把把矩阵切成多个小的矩阵,并行处理,然后需要有一个master来管理所有矩阵的边缘信息。需要注意的是如果每个矩阵太大,并行度很差。如果每个矩阵太小,communication cost很大。
3)多台机器的话,map-reduce。不知道怎么写map和reduce的函数
4)把周围的八个点看作是一个environment,用一个变量存起来。在处理每一行的时候,可以re-use一部分之前environment的计算结果。这样的好处是,计算每个点死活的时候,不需要读取8个邻居,只需要读取三个邻居。每次读取都是一次memory access。核心思想就是减少内存读取。
5)如果矩阵很稀疏。可以只计算live cell及其邻居,因为只有live cell才能把dead cell起死回生
6)传统算法中,检查邻居,是row-by-row,不是column-by-column,这样可以利用cache
7)传统算法中,可以把矩阵外面包一圈dead cell,这样就不需要检查newX和newY是否越界。好处是省去了if语句,减少branch misprediction
8)可以用hashlife,这是一个memoization algorithm,没大看懂,目测是把曾经计算过的pattern存下来,这样遇到同样的pattern就不需要计算了。坏处是memory开销很大。 275 fler ord

Google turns New Yorkers into real-life lab rats

Failed proposal for the NYC 2012 Olympics stadium at Hudson Yards.

Instrumental City: The View from Hudson Yards, circa 2019

The world’s most ambitious “smart city” project is here. 768 fler ord

Visions

Are There Barbarians at the Gates of Science?

ILLUSTRATION BY FRANCESCO IZZO

The increasingly complex border between science and society is changing both.

BY ROBBERT DIJKGRAAF

Alessandro Baricco paints a lively portrait of the modern-age barbarian in his 2014 book, The Barbarians… 803 fler ord

Visions