mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
fix mandelbrot compilation, and make it use Array instead of Matrix
This commit is contained in:
parent
c64c0f382f
commit
f1104a3b0f
@ -23,6 +23,7 @@
|
|||||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "mandelbrot.h"
|
#include "mandelbrot.h"
|
||||||
|
#include <iostream>
|
||||||
#include<QtGui/QPainter>
|
#include<QtGui/QPainter>
|
||||||
#include<QtGui/QImage>
|
#include<QtGui/QImage>
|
||||||
#include<QtGui/QMouseEvent>
|
#include<QtGui/QMouseEvent>
|
||||||
@ -45,7 +46,7 @@ template<> struct iters_before_test<double> { enum { ret = 16 }; };
|
|||||||
template<typename Real> void MandelbrotThread::render(int img_width, int img_height)
|
template<typename Real> void MandelbrotThread::render(int img_width, int img_height)
|
||||||
{
|
{
|
||||||
enum { packetSize = Eigen::ei_packet_traits<Real>::size }; // number of reals in a Packet
|
enum { packetSize = Eigen::ei_packet_traits<Real>::size }; // number of reals in a Packet
|
||||||
typedef Eigen::Matrix<Real, packetSize, 1> Packet; // wrap a Packet as a vector
|
typedef Eigen::Array<Real, packetSize, 1> Packet; // wrap a Packet as a vector
|
||||||
|
|
||||||
enum { iters_before_test = iters_before_test<Real>::ret };
|
enum { iters_before_test = iters_before_test<Real>::ret };
|
||||||
max_iter = (max_iter / iters_before_test) * iters_before_test;
|
max_iter = (max_iter / iters_before_test) * iters_before_test;
|
||||||
@ -54,7 +55,7 @@ template<typename Real> void MandelbrotThread::render(int img_width, int img_hei
|
|||||||
const double xradius = widget->xradius;
|
const double xradius = widget->xradius;
|
||||||
const double yradius = xradius * img_height / img_width;
|
const double yradius = xradius * img_height / img_width;
|
||||||
const int threadcount = widget->threadcount;
|
const int threadcount = widget->threadcount;
|
||||||
typedef Eigen::Matrix<Real, 2, 1> Vector2;
|
typedef Eigen::Array<Real, 2, 1> Vector2;
|
||||||
Vector2 start(widget->center.x() - widget->xradius, widget->center.y() - yradius);
|
Vector2 start(widget->center.x() - widget->xradius, widget->center.y() - yradius);
|
||||||
Vector2 step(2*widget->xradius/img_width, 2*yradius/img_height);
|
Vector2 step(2*widget->xradius/img_width, 2*yradius/img_height);
|
||||||
total_iter = 0;
|
total_iter = 0;
|
||||||
@ -87,16 +88,16 @@ template<typename Real> void MandelbrotThread::render(int img_width, int img_hei
|
|||||||
{
|
{
|
||||||
# define ITERATE \
|
# define ITERATE \
|
||||||
pzr_buf = pzr; \
|
pzr_buf = pzr; \
|
||||||
pzr = pzr.cwise().square(); \
|
pzr = pzr.square(); \
|
||||||
pzr -= pzi.cwise().square(); \
|
pzr -= pzi.square(); \
|
||||||
pzr += pcr; \
|
pzr += pcr; \
|
||||||
pzi = (2*pzr_buf).cwise()*pzi; \
|
pzi = (2*pzr_buf)*pzi; \
|
||||||
pzi += pci;
|
pzi += pci;
|
||||||
ITERATE ITERATE ITERATE ITERATE
|
ITERATE ITERATE ITERATE ITERATE
|
||||||
}
|
}
|
||||||
pix_dont_diverge = ((pzr.cwise().square() + pzi.cwise().square())
|
pix_dont_diverge = ((pzr.square() + pzi.square())
|
||||||
.eval() // temporary fix as what follows is not yet vectorized by Eigen
|
.eval() // temporary fix as what follows is not yet vectorized by Eigen
|
||||||
.cwise() <= Packet::Constant(4))
|
<= Packet::Constant(4))
|
||||||
// the 4 here is not a magic value, it's a math fact that if
|
// the 4 here is not a magic value, it's a math fact that if
|
||||||
// the square modulus is >4 then divergence is inevitable.
|
// the square modulus is >4 then divergence is inevitable.
|
||||||
.template cast<int>();
|
.template cast<int>();
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#ifndef MANDELBROT_H
|
#ifndef MANDELBROT_H
|
||||||
#define MANDELBROT_H
|
#define MANDELBROT_H
|
||||||
|
|
||||||
#include <Eigen/Array>
|
#include <Eigen/Core>
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user