Skip to content

Commit

Permalink
Listos ejercicios
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloalcain committed Nov 4, 2015
0 parents commit 3de37e5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pp.c
*.asm
*.o
*.e
*~
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Compiled languages into Python

En este hands-on vamos a practicar cómo llamar a una librería
nuestra desde python. En la carpeta `src/` tienen dos archivos de C.
Para completar este ejercicio tienen que hacer los siguientes pasos:

1. Compilar ambos archivos como objetos separados
2. Construir una librería dinámica que tenga ambos objetos
3. Escribir un script en python que pruebe **todas** las funciones
de la librería
19 changes: 19 additions & 0 deletions src/add_two.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* file: add_two.c */

float add_float(float a, float b) {
return a + b;
}

int add_int(int a, int b) {
return a + b;
}

int add_float_ref(float *a, float *b, float *c) {
*c = *a + *b;
return 0;
}

int add_int_ref(int *a, int *b, int *c) {
*c = *a + *b;
return 0;
}
19 changes: 19 additions & 0 deletions src/arrays.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* file: arrays.c */

int add_int_array(int *a, int *b, int *c, int n) {
int i;
for (i = 0; i < n; i++) {
c[i] = a[i] + b[i];
}
return 0;
}

float dot_product(float *a, float *b, int n) {
float res;
int i;
res = 0;
for (i = 0; i < n; i++) {
res = res + a[i] * b[i];
}
return res;
}

0 comments on commit 3de37e5

Please sign in to comment.