DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015.

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

the c language BY SA 1972 by Ken Thompson and Dennis Ritchie.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.

void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
WEEK 5 Class Activities Lecturer’s slides.
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Introduction to Programming Lecture 39. Copy Constructor.
Lab 8 User Defined Function.
Pointers & Dynamic Memory Allocation Mugurel Ionu Andreica Spring 2012.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Pointer, malloc and realloc 1. Name entered was 6 char, not enough space to put null terminator 2 Array of char.
C Pointers Systems Programming Concepts. PointersPointers  Pointers and Addresses  Pointers  Using Pointers in Call by Reference  Swap – A Pointer.
C Pointers Systems Programming. Systems Programming: Pointers 2 Systems Programming: 2 PointersPointers  Pointers and Addresses  Pointers  Using Pointers.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility,
Lectures for cross-layer design (swallow, but, enough to understand the other) Wed Uhr Doug Young Suh Media Lab. Last update : May.
CSI2172
DSP Lab. Week 5 complex Doug Young Suh Media Lab. Rm401 Last update : September 16, 2015.
1 ร. ศ. ดร. สุเทพ มาดารัศมี Understanding Pointers in C Chapter 10 of Programming with C Book.
Arrays in C.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
Multimedia Systems MW 12:00-13:15, Rm445 Doug Young Suh Media Lab. Rm401 Last update : August 30, 2015.
Lecture 9.4 Java Interfaces. © 2006 Pearson Addison-Wesley. All rights reserved Java does not support multiple inheritance. Interface Characteristics...
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Pointers Value, Address, and Pointer. Values and Addresses int x, y, z; y x z values of x,
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Lecture 7: Arrays BJ Furman 06OCT2012. The Plan for Today Announcements Review of variables and memory Arrays  What is an array?  How do you declare.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
CS180 Recitation Chapter 7: Defining Your Own Classes II.
Chapter 1. Experiments and Probabilities Doug Young Suh Media Lab.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
Windows Programming Lecture 03. Pointers and Arrays.
DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
“Studying C programming excluding pointers is meaningless.” d0m3z
Recursion.
Basic notes on pointers in C
Tejalal Choudhary “C Programming from Scratch” Pointers
DSP Lab. Week 7 CDMA and noise
מיחזור במערכת החינוך.
DSP Lab. Week 1 Drawing sinusoidal waves
Pointers  Week 10.
Systems Programming Concepts
Pointers & Functions.
CS111 Computer Programming
Recursion.
Local Variables, Global Variables and Variable Scope
By Hector M Lugo-Cordero September 17, 2008
Introduction to C++ Programming Language
Default Arguments.
Recap Week 2 and 3.
Lecture 2 SCOPE – Local and Global variables
DSP Lab. Week 12 DFT audio Doug Young Suh Media Lab. Rm401
7. Pointers, Dynamic Memory
C (and C++) Pointers April 4, 2019.
IPC144 Introduction to Programming Using C Week 6 – Lesson 1
GPU Lab1 Discussion A MATRIX-MATRIX MULTIPLICATION EXAMPLE.
Pointers & Functions.
The Stack.
C Pointers Systems Programming.
Pointer Arithmetic By Anand George.
Presentation transcript:

DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015

Matrix multiplication MediaLab, Kyunghee University2

Pointer (address) RAM 상의 주소 한번 건너뛰는 byte 수는 type 에 따라 다르다 예 ) int a, A[4], *aa; short b,*bb; aa = A+2; A[0] = 3; A[1] = -3; A[2] = 2; A[3] = 1; A[4] = 7; // error!! aa[-1] = 5; aa[1] = 3; // *(aa+1) = 3; 과 같다. bb = (short *)(A+1) + 1; *(bb+3) = 5; // 어떻게 되나 ? MediaLab, Kyunghee University3 RAM &a A A+1 aa bb 0

Function int set3( ); void main( ){ …. int a; a = set3( ); …. } int set3( ){ return 3; } MediaLab, Kyunghee University4 void set3(int * ); void main( ){ …. int a; set3(&a); …. } void set3(int *b ){ *b = 3; return; } int a; // global void set3( ); void main( ){ …. set3( ); …. } void set3( ){ a = 3; return; } void set3(int * ); void main( ){ …. int *a, x; a = &x; set3(a); …. } void set3(int *b ){ *b = 3; return; } a 에 3 이라는 값을 넣는 함수

C-program (pointer and function) 1. #include 2. #include 3. int matrixMultiplication(int *, int *, int *,int, int, int); 4. float ff; // global variable 5. int main(){ 6. int *A,*B,*C, m,n,p; 7. m=2; n=3, p=2; 8. A = new int[m*n]; B = new int[n*p]; C = new int[m*p]; 9. A[0] = 2;A[1] = 3;A[2] = 4; *(A+n) = 5;A[n*1+1] = 6;A[5] = 7; 10. B[0] = 2; B[1] = 3; B[2] = 5; B[3] = 7; B[4] = 1; *(B+p*2+1) = 3; 11. matrixMultiplication(A, B, C, m, n, p); 12. printf("A\n"); 13. for(int mm=0;mm<m;mm++){ printf("\n"); for(int nn=0;nn<n;nn++) printf(" %3d",A[mm*n+nn]); } 14. return 1; 15. }// end of main 16. int matrixMultiplication(int *a, int *b, int *c,int m, int n, int p){ 17. int dum; 18. for(int j = 0; j<m; j++) 19. for(int k = 0; k<p; k++){ 20. dum = 0; 21. for(int l=0;l<n;l++) dum += a[j*n+l] * b[l*p+k]; 22. c[j*p+k] = dum; 23. } 24. return 1; 25. } MediaLab, Kyunghee University5 main 이라는 function 꼭 하나는 있 어야 … 내가 만든 function 선언 Return type 주고받는 data types