[Weekly Review] 2019/12/16-22
2019/12/16-22
Last week, I cost Monday to review the growth in the last two weeks, and Tuesday to prepare for the presentation on Thursday. And also, I improved the program of matrix sum I wrote two weeks ago, with an additional C test file. I learned the basic Scala knowledge on Wednesday but still lack some practice. Thursday to Saturday, I followed Shien's advice to watch the tutorial provided by one team in MIT who creates the Eyeriss project. A module of one translation project related to Chisel, named Bootcamp
, also was done by me.
Unfortunately, due to the complex and chaos steps of both Rocket Core and FPGA, which need to boot Linux, I haven't done the hardware simulation. However, after the monthly report to my advisor in UESTC, I got a more simple method to skip the boot, I'd try after Shiqing came back.
So this week, I'll focus on some papers mentioned in the tutorial, including reference 1-5, and several papers Shien suggested me to read, including reference 6-14.
Functional Programming Principles in Scala
Week1
Classes, Traits, Objects and Packages
Classes
Like in Java, classes can be instantiated using the new construct, there can be many “instances” (or “objects”) of the same class. Classes in Scala cannot have static members. You can use objects (see below) to achieve similar functionality as with static members in Java.
Traits
Traits are like interfaces in Java, but they can also contain concrete members, i.e. method implementations or field definitions.
Objects
The Object in Scala are like classes, but for every object definition, there is only one single instance.
Packages
Adding a statement such as package foo.bar
at the top of a file makes the code in a file part of the package foo.bar
. If you define a class MyClass
in package foo.bar
, you can import that specific class (and not anything else from that package) with import foo.bar.MyClass
.
Source Files
Package hierarchies should be reflected in the directory structure: a source file defining class C in package foo.bar
should be stored in a subdirectory as foo/bar/C.scala
. Scala does not enforce this convention, but some tools such as the Scala IDE for eclipse might have problems otherwise.
Coursera Elements of Programming
In Scala, usually call-by-value
, but can use =>
to use call-by-name
.
If call-by-value
, then it will calculate the values of the arguments firstly.
Blocks
{}
The definitions inside a block are only visible from within the block
It's not just named space control but it's also reusing outer definitions without passing them explicitly in parameters.
Recursion
def factorial(n: Int): Int =
if (n == 0) 1 else n * factorial(n-1)
Week2
High Order Functions
Function Type
def sum(f: Int => Int, a: Int, b: Int): Int =
if (a > b) 0
else f(a) + sum(f, a + 1, b)
def cube(x: Int): Int = x*x*x
def id(x:Int): Int = x
def sumInts(a: Int, b: Int) = sum(id, a, b)
def sumCubes(a: Int, b: Int) = sum(cube, a, b)
Anonymous Function
(x: Int) => x * x * x
(x: Int, y: Int) => x + y
def sum(f: Int => Int, a: Int, b: Int): Int =
if (a > b) 0
else f(a) + sum(f, a + 1, b)
def sumInts(a: Int, b: Int) = sum(x = > x, a, b)
def sumCubes(a: Int, b: Int) = sum(x => x * x * x, a, b)
def sum(f: Int => Int)(a: Int, b: Int): Int =
if (a>b) 0
else f(a) + sum(f)(a + 1, b)
def sumInts = sum(x => x)
def sumCubes = sum(x => x * x * x)
sumCubes(1, 10) + sumInts(10, 20)
Require and Assert
val x = sqrt(y)
assert(x >= 0)
class Balabala(x: Int, y: Int){
require(y != 0, "y must be nonzero")
}
Efficient Processing of Deep Neural Network: from Algorithms to Hardware Architectures
OneNote