IEEE-storage convention for real numbers

Recall that computers can only store discrete values in memory. What does this imply for the storage of real (floating-point) numbers in computers? Now consider the IEEE-storage convention for real numbers in computers for real32, real64, and real128 bit storage...

Intel OneAPI C/C++/Fortran Compiler Installation

Problem How can I install the Intel OneAPI C/C++/Fortran Compiler on Windows, Linux, or macOS? Solution The Intel OneAPI HPC toolkit provides a wide variety of High-Performance numerical libraries and tools, most importantly, the Intel Fortran and C/C++ compilers. However,...

Logic NAND and NOR

Recall the definitions of NAND and NOR from our lecture notes. Show that, \[\overline{(A \uparrow A) \downarrow (B \uparrow B)} \equiv (\overline{A} \downarrow \overline{A}) \uparrow (\overline{B} \downarrow \overline{B}) ~.\]

Logical implication in terms of logic functions

Consider the following logic functions, Show that, \[f_1(A, B) + f_3(A, B) + f_4(A, B)\] is equivalent to logical implication $A \Rightarrow B$.

Version-control: Setting up Git Software and GitHub Account

Git This exercise guides you through the steps needed to take to properly install and minimally use the git software and the Git Bash terminal on your system. By the end of this exercise, you will be able to initialize...

Performance benchmarking of naive matrix multiplication in Python vs. optimized libraries

Problem Write a Python function with the following interface that computes the matrix multiplication of two input matrices. def matmul(matA, matB): ... such that it returns the following result for the given input matrices. matA = [ [12, 7, 3]...

Performance benchmarking of naive matrix multiplication: naive vs. matmul vs. MKL

Problem Unlike The C/C++ programming languages, The Fortran language has native functions for matrix operations. The most important of these is the matmul intrinsic function, which has inspired all other programming languages for the same functionality. However, we can also...

Performance optimization: loop invariant code motion

Problem Consider the following Python code snippet, import numpy as np const = 256. x = [i for i in range(1, 100000)] z = np.zeros(len(x)) for i, element in enumerate(x): z[i] = np.sqrt(const) * x[i] What can you do to...

Performance optimization: Searching sorted array via linear vs. binary search

Problem Recall our discussion of linear vs. binary searching of sorted arrays for a particular value. Suppose we a set of nbin ascending-sorted histogram bins edges = range(nbin) and a given number x whose histogram bin i we wish to...

Performance optimization: Forced reduction - sin(x)cos(y) + cos(x)sin(y)

Problem Consider the following Python function, import numpy as np def getSCCS_slow(x, y): """ Return `sin(x) * cos(y) + cos(x) * sin(y)`. """ return np.sin(x) * np.cos(y) + np.cos(x) * np.sin(y) What can you do to the above code to...

Performance optimization: Forced reduction - sincos

Problem Consider the following Python function, import numpy as np def sincos(x): """ Return `sin(x) * cos(x)`. """ return np.sin(x) * np.cos(x) What can you do to the above code to make it more performant? Prove your suggestion by benchmarking...

Performance optimization: Forced reduction - hidden opportunities

Problem Consider the following Python function, import numpy as np def count(xvec): """ Return the count of elements of the input `xvec` whose natural logarithm is less than `0`. """ counter = 0 for element in xvec: if np.log(element) <...

Performance optimization: Breaking out of loop early

Problem Consider the following Python function, def any(boolVec): """ Return True if any of the elements of the input value are True, otherwise, return False. """ result = False for element in boolVec: result = result or element return result...

A naive implementation of Kmedoids clustering

Problem The K-medoids is a classical partitioning technique of clustering that splits the data set of $n$ objects into $k$ clusters, where the number $k$ of clusters is assumed to be known a priori. Unlike the K-means algorithm however, the...

Online comparison of the Kmeans clustering algorithm with DBSCAN

Problem On this website, you will find an online simulator of the Kmeans clustering technique. Visit this page and choose the first choice stating I’ll Chooose. You will be taken to a new page. On this new page, choose Smiley...

Online experimentation with DBSCAN clustering technique

Problem On this website, you will find an online simulator of the DBSCAN clustering technique. Visit this page and choose the first dataset option named Uniform. Recall from our lecture notes that the DBSCAN method has two free adjustable parameters...

Kmeans clustering - an implementation

Problem Consider this dataset points.txt. Write a script that reads this dataset and plots the second column of the dataset versus the first column as the following, Now write another script that applies Kmeans clustering technique to this data set...

Kmeans clustering: Determining the cluster number using the Elbow method

Problem Consider this dataset customers.csv of a Mall’s customers containing the details of customers in a mall. Our aim is to cluster the customers based on the relevant features “annual income” and “spending score”. Write a script that reads this...

Puzzle: Matchstick Wrong Equation

Problem Move just one matchstick in the following equation to make it hold.