Question: BLAS ( Basic Linear Algebra Subprograms ) is a library that serves as a fundamental building block for many numerical algorithms. For example, NVIDIA s

BLAS (Basic Linear Algebra Subprograms) is a library that serves as a fundamental building block for many numerical algorithms. For example, NVIDIAs cuBLAS library implements highly optimized parallel versions of BLAS functions for GPU computations. Almost all neural network- type AI algorithms and computer graphics algorithms that run on NVIDIA GPUs rely on cuBLAS. Likewise, Intel also provides its own BLAS library for computations on Intel CPUs. This question aims to implement a version of the gaxpy function in BLAS.
Gaxpy takes three inputs: an -by- matrix , an -vector , and an -vector . It outputs the vector +, which is an -vector equal to the sum of the matrix-vector product and the vector . For example,
213123+14+111[31][4]+[2]=[3314+2]=[7].12313+24+314
(a) Write a function Q1a_validate_vector(x) to validate that the input x is a proper vector, i.e., a list of numbers (int, float, or complex). Return True if the input is proper, False otherwise.
Note: 1. You may use isinstance(x, list) to check whether x is a list and use isinstance(z,(int, float, complex)) to check whether z is a number.
2. The result must be returned via some return statements. Outputs generated by print() statements will be ignored by the grader.
Sample input 1: [1,2,3] Return value(s): True Sample input 3: 1
Return value(s): False Sample input 5: [0,[]] Return value(s): False
Sample input 2: [1]
Return value(s): True Sample input 4: [[0,0,0]] Return value(s): False Sample input 6: []
Return value(s): False
(b) Write a function Q1b_validate_matrix(A) to validate that the input A is a proper matrix, i.e., a list of lists of numbers (int, float, or complex) and of rectangular shape. Return True if the input is proper, False otherwise. See the Note in part (a).
Sample input 1: [[2,1],[3,-1],[1,2]] Return value(s): True
Sample input 3: [[2,1],[3,-1]] Return value(s): True
Sample input 5: [[0],[0],[0]] Return value(s): True
Sample input 7: [0] Return value(s): False
Sample input 9: 1 Return value(s): False
Sample input 11: [[]] Return value(s): False
Sample input 13: [[[1,2],[3,4]]] Return value(s): False
Sample input 2: [[1,2,3],[4,5,6]] Return value(s): True
Sample input 4: [[0]] Return value(s): True
Sample input 6: [[0,0,0]] Return value(s): True
Sample input 8: [[1,2],[3,4,5,6]] Return value(s): False
Sample input 10: [] Return value(s): False
Sample input 12: [[],1] Return value(s): False
(c) Write a function Q1c_validate_size(A,x,y) to validate that the size of inputs are compatible for gaxpy, i.e., the number of columns in A equals the number of elements in x and the number of rows in A equals the number of elements in y. Return True if the inputs are compatible, False otherwise.
Note: 1. You may assume that A is a proper matrix, x and y are proper vectors, i.e., they pass the relevant tests in parts (a) and (b).
2. The result must be returned via some return statements. Outputs generated by print() statements will be ignored by the grader.
Sample input 1: [[2,1],[3,-1],[1,2]],[3,4],[1,2,3] Return value(s): True
Sample input 2: [[2,1]],[3,4],[1] Return value(s): True
Sample input 3: [[2,1,3],[-1,1,2]],[3,4],[1,2,3] Return value(s): False
Sample input 4: [[2,1],[3,-1],[1,2]],[3,4],[1,2] Return value(s): False
(d) Write a function Q1d_gaxpy(A,x,y) to compute and return the gaxpy. The output should be a list of numbers and of length equal to the length of y. The output should be a newly created list.
Note: 1. You may assume that the inputs are proper and compatible, i.e., they pass the relevant tests in parts (a)-(c).
2. The result must be returned via some return statements. Outputs generated by print() statements will be ignored by the grader.
Sample input 1: [[2,1],[3,-1],[1,2]],[3,4],[1,2,3] Return value(s): [11,7,14]
Sample input 2: [[1,2,3],[4,5,6]],[1,0,2],[2,3] Return value(s): [9,19]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!