# CSE102 HW04 solved

\$35.00

## Description

5/5 - (1 vote)

Part 1 50pts
In this part, you will build an array with some modifications with the given array as input parameter and return it on output
elements) to left and right side of this array. Padding operation is explained below. addPadding function also takes array
size (integer), padding width (integer, number of elements that you will add both sides) and padding method (function
pointer) as argument. You must implement three different padding methods. These methods are described below:
Example:
inputArr: [5, 6, 7, 8, 9]
ouputArr: [0, 0, 0, 5, 6, 7, 8, 9, 0, 0, 0], paddingWidth: 3
-Same padding: Padding values are the value of the first element of input array (inputArr[0]) for left padding and
the value of the last element of input array (inputArr[arraySize-1]) for right padding.
ouputArr: [5, 5, 5, 5, 5, 6, 7, 8, 9, 9, 9, 9, 9], paddingWidth: 4
-Half padding: Padding values are half of the value of the first element of input array (inputArr[0]/2) for left padding
and half of the value of the last element of input array (inputArr[arraySize-1]/2) for right padding.
ouputArr: [2.5, 2.5, 5, 6, 7, 8, 9, 4.5, 4.5], paddingWidth: 2
assigned by calling the given function in paddingMethod parameter.

Note: You can assume that output array can have at most 255 elements.
Signature
Sample Usage
double inputArr = {5, 6, 7, 8, 9};
double outputArr[255];
int outputArrSize = 0;
Return Value
ouputArr: [5, 5, 5, 5, 5, 6, 7, 8, 9, 9, 9, 9, 9]
Part 2 50pts
In the second part, you will make a convolution operation over a given array. This operation has two components: First
component is an input array and second component is a kernel array. The relationship between these two components are
shown in figure 1. Kernel array moves on the input array in each iteration and calculates one array element for the output
array.
𝑜𝑛𝑒 𝑒𝑙𝑒𝑚𝑒𝑛𝑡 = 𝐾1 ∗ 𝐴𝑖 + 𝐾2 ∗ 𝐴𝑖+1 + ⋯ + 𝐾𝑗 ∗ 𝐴𝑖+𝑗−1
If you look at the output array in the figure 1, you can see that the size of the array shrinks after convolution operation. To
prevent that, you will add some padding to the inputArray and get an output array with the same size. You can use the
function that you wrote in the part 1 for the padding operation.
Another parameter, stride that effects the step for the convolution operation. Stride is the amount of kernel movement for
each iteration. Stride is 1 for the figure 1. If stride is 2, then you will move the kernel not one element, but 2 elements for
one iteration. If there is no error return 0, otherwise return -1.
PaddingType parameter is an enum type. Definition of that type is given below.
Error condition:
-kernelSize > inputArrSize return -1;
Figure 1: Convolution operation
Signature