My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

85 lines
1.7 KiB

14 years ago
/*
* AttractorKernel.cpp
* AwesomeAttractor
*
* Created by Joshua Moerman on 07-08-10.
* Copyright 2010 Rodo. All rights reserved.
*
*/
#include "AttractorKernel.hpp"
#include <algorithm>
#include <iostream>
#pragma mark -
#pragma mark memory
AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters) :
numberOfParameters(numberOfParameters), dimension(dimension){
14 years ago
try {
allocate();
}
catch (std::exception& e) {
std::cout << "Couldn't construct AttractorKernel: " << e.what() << std::endl;
dealloc();
14 years ago
}
std::fill_n(parameters, numberOfParameters, 0.0);
std::fill_n(vectorNew, dimension, 0.0);
std::fill_n(vectorOld, dimension, 0.0);
}
AttractorKernel::~AttractorKernel(){
dealloc();
14 years ago
}
void AttractorKernel::allocate(){
parameters = new double[numberOfParameters];
vectorNew = new double[dimension];
vectorOld = new double[dimension];
}
void AttractorKernel::dealloc(){
delete[] vectorOld;
vectorOld = NULL;
delete[] vectorNew;
vectorNew = NULL;
14 years ago
delete[] parameters;
parameters = NULL;
14 years ago
}
#pragma mark -
#pragma mark parameters
// NOTE: inlining these functions (with the keyword inline) improves performance by at most 1% (tested)
14 years ago
double & AttractorKernel::operator[](const unsigned int index){
return parameters[index];
}
double const & AttractorKernel::operator[](const unsigned int index) const{
return parameters[index];
}
unsigned int AttractorKernel::getNumberOfParameters() const{
return numberOfParameters;
}
#pragma mark -
#pragma mark vector
double const * AttractorKernel::vector() const{
return vectorNew;
}
double const * AttractorKernel::previousVector() const{
return vectorOld;
}
unsigned int AttractorKernel::getDimension() const{
return dimension;
}