Week 5
Picking up the pace …. Hello everyone, hope this blog finds you well.
This week was an essential week as far as the robustness and concreteness of my project is concerned. We wrote tests for all kinds of numpy routines and this led to resolution of many bugs and edge cases.
Aim :
My aim for this week was to learn how to write pytest modules for array creation, manipulation, sorting, trigonometry, exponentiation and binary operations.
Following that I got started with the initial code for the numpy Random module.
Work :
I raised the following pull requests this week.
-
PR#13 : Make operators robust in comparison to numpy
This pull request makes the code use xtensor operators explicitly for reverse dunder operators.
- PR#14 : Add Array creation tests
arr1 = np.array([]) arr2 = np.array(10) arr3 = np.array([-2, -1, 0, 1, 2]) arr4 = np.array([[1, 2], [2, 1]]) arr5 = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) arr6 = np.array([[[[[1], [10], [100], [1000], [10000]]]]]) arr7 = np.array([[[2147483647]]]) arr8 = np.array([1, 2, 3, 4, 5], dtype='int8') arr8 = np.array([1, 2, 3, 4, 5], np.int8) arr9 = np.array([1, 2, 3, 4, 5], dtype='int16') arr9 = np.array([1, 2, 3, 4, 5], np.int16) arr10 = np.array([1, 2, 3, 4, 5], dtype='int32') arr10 = np.array([1, 2, 3, 4, 5], np.int32) arr11 = np.array([1, 2, 3, 4, 5], dtype='int64') arr11 = np.array([1, 2, 3, 4, 5], np.int64)
- PR#15 : Add tests for trigonometric functions
arr1 = np.array([np.pi / 6, np.pi / 4, np.pi / 3, np.pi / 2, np.pi]) assert np.allclose(np.sin(arr1), np.array([0.5, 0.707107, 0.866025, 1.0, 0.0])) assert np.allclose(np.cos(arr1), np.array([0.866025, 0.707107, 0.5, 0.0, -1.0])) assert np.allclose(np.tan(arr1), np.array([0.57735, 1.0, 1.73205, np.inf, 0.0])) arr2 = np.array([0.5, 0.707107, 0.866025, 1.0, 0.0]) assert np.allclose(np.arcsin(arr2), np.array([np.pi / 6, np.pi / 4, np.pi / 3, np.pi / 2, 0.0])) assert np.allclose(np.arccos(arr2), np.array([np.pi / 3, np.pi / 4, np.pi / 6, 0.0, np.pi / 2])) assert np.allclose(np.arctan(arr2), np.array([0.463648, 0.61548, 0.713724, 0.785398, 0.0]))
- PR#16 : Added tests for sorting functions
arr1 = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) arr1.sort() assert_equal(arr1, np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])) arr2 = np.array([9, 8, 7, 6, 5, 4, 3, 2, 1]) arr2.sort() assert_equal(arr2, np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])) arr3 = np.array([[-1], [-2], [-3]]) arr3.sort(0) assert_equal(arr3, np.array([[-3], [-2], [-1]])) arr4 = np.array([[[[[1.5, -1.5], [3.5, -3.5], [5.5, -5.5]]]]]) arr4.sort(3) assert_equal(arr4, np.array([[[[[1.5, -5.5], [3.5, -3.5], [5.5, -1.5]]]]]))
-
PR#17 : Added tests for array manipulation
This pull request adds tests for the following operations:
- Resize: Changes the shape and size of an array, padding or trimming elements if necessary.
- Reshape: Gives a new shape to an array without changing its data.
- Repeat: Repeats elements of an array along a specified axis.
- Squeeze: Removes single-dimensional entries from the shape of an array.
- Transpose: Permutes the dimensions of an array.
- Flatten: Returns a copy of the array collapsed into one dimension.
-
PR#18 : Initial implementation of the Random Class
This pull request adds tests for the following methods:
- Rand: Generates random values from a uniform distribution over [0, 1).
- Randn: Generates random values from a standard normal distribution (mean 0, variance 1).
- Randint: Generates random integers from a specified range.
- Uniform: Draws samples from a uniform distribution over a specified interval.
- PR#19 : Added test for exponential functions
arr1 = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) assert np.allclose(np.exp(arr1), np.array([1.0, 2.718282, 7.389056, 20.085537, 54.598150])) assert np.allclose(np.log(arr1), np.array([-np.inf, 0.0, 0.693147, 1.098612, 1.386294])) assert np.allclose(np.log2(arr1), np.array([-np.inf, 0.0, 1.0, 1.584963, 2.0])) assert np.allclose(np.log10(arr1), np.array([-np.inf, 0.0, 0.30103, 0.477121, 0.60206]))
Future Work :
In the upcoming week, I need to add more testing and starting fixing the bugs I encountered while writing tests this week.