#include <stdio.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#define WIDTH 400
#define HEIGHT 400
array complex_grid(
int width,
int height,
float zoom,
float center[2]) {
(
iota(dim4(1, height), dim4(width, 1)) - (float)height / 2.0) / zoom +
center[0];
(
iota(dim4(width, 1), dim4(1, height)) - (float)width / 2.0) / zoom +
center[1];
}
array mandelbrot(
const array &in,
int iter,
float maxval) {
for (int ii = 1; ii < iter; ii++) {
Z = Z * Z + C;
C = C * (1 - cond);
Z = Z * (1 - cond);
mag.eval();
}
return mag / maxval;
}
float mx = af::max<float>(a);
float mn = af::min<float>(a);
return (a - mn) / (mx - mn);
}
int main(int argc, char **argv) {
int device = argc > 1 ? atoi(argv[1]) : 0;
int iter = argc > 2 ? atoi(argv[2]) : 100;
bool console = argc > 2 ? argv[2][0] == '-' : false;
try {
printf("** ArrayFire Fractals Demo **\n");
float center[] = {-0.75f, 0.1f};
for (int i = 10; i < 400; i++) {
int zoom = i * i;
if (!(i % 10)) {
printf("iteration: %d zoom: %d\n", i, zoom);
fflush(stdout);
}
array c = complex_grid(WIDTH, HEIGHT, zoom, center);
array mag = mandelbrot(c, iter, 1000);
if (!console) {
if (wnd.close()) break;
array mag_norm = normalize(mag);
wnd.image(mag_norm);
}
}
fprintf(stderr,
"%s\n", e.
what());
throw;
}
return 0;
}
Window object to render af::arrays.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
@ f32
32-bit floating point values
@ AF_COLORMAP_SPECTRUM
Spectrum map (390nm-830nm, in sRGB colorspace)
AFAPI array abs(const array &in)
C++ Interface for absolute value.
AFAPI array complex(const array &real, const array &imaginary)
C++ Interface for creating complex array from two inputs.
AFAPI array sqrt(const array &in)
C++ Interface for square root of input.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
AFAPI array iota(const dim4 &dims, const dim4 &tile_dims=dim4(1), const dtype ty=f32)
array & eval(array &a)
Evaluate an expression (nonblocking).
AFAPI void setDevice(const int device)
Sets the current device.
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
AFAPI array max(const array &in, const int dim=-1)
C++ Interface for maximum values in an array.