deanwampler / spark-scala-tutorial

A free tutorial for Apache Spark.
Other
985 stars 430 forks source link

Fixing the order of the NxM code in Matrix4 #41

Closed Jmgiacone closed 6 years ago

Jmgiacone commented 6 years ago

I was going through Matrix4 in the tutorial earlier today and was confused as to why this piece of code was creating a Seq from 1 to m instead of 1 to n

sc.parallelize(1 to dimensions.m)

I launched the code in a debugger and it turns out that the problem was with the handling of the regex being converted into the Dimensions case class. The line case dimsRE(m, n) => Dimensions(m.toInt, n.toInt) switches the order of the dimensions and then passes them to Dimensions. The code still works as intended because the rest of it refers to m as the number of rows and n as the number of columns

The below screenshot was taken while debugging Matrix4 using the default arguments ss 2018-08-22 at 21 03 09 png

In my fix, I swapped the ordering of m and n to reflect the original intent and edited a few bits of code so that the output would still be as intended