Skip to content
Snippets Groups Projects
Commit 3340dacb authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Renamed mendel into mandel

parent 71af6db6
No related branches found
No related tags found
No related merge requests found
mendel.so:mendel_module.o libmendel.so
all: mandel.so libmandelc.so
mandel.so:mandel_module.o libmandel.so
g++ -shared $^ -o $@
mendel_module.o:mendel_module.cpp
mandel_module.o:mandel_module.cpp
g++ -pthread -O3 -Wall -std=c++14 -fPIC -I. -I/usr/include/python2.7 -c $< -o $@
libmendelc.so:mendel_cwrapper.o libmendel.so
libmandelc.so:mandel_cwrapper.o libmandel.so
g++ -shared $^ -o $@
mendel_cwrapper.o:mendel_cwrapper.cpp
mandel_cwrapper.o:mandel_cwrapper.cpp
g++ -O3 -Wall -std=c++14 -fPIC -c $< -o $@
libmendel.so:mendel.cpp Complex.hpp
libmandel.so:mandel.cpp Complex.hpp
g++ -shared -O3 -Wall -std=c++14 -fPIC $< -o $@
clean:
......
#include "mendel.hpp"
#include "mandel.hpp"
int mendel(const Complex &a) {
int mandel(const Complex &a) {
Complex z = 0;
for (int n = 1; n < 100; n++) {
z = z*z + a;
......
#include "Complex.hpp"
/**
* computes number of iterations of the mendelbrot
* computes number of iterations of the mandelbrot
* formula you need before reaching a norm > 2
* returned value is -1 if 100 iterations are reached
* without reaching it
*/
int mendel(const Complex &a);
int mandel(const Complex &a);
File moved
from pylab import *
from numpy import NaN
from mendel import mendel
from mandel import mandel
X = arange(-2, .5, .002)
Y = arange(-1, 1, .002)
......@@ -9,7 +9,7 @@ Z = zeros((len(Y), len(X)))
for iy, y in enumerate(Y):
print (iy, "of", len(Y))
for ix, x in enumerate(X):
v = mendel(x, y)
v = mandel(x, y)
if v >= 0 :
Z[iy,ix] = v
else:
......
......@@ -3,7 +3,7 @@ from numpy import NaN
from ctypes import *
# interface with C library
libmendel = CDLL('libmendelc.so')
libmandel = CDLL('libmandelc.so')
X = arange(-2, .5, .002)
Y = arange(-1, 1, .002)
......@@ -12,7 +12,7 @@ Z = zeros((len(Y), len(X)))
for iy, y in enumerate(Y):
print (iy, "of", len(Y))
for ix, x in enumerate(X):
v = libmendel.mendel(c_float(x), c_float(y))
v = libmandel.mandel(c_float(x), c_float(y))
if v >= 0 :
Z[iy,ix] = v
else:
......
#include "mandel_cwrapper.hpp"
extern "C" {
int mandel(float r, float i) {
return mandel(Complex(r, i));
}
}
#include "mandel.hpp"
extern "C" {
int mandel(float r, float i);
}
#include <Python.h>
#include "mendel.hpp"
#include "mandel.hpp"
static PyObject * mendel_wrapper(PyObject * self,
static PyObject * mandel_wrapper(PyObject * self,
PyObject * args) {
// Parse Input
float r, i;
if (!PyArg_ParseTuple(args, "ff", &r, &i)) return NULL;
// Call C function
int result = mendel(Complex(r, i));
int result = mandel(Complex(r, i));
// Build returned objects
return Py_BuildValue("i", result);
}
static PyMethodDef MendelMethods[] = {
{"mendel", mendel_wrapper, METH_VARARGS, "computes nb of iterations for mendelbrot set for a given complex number"},
{"mandel", mandel_wrapper, METH_VARARGS, "computes nb of iterations for mandelbrot set for a given complex number"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC initmendel(void) {
(void) Py_InitModule("mendel", MendelMethods);
PyMODINIT_FUNC initmandel(void) {
(void) Py_InitModule("mandel", MendelMethods);
}
#include "mendel_cwrapper.hpp"
extern "C" {
int mendel(float r, float i) {
return mendel(Complex(r, i));
}
}
#include "mendel.hpp"
extern "C" {
int mendel(float r, float i);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment