# Path: odelab/system/exponential/burgers.py
# class BurgersComplex(Burgers):
# 	def __getstate__(self):
# 		state = self.__dict__.copy()
# 		del state['laplace']
# 		del state['points']
# 		del state['k']
# 		return state
# 
# 	def initialize(self):
# 		self.k = 2*np.pi*np.array(np.fft.fftfreq(self.size, 1/self.size),dtype='complex')
# 		self.k[len(self.k)/2] = 0
# 		self.laplace = self.viscosity*np.diag(self.k**2)
# 		x = np.linspace(0,1,self.size,endpoint=False)
# 		self.points = x - x.mean() # too lazy to compute x.mean manually here...
# 
# 	def preprocess(self, event0):
# 		return np.hstack([np.fft.fft(event0[:-1]), event0[-1]])
# 
# 	def postprocess(self, event1):
# 		return np.hstack([np.real(np.fft.ifft(event1[:-1])),event1[-1]])
# 
# 	def nonlin(self, t, u):
# 		return -0.5j * self.k * np.fft.fft(np.real(np.fft.ifft(u)) ** 2)


from odelab.scheme import *
from odelab.scheme.exponential import *
from odelab.scheme.rungekutta import *
from odelab.scheme.generallinear import *
from odelab.scheme.classic import *
from odelab.system import *
from odelab.system.exponential.burgers import BurgersComplex
from odelab.solver import *
import numpy.testing as npt
import pytest
import scipy.linalg as slin
import odelab.scheme.exponential as E
	if do_plot:
		pl.clf()
		pl.plot(B.points, sol, lw=2)
	check_convection(scheme, time, time/N, B, u0, sol, do_plot)

def find_N(self):
	for N in [10,20,50,75,100,120,150]:
		self.N = N
		try:
			self.notest_run()
		except AssertionError:
			continue
		else:
			break
	else:
		raise Exception('No N!')
	print(type(self.scheme).__name__, N)


# Auxiliary test to check that the tableaux are square

def check_square(a,b,nb_stages, tail_length):
	npt.assert_equal(len(b), tail_length, 'bv not right # of rows')
	for i,row in enumerate(a):
		npt.assert_equal(len(row), nb_stages+tail_length+1, 'au[%d]'%i)
	for i,row in enumerate(b):
		npt.assert_equal(len(row), nb_stages+tail_length, 'bv[%d]'%i)

exp_objs = [cls() for cls in [getattr(E, name) for name in dir(E)] if hasattr(cls, 'general_linear_z')]


# Path: odelab/system/exponential/burgers.py
# class BurgersComplex(Burgers):
# 	def __getstate__(self):
# 		state = self.__dict__.copy()
# 		del state['laplace']
# 		del state['points']
# 		del state['k']
# 		return state
# 
# 	def initialize(self):
# 		self.k = 2*np.pi*np.array(np.fft.fftfreq(self.size, 1/self.size),dtype='complex')
# 		self.k[len(self.k)/2] = 0
# 		self.laplace = self.viscosity*np.diag(self.k**2)
# 		x = np.linspace(0,1,self.size,endpoint=False)
# 		self.points = x - x.mean() # too lazy to compute x.mean manually here...
# 
# 	def preprocess(self, event0):
# 		return np.hstack([np.fft.fft(event0[:-1]), event0[-1]])
# 
# 	def postprocess(self, event1):
# 		return np.hstack([np.real(np.fft.ifft(event1[:-1])),event1[-1]])
# 
# 	def nonlin(self, t, u):
# 		return -0.5j * self.k * np.fft.fft(np.real(np.fft.ifft(u)) ** 2)


# Path: tests/scheme/test_exponential.py
from odelab.scheme import *
from odelab.scheme.exponential import *
from odelab.scheme.rungekutta import *
from odelab.scheme.generallinear import *
from odelab.scheme.classic import *
from odelab.system import *
from odelab.system.exponential.burgers import BurgersComplex
from odelab.solver import *
import numpy.testing as npt
import pytest
import scipy.linalg as slin
import odelab.scheme.exponential as E

	if do_plot:
		pl.clf()
		pl.plot(B.points, sol, lw=2)
	check_convection(scheme, time, time/N, B, u0, sol, do_plot)

def find_N(self):
	for N in [10,20,50,75,100,120,150]:
		self.N = N
		try:
			self.notest_run()
		except AssertionError:
			continue
		else:
			break
	else:
		raise Exception('No N!')
	print(type(self.scheme).__name__, N)


# Auxiliary test to check that the tableaux are square

def check_square(a,b,nb_stages, tail_length):
	npt.assert_equal(len(b), tail_length, 'bv not right # of rows')
	for i,row in enumerate(a):
		npt.assert_equal(len(row), nb_stages+tail_length+1, 'au[%d]'%i)
	for i,row in enumerate(b):
		npt.assert_equal(len(row), nb_stages+tail_length, 'bv[%d]'%i)

exp_objs = [cls() for cls in [getattr(E, name) for name in dir(E)] if hasattr(cls, 'general_linear_z')]


@pytest.mark.parametrize("obj", exp_objs, ids=repr)