mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
Merge branch 'master' of github.com:SheffieldML/GPy
This commit is contained in:
commit
72544f3b81
28 changed files with 201 additions and 5347 deletions
|
|
@ -83,7 +83,7 @@ class model(parameterised):
|
|||
|
||||
def get(self,name, return_names=False):
|
||||
"""
|
||||
Get a model parameter by name. The name is applied as a regular expression and all parameters that match that regular expression are returned.
|
||||
Get a model parameter by name. The name is applied as a regular expression and all parameters that match that regular expression are returned.
|
||||
"""
|
||||
matches = self.grep_param_names(name)
|
||||
if len(matches):
|
||||
|
|
@ -108,7 +108,7 @@ class model(parameterised):
|
|||
|
||||
def get_gradient(self,name, return_names=False):
|
||||
"""
|
||||
Get model gradient(s) by name. The name is applied as a regular expression and all parameters that match that regular expression are returned.
|
||||
Get model gradient(s) by name. The name is applied as a regular expression and all parameters that match that regular expression are returned.
|
||||
"""
|
||||
matches = self.grep_param_names(name)
|
||||
if len(matches):
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class GP(model):
|
|||
.. Note:: Multiple independent outputs are allowed using columns of Y
|
||||
|
||||
"""
|
||||
|
||||
#FIXME normalize vs normalise
|
||||
def __init__(self, X, likelihood, kernel, normalize_X=False, Xslices=None):
|
||||
|
||||
# parse arguments
|
||||
|
|
@ -216,9 +216,14 @@ class GP(model):
|
|||
gpplot(Xnew,m,m-2*np.sqrt(np.diag(v)[:,None]),m+2*np.sqrt(np.diag(v))[:,None])
|
||||
for i in range(samples):
|
||||
pb.plot(Xnew,Ysim[i,:],Tango.coloursHex['darkBlue'],linewidth=0.25)
|
||||
|
||||
pb.plot(self.X[which_data],self.likelihood.Y[which_data],'kx',mew=1.5)
|
||||
pb.xlim(xmin,xmax)
|
||||
ymin,ymax = min(np.append(self.likelihood.Y,m-2*np.sqrt(np.diag(v)[:,None]))), max(np.append(self.likelihood.Y,m+2*np.sqrt(np.diag(v)[:,None])))
|
||||
ymin, ymax = ymin - 0.1*(ymax - ymin), ymax + 0.1*(ymax - ymin)
|
||||
pb.ylim(ymin,ymax)
|
||||
if hasattr(self,'Z'):
|
||||
pb.plot(self.Z,self.Z*0+pb.ylim()[0],'r|',mew=1.5,markersize=12)
|
||||
|
||||
elif self.X.shape[1] == 2:
|
||||
resolution = resolution or 50
|
||||
Xnew, xmin, xmax, xx, yy = x_frame2D(self.X, plot_limits,resolution)
|
||||
|
|
@ -239,16 +244,22 @@ class GP(model):
|
|||
which_data = slice(None)
|
||||
|
||||
if self.X.shape[1] == 1:
|
||||
Xnew, xmin, xmax = x_frame1D(self.X, plot_limits=plot_limits)
|
||||
|
||||
Xu = self.X * self._Xstd + self._Xmean #NOTE self.X are the normalized values now
|
||||
|
||||
Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits)
|
||||
m, var, lower, upper = self.predict(Xnew, slices=which_functions)
|
||||
gpplot(Xnew,m, lower, upper)
|
||||
pb.plot(self.X[which_data],self.likelihood.data[which_data],'kx',mew=1.5)
|
||||
pb.plot(Xu[which_data],self.likelihood.data[which_data],'kx',mew=1.5)
|
||||
ymin,ymax = min(np.append(self.likelihood.data,lower)), max(np.append(self.likelihood.data,upper))
|
||||
ymin, ymax = ymin - 0.1*(ymax - ymin), ymax + 0.1*(ymax - ymin)
|
||||
pb.xlim(xmin,xmax)
|
||||
pb.ylim(ymin,ymax)
|
||||
if hasattr(self,'Z'):
|
||||
Zu = self.Z*self._Xstd + self._Xmean
|
||||
pb.plot(Zu,Zu*0+pb.ylim()[0],'r|',mew=1.5,markersize=12)
|
||||
|
||||
elif self.X.shape[1]==2:
|
||||
elif self.X.shape[1]==2: #FIXME
|
||||
resolution = resolution or 50
|
||||
Xnew, xx, yy, xmin, xmax = x_frame2D(self.X, plot_limits,resolution)
|
||||
x, y = np.linspace(xmin[0],xmax[0],resolution), np.linspace(xmin[1],xmax[1],resolution)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ from sparse_GP import sparse_GP
|
|||
from sparse_GP_regression import sparse_GP_regression
|
||||
from GPLVM import GPLVM
|
||||
from warped_GP import warpedGP
|
||||
# TODO: from generalized_FITC import generalized_FITC
|
||||
from sparse_GPLVM import sparse_GPLVM
|
||||
#from uncollapsed_sparse_GP import uncollapsed_sparse_GP
|
||||
from BGPLVM import Bayesian_GPLVM
|
||||
|
|
|
|||
|
|
@ -1,242 +0,0 @@
|
|||
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
|
||||
import numpy as np
|
||||
import pylab as pb
|
||||
from scipy import stats, linalg
|
||||
from .. import kern
|
||||
from ..core import model
|
||||
from ..util.linalg import pdinv,mdot
|
||||
from ..util.plot import gpplot
|
||||
#from ..inference.Expectation_Propagation import FITC
|
||||
from ..inference.EP import FITC
|
||||
from ..inference.likelihoods import likelihood,probit
|
||||
|
||||
class generalized_FITC(model):
|
||||
def __init__(self,X,likelihood,kernel=None,inducing=10,epsilon_ep=1e-3,powerep=[1.,1.]):
|
||||
"""
|
||||
Naish-Guzman, A. and Holden, S. (2008) implemantation of EP with FITC.
|
||||
|
||||
:param X: input observations
|
||||
:param likelihood: Output's likelihood (likelihood class)
|
||||
:param kernel: a GPy kernel
|
||||
:param inducing: Either an array specifying the inducing points location or a scalar defining their number.
|
||||
:param epsilon_ep: EP convergence criterion, maximum squared difference allowed between mean updates to stop iterations (float)
|
||||
:param powerep: Power-EP parameters (eta,delta) - 2x1 numpy array (floats)
|
||||
"""
|
||||
assert isinstance(kernel,kern.kern)
|
||||
self.likelihood = likelihood
|
||||
self.Y = self.likelihood.Y
|
||||
self.kernel = kernel
|
||||
self.X = X
|
||||
self.N, self.D = self.X.shape
|
||||
assert self.Y.shape[0] == self.N
|
||||
if type(inducing) == int:
|
||||
self.M = inducing
|
||||
self.Z = (np.random.random_sample(self.D*self.M)*(self.X.max()-self.X.min())+self.X.min()).reshape(self.M,-1)
|
||||
elif type(inducing) == np.ndarray:
|
||||
self.Z = inducing
|
||||
self.M = self.Z.shape[0]
|
||||
self.eta,self.delta = powerep
|
||||
self.epsilon_ep = epsilon_ep
|
||||
self.jitter = 1e-12
|
||||
model.__init__(self)
|
||||
|
||||
def _set_params(self,p):
|
||||
self.kernel._set_params_transformed(p[0:-self.Z.size])
|
||||
self.Z = p[-self.Z.size:].reshape(self.M,self.D)
|
||||
|
||||
def _get_params(self):
|
||||
return np.hstack([self.kernel._get_params_transformed(),self.Z.flatten()])
|
||||
|
||||
def _get_param_names(self):
|
||||
return self.kernel._get_param_names_transformed()+['iip_%i'%i for i in range(self.Z.size)]
|
||||
|
||||
def approximate_likelihood(self):
|
||||
self.Kmm = self.kernel.K(self.Z)
|
||||
self.Knm = self.kernel.K(self.X,self.Z)
|
||||
self.Knn_diag = self.kernel.Kdiag(self.X)
|
||||
self.ep_approx = FITC(self.Kmm,self.likelihood,self.Knm.T,self.Knn_diag,epsilon=self.epsilon_ep,powerep=[self.eta,self.delta])
|
||||
self.ep_approx.fit_EP()
|
||||
|
||||
def posterior_param(self):
|
||||
self.Knn_diag = self.kernel.Kdiag(self.X)
|
||||
self.Kmm = self.kernel.K(self.Z)
|
||||
self.Kmmi, self.Lmm, self.Lmmi, self.Kmm_logdet = pdinv(self.Kmm)
|
||||
self.Knm = self.kernel.K(self.X,self.Z)
|
||||
self.KmmiKmn = np.dot(self.Kmmi,self.Knm.T)
|
||||
self.Qnn = np.dot(self.Knm,self.KmmiKmn)
|
||||
self.Diag0 = self.Knn_diag - np.diag(self.Qnn)
|
||||
self.R0 = np.linalg.cholesky(self.Kmmi).T
|
||||
|
||||
self.Taut = self.ep_approx.tau_tilde/(1.+ self.ep_approx.tau_tilde*self.Diag0)
|
||||
self.KmnTaut = self.Knm.T*self.Taut[None,:]
|
||||
self.KmnTautKnm = np.dot(self.KmnTaut, self.Knm)
|
||||
self.Woodbury_inv, self.Wood_L, self.Wood_Li, self.Woodbury_logdet = pdinv(self.Kmm + self.KmnTautKnm)
|
||||
self.Qnn_diag = self.Knn_diag - np.diag(self.Qnn) + 1./self.ep_approx.tau_tilde
|
||||
self.Qi = -np.dot(self.KmnTaut.T, np.dot(self.Woodbury_inv,self.KmnTaut)) + np.diag(self.Taut)
|
||||
self.hld = 0.5*np.sum(np.log(self.Diag0 + 1./self.ep_approx.tau_tilde)) - 0.5*self.Kmm_logdet + 0.5*self.Woodbury_logdet
|
||||
|
||||
self.Diag = self.Diag0/(1.+ self.Diag0 * self.ep_approx.tau_tilde)
|
||||
self.P = (self.Diag / self.Diag0)[:,None] * self.Knm
|
||||
self.RPT0 = np.dot(self.R0,self.Knm.T)
|
||||
self.L = np.linalg.cholesky(np.eye(self.M) + np.dot(self.RPT0,(1./self.Diag0 - self.Diag/(self.Diag0**2))[:,None]*self.RPT0.T))
|
||||
self.R,info = linalg.flapack.dtrtrs(self.L,self.R0,lower=1)
|
||||
self.RPT = np.dot(self.R,self.P.T)
|
||||
self.Sigma = np.diag(self.Diag) + np.dot(self.RPT.T,self.RPT)
|
||||
self.w = self.Diag * self.ep_approx.v_tilde
|
||||
self.gamma = np.dot(self.R.T, np.dot(self.RPT,self.ep_approx.v_tilde))
|
||||
self.mu = self.w + np.dot(self.P,self.gamma)
|
||||
self.mu_tilde = (self.ep_approx.v_tilde/self.ep_approx.tau_tilde)[:,None]
|
||||
|
||||
def log_likelihood(self):
|
||||
self.posterior_param()
|
||||
self.YYT = np.dot(self.mu_tilde,self.mu_tilde.T)
|
||||
A = -self.hld
|
||||
B = -.5*np.sum(self.Qi*self.YYT)
|
||||
C = sum(np.log(self.ep_approx.Z_hat))
|
||||
D = .5*np.sum(np.log(1./self.ep_approx.tau_tilde + 1./self.ep_approx.tau_))
|
||||
E = .5*np.sum((self.ep_approx.v_/self.ep_approx.tau_ - self.mu_tilde.flatten())**2/(1./self.ep_approx.tau_ + 1./self.ep_approx.tau_tilde))
|
||||
return A + B + C + D + E
|
||||
|
||||
def _log_likelihood_gradients(self):
|
||||
dKmm_dtheta = self.kernel.dK_dtheta(self.Z)
|
||||
dKnn_dtheta = self.kernel.dK_dtheta(self.X)
|
||||
dKmn_dtheta = self.kernel.dK_dtheta(self.Z,self.X)
|
||||
dKmm_dZ = -self.kernel.dK_dX(self.Z)
|
||||
dKnm_dZ = -self.kernel.dK_dX(self.X,self.Z)
|
||||
tmp = [np.dot(dKmn_dtheta_i,self.KmmiKmn) for dKmn_dtheta_i in dKmn_dtheta.T]
|
||||
dQnn_dtheta = [tmp_i + tmp_i.T - np.dot(np.dot(self.KmmiKmn.T,dKmm_dtheta_i),self.KmmiKmn) for tmp_i,dKmm_dtheta_i in zip(tmp,dKmm_dtheta.T)]
|
||||
dDiag0_dtheta = [np.diag(dKnn_dtheta_i) - np.diag(dQnn_dtheta_i) for dKnn_dtheta_i,dQnn_dtheta_i in zip(dKnn_dtheta.T,dQnn_dtheta)]
|
||||
dQ_dtheta = [np.diag(dDiag0_dtheta_i) + dQnn_dtheta_i for dDiag0_dtheta_i,dQnn_dtheta_i in zip(dDiag0_dtheta,dQnn_dtheta)]
|
||||
dW_dtheta = [dKmm_dtheta_i + 2*np.dot(self.KmnTaut,dKmn_dtheta_i) - np.dot(self.KmnTaut*dDiag0_dtheta_i,self.KmnTaut.T) for dKmm_dtheta_i,dDiag0_dtheta_i,dKmn_dtheta_i in zip(dKmm_dtheta.T,dDiag0_dtheta,dKmn_dtheta.T)]
|
||||
|
||||
QiY = np.dot(self.Qi, self.mu_tilde)
|
||||
QiYYQi = np.outer(QiY,QiY)
|
||||
WiKmnTaut = np.dot(self.Woodbury_inv,self.KmnTaut)
|
||||
K_Y = np.dot(self.KmmiKmn,QiY)
|
||||
# gradient - theta
|
||||
Atheta = [-0.5*np.dot(self.Taut,dDiag0_dtheta_i) + 0.5*np.sum(self.Kmmi*dKmm_dtheta_i) - 0.5*np.sum(self.Woodbury_inv*dW_dtheta_i) for dDiag0_dtheta_i,dKmm_dtheta_i,dW_dtheta_i in zip(dDiag0_dtheta,dKmm_dtheta.T,dW_dtheta)]
|
||||
Btheta = np.array([0.5*np.sum(QiYYQi*dQ_dtheta_i) for dQ_dtheta_i in dQ_dtheta])
|
||||
dL_dtheta = Atheta + Btheta
|
||||
# gradient - Z
|
||||
# Az
|
||||
dQnn_dZ_diag_a2 = (np.array([d[:,:,None]*self.KmmiKmn[:,:,None] for d in dKnm_dZ.transpose(2,0,1)]).reshape(self.D,self.M,self.N)).transpose(1,2,0)
|
||||
dQnn_dZ_diag_b2 = (np.array([(self.KmmiKmn*np.sum(d[:,:,None]*self.KmmiKmn,-2))[:,:,None] for d in dKmm_dZ.transpose(2,0,1)]).reshape(self.D,self.M,self.N)).transpose(1,2,0)
|
||||
dQnn_dZ_diag = dQnn_dZ_diag_a2 - dQnn_dZ_diag_b2
|
||||
d_hld_Diag1_dZ = -np.sum(np.dot(self.KmmiKmn*self.Taut,self.KmmiKmn.T)[:,:,None]*dKmm_dZ,-2) + np.sum((self.KmmiKmn*self.Taut)[:,:,None]*dKnm_dZ,-2)
|
||||
d_hld_Kmm_dZ = np.sum(self.Kmmi[:,:,None]*dKmm_dZ,-2)
|
||||
d_hld_W_dZ1 = np.sum(WiKmnTaut[:,:,None]*dKnm_dZ,-2)
|
||||
d_hld_W_dZ3 = np.sum(self.Woodbury_inv[:,:,None]*dKmm_dZ,-2)
|
||||
d_hld_W_dZ2 = np.array([np.sum(np.sum(WiKmnTaut.T*d[:,:,None]*self.KmnTaut.T,-2),-1) for d in dQnn_dZ_diag.transpose(2,0,1)]).T
|
||||
Az = d_hld_Diag1_dZ + d_hld_Kmm_dZ - d_hld_W_dZ1 - d_hld_W_dZ2 - d_hld_W_dZ3
|
||||
# Bz
|
||||
Bz2 = np.sum(np.dot(K_Y,QiY.T)[:,:,None]*dKnm_dZ,-2)
|
||||
Bz3 = - np.sum(np.dot(K_Y,K_Y.T)[:,:,None]*dKmm_dZ,-2)
|
||||
Bz1 = -np.array([np.sum((QiY**2)*d[:,:,None],-2) for d in dQnn_dZ_diag.transpose(2,0,1)]).reshape(self.D,self.M).T
|
||||
Bz = Bz1 + Bz2 + Bz3
|
||||
dL_dZ = (Az + Bz).flatten()
|
||||
return np.hstack([dL_dtheta, dL_dZ])
|
||||
|
||||
def predict(self,X):
|
||||
"""
|
||||
Make a prediction for the vsGP model
|
||||
|
||||
Arguments
|
||||
---------
|
||||
X : Input prediction data - Nx1 numpy array (floats)
|
||||
"""
|
||||
#TODO: check output dimensions
|
||||
K_x = self.kernel.K(self.Z,X)
|
||||
Kxx = self.kernel.K(X)
|
||||
#K_x = self.kernM.cross.K(X)
|
||||
# q(u|f) = N(u| R0i*mu_u*f, R0i*C*R0i.T)
|
||||
|
||||
# Ci = I + (RPT0)Di(RPT0).T
|
||||
# C = I - [RPT0] * (D+[RPT0].T*[RPT0])^-1*[RPT0].T
|
||||
# = I - [RPT0] * (D + self.Qnn)^-1 * [RPT0].T
|
||||
# = I - [RPT0] * (U*U.T)^-1 * [RPT0].T
|
||||
# = I - V.T * V
|
||||
U = np.linalg.cholesky(np.diag(self.Diag0) + self.Qnn)
|
||||
V,info = linalg.flapack.dtrtrs(U,self.RPT0.T,lower=1)
|
||||
C = np.eye(self.M) - np.dot(V.T,V)
|
||||
mu_u = np.dot(C,self.RPT0)*(1./self.Diag0[None,:])
|
||||
#self.C = C
|
||||
#self.RPT0 = np.dot(self.R0,self.Knm.T) P0.T
|
||||
#self.mu_u = mu_u
|
||||
#self.U = U
|
||||
# q(u|y) = N(u| R0i*mu_H,R0i*Sigma_H*R0i.T)
|
||||
mu_H = np.dot(mu_u,self.mu)
|
||||
self.mu_H = mu_H
|
||||
Sigma_H = C + np.dot(mu_u,np.dot(self.Sigma,mu_u.T))
|
||||
# q(f_star|y) = N(f_star|mu_star,sigma2_star)
|
||||
KR0T = np.dot(K_x.T,self.R0.T)
|
||||
mu_star = np.dot(KR0T,mu_H)
|
||||
sigma2_star = Kxx + np.dot(KR0T,np.dot(Sigma_H - np.eye(self.M),KR0T.T))
|
||||
vdiag = np.diag(sigma2_star)
|
||||
# q(y_star|y) = non-gaussian posterior probability of class membership
|
||||
p = self.likelihood.predictive_mean(mu_star,vdiag)
|
||||
return mu_star,vdiag,p
|
||||
|
||||
def plot(self):
|
||||
"""
|
||||
Plot the fitted model: training function values, inducing points used, mean estimate and confidence intervals.
|
||||
"""
|
||||
if self.X.shape[1]==1:
|
||||
pb.figure()
|
||||
xmin,xmax = np.r_[self.X,self.Z].min(),np.r_[self.X,self.Z].max()
|
||||
xmin, xmax = xmin-0.2*(xmax-xmin), xmax+0.2*(xmax-xmin)
|
||||
Xnew = np.linspace(xmin,xmax,100)[:,None]
|
||||
mu_f, var_f, mu_phi = self.predict(Xnew)
|
||||
self.mu_inducing,self.var_diag_inducing,self.phi_inducing = self.predict(self.Z)
|
||||
pb.subplot(211)
|
||||
self.likelihood.plot1Da(X_new=Xnew,Mean_new=mu_f,Var_new=var_f,X_u=self.Z,Mean_u=self.mu_inducing,Var_u=self.var_diag_inducing)
|
||||
pb.subplot(212)
|
||||
self.likelihood.plot1Db(self.X,Xnew,mu_phi,self.Z)
|
||||
elif self.X.shape[1]==2:
|
||||
pb.figure()
|
||||
x1min,x1max = self.X[:,0].min(0),self.X[:,0].max(0)
|
||||
x2min,x2max = self.X[:,1].min(0),self.X[:,1].max(0)
|
||||
x1min, x1max = x1min-0.2*(x1max-x1min), x1max+0.2*(x1max-x1min)
|
||||
x2min, x2max = x2min-0.2*(x2max-x2min), x2max+0.2*(x1max-x1min)
|
||||
axis1 = np.linspace(x1min,x1max,50)
|
||||
axis2 = np.linspace(x2min,x2max,50)
|
||||
XX1, XX2 = [e.flatten() for e in np.meshgrid(axis1,axis2)]
|
||||
Xnew = np.c_[XX1.flatten(),XX2.flatten()]
|
||||
f,v,p = self.predict(Xnew)
|
||||
self.likelihood.plot2D(self.X,Xnew,p,self.Z)
|
||||
else:
|
||||
raise NotImplementedError, "Cannot plot GPs with more than two input dimensions"
|
||||
|
||||
def em(self,max_f_eval=1e4,epsilon=.1,plot_all=False): #TODO check this makes sense
|
||||
"""
|
||||
Fits sparse_EP and optimizes the hyperparametes iteratively until convergence is achieved.
|
||||
"""
|
||||
self.epsilon_em = epsilon
|
||||
log_likelihood_change = self.epsilon_em + 1.
|
||||
self.parameters_path = [self.kernel._get_params()]
|
||||
self.approximate_likelihood()
|
||||
self.site_approximations_path = [[self.ep_approx.tau_tilde,self.ep_approx.v_tilde]]
|
||||
self.inducing_inputs_path = [self.Z]
|
||||
self.log_likelihood_path = [self.log_likelihood()]
|
||||
iteration = 0
|
||||
while log_likelihood_change > self.epsilon_em:
|
||||
print 'EM iteration', iteration
|
||||
self.optimize(max_f_eval = max_f_eval)
|
||||
log_likelihood_new = self.log_likelihood()
|
||||
log_likelihood_change = log_likelihood_new - self.log_likelihood_path[-1]
|
||||
if log_likelihood_change < 0:
|
||||
print 'log_likelihood decrement'
|
||||
self.kernel._set_params_transformed(self.parameters_path[-1])
|
||||
self.kernM = self.kernel.copy()
|
||||
slef.kernM.expand_X(self.iducing_inputs_path[-1])
|
||||
self.__init__(self.kernel,self.likelihood,kernM=self.kernM,powerep=[self.eta,self.delta],epsilon_ep = self.epsilon_ep, epsilon_em = self.epsilon_em)
|
||||
|
||||
else:
|
||||
self.approximate_likelihood()
|
||||
self.log_likelihood_path.append(self.log_likelihood())
|
||||
self.parameters_path.append(self.kernel._get_params())
|
||||
self.site_approximations_path.append([self.ep_approx.tau_tilde,self.ep_approx.v_tilde])
|
||||
self.inducing_inputs_path.append(self.Z)
|
||||
iteration += 1
|
||||
|
|
@ -198,7 +198,7 @@ class sparse_GP(GP):
|
|||
mu = mdot(Kx.T, self.C/self.scale_factor, self.psi1V)
|
||||
if full_cov:
|
||||
Kxx = self.kern.K(Xnew)
|
||||
var = Kxx - mdot(Kx.T, (self.Kmmi - self.C/self.scale_factor**2), Kx) #NOTE thiswon't work for plotting
|
||||
var = Kxx - mdot(Kx.T, (self.Kmmi - self.C/self.scale_factor**2), Kx) #NOTE this won't work for plotting
|
||||
else:
|
||||
Kxx = self.kern.Kdiag(Xnew)
|
||||
var = Kxx - np.sum(Kx*np.dot(self.Kmmi - self.C/self.scale_factor**2, Kx),0)
|
||||
|
|
@ -211,7 +211,6 @@ class sparse_GP(GP):
|
|||
"""
|
||||
GP.plot(self,*args,**kwargs)
|
||||
if self.Q==1:
|
||||
pb.plot(self.Z,self.Z*0+pb.ylim()[0],'k|',mew=1.5,markersize=12)
|
||||
if self.has_uncertain_inputs:
|
||||
pb.errorbar(self.X[:,0], pb.ylim()[0]+np.zeros(self.N), xerr=2*np.sqrt(self.X_uncertainty.flatten()))
|
||||
if self.Q==2:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import pylab as pb
|
|||
from ..util.linalg import mdot, jitchol, chol_inv, pdinv
|
||||
from ..util.plot import gpplot
|
||||
from .. import kern
|
||||
from ..inference.likelihoods import likelihood
|
||||
from ..likelihoods import likelihood
|
||||
from sparse_GP_regression import sparse_GP_regression
|
||||
|
||||
class uncollapsed_sparse_GP(sparse_GP_regression):
|
||||
|
|
@ -136,8 +136,8 @@ class uncollapsed_sparse_GP(sparse_GP_regression):
|
|||
#dL_dm = np.dot(self.Kmmi,self.psi1V) - np.dot(self.Lambda,self.q_u_mean)
|
||||
dL_dm = np.dot(self.Kmmi,self.psi1V) - self.q_u_canonical[0]
|
||||
|
||||
#dL_dSim =
|
||||
#dL_dmhSi =
|
||||
#dL_dSim =
|
||||
#dL_dmhSi =
|
||||
|
||||
return np.hstack((dL_dm.flatten(),dL_dmmT_S.flatten())) # natgrad only, grad TODO
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,14 @@ examples Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`poisson` Module
|
||||
---------------------
|
||||
|
||||
.. automodule:: GPy.examples.poisson
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`regression` Module
|
||||
------------------------
|
||||
|
||||
|
|
@ -57,6 +65,14 @@ examples Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`sparse_ep_fix` Module
|
||||
---------------------------
|
||||
|
||||
.. automodule:: GPy.examples.sparse_ep_fix
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`uncertain_input_GP_regression_demo` Module
|
||||
------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,6 @@
|
|||
inference Package
|
||||
=================
|
||||
|
||||
:mod:`Expectation_Propagation` Module
|
||||
-------------------------------------
|
||||
|
||||
.. automodule:: GPy.inference.Expectation_Propagation
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`likelihoods` Module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: GPy.inference.likelihoods
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`optimization` Module
|
||||
--------------------------
|
||||
|
||||
|
|
|
|||
43
doc/GPy.likelihoods.rst
Normal file
43
doc/GPy.likelihoods.rst
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
likelihoods Package
|
||||
===================
|
||||
|
||||
:mod:`likelihoods` Package
|
||||
--------------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`EP` Module
|
||||
----------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.EP
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`Gaussian` Module
|
||||
----------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.Gaussian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`likelihood` Module
|
||||
------------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.likelihood
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`likelihood_functions` Module
|
||||
----------------------------------
|
||||
|
||||
.. automodule:: GPy.likelihoods.likelihood_functions
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
|
@ -17,18 +17,18 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`GPLVM` Module
|
||||
-------------------
|
||||
:mod:`GP` Module
|
||||
----------------
|
||||
|
||||
.. automodule:: GPy.models.GPLVM
|
||||
.. automodule:: GPy.models.GP
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`GP_EP` Module
|
||||
:mod:`GPLVM` Module
|
||||
-------------------
|
||||
|
||||
.. automodule:: GPy.models.GP_EP
|
||||
.. automodule:: GPy.models.GPLVM
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
@ -41,10 +41,10 @@ models Package
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`generalized_FITC` Module
|
||||
------------------------------
|
||||
:mod:`sparse_GP` Module
|
||||
-----------------------
|
||||
|
||||
.. automodule:: GPy.models.generalized_FITC
|
||||
.. automodule:: GPy.models.sparse_GP
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ Subpackages
|
|||
GPy.examples
|
||||
GPy.inference
|
||||
GPy.kern
|
||||
GPy.likelihoods
|
||||
GPy.models
|
||||
GPy.util
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ help:
|
|||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
|
|
|
|||
189
doc/conf.py
189
doc/conf.py
|
|
@ -11,96 +11,62 @@
|
|||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
import sys
|
||||
import os
|
||||
|
||||
#Mocking uninstalled modules: https://read-the-docs.readthedocs.org/en/latest/faq.html
|
||||
print "python exec:", sys.executable
|
||||
print "sys.path:", sys.path
|
||||
try:
|
||||
import numpy
|
||||
print "numpy: %s, %s" % (numpy.__version__, numpy.__file__)
|
||||
except ImportError:
|
||||
print "no numpy"
|
||||
try:
|
||||
import matplotlib
|
||||
print "matplotlib: %s, %s" % (matplotlib.__version__, matplotlib.__file__)
|
||||
except ImportError:
|
||||
print "no matplotlib"
|
||||
try:
|
||||
import ipython
|
||||
print "ipython: %s, %s" % (ipython.__version__, ipython.__file__)
|
||||
except ImportError:
|
||||
print "no ipython"
|
||||
try:
|
||||
import sphinx
|
||||
print "sphinx: %s, %s" % (sphinx.__version__, sphinx.__file__)
|
||||
except ImportError:
|
||||
print "no sphinx"
|
||||
|
||||
#class Mock(object):
|
||||
#__all__ = []
|
||||
#def __init__(self, *args, **kwargs):
|
||||
#for key, value in kwargs.iteritems():
|
||||
#setattr(self, key, value)
|
||||
#sys.path.insert(0, os.getcwd() + "/..")
|
||||
#parent = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
#sys.path.insert(0, parent)
|
||||
#sys.path.append(parent)
|
||||
|
||||
#def __call__(self, *args, **kwargs):
|
||||
#return Mock()
|
||||
#parent = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'GPy'))
|
||||
#sys.path.insert(0, parent)
|
||||
#sys.path.append(parent)
|
||||
|
||||
#__add__ = __mul__ = __getitem__ = __setitem__ = \
|
||||
#__delitem__ = __sub__ = __floordiv__ = __mod__ = __divmod__ = \
|
||||
#__pow__ = __lshift__ = __rshift__ = __and__ = __xor__ = __or__ = \
|
||||
#__rmul__ = __rsub__ = __rfloordiv__ = __rmod__ = __rdivmod__ = \
|
||||
#__rpow__ = __rlshift__ = __rrshift__ = __rand__ = __rxor__ = __ror__ = \
|
||||
#__imul__ = __isub__ = __ifloordiv__ = __imod__ = __idivmod__ = \
|
||||
#__ipow__ = __ilshift__ = __irshift__ = __iand__ = __ixor__ = __ior__ = \
|
||||
#__neg__ = __pos__ = __abs__ = __invert__ = __call__
|
||||
|
||||
#def __getattr__(self, name):
|
||||
#if name in ('__file__', '__path__'):
|
||||
#return '/dev/null'
|
||||
#if name == 'sqrt':
|
||||
#return math.sqrt
|
||||
#elif name[0] != '_' and name[0] == name[0].upper():
|
||||
#return type(name, (), {})
|
||||
#else:
|
||||
#return Mock(**vars(self))
|
||||
|
||||
#def __lt__(self, *args, **kwargs):
|
||||
#return True
|
||||
|
||||
#__nonzero__ = __le__ = __eq__ = __ne__ = __gt__ = __ge__ = __contains__ = \
|
||||
#__lt__
|
||||
|
||||
|
||||
#def __repr__(self):
|
||||
## Use _mock_repr to fake the __repr__ call
|
||||
#res = getattr(self, "_mock_repr")
|
||||
#return res if isinstance(res, str) else "Mock"
|
||||
|
||||
#def __hash__(self):
|
||||
#return 1
|
||||
|
||||
#__len__ = __int__ = __long__ = __index__ = __hash__
|
||||
|
||||
#def __oct__(self):
|
||||
#return '01'
|
||||
|
||||
#def __hex__(self):
|
||||
#return '0x1'
|
||||
|
||||
#def __float__(self):
|
||||
#return 0.1
|
||||
|
||||
#def __complex__(self):
|
||||
#return 1j
|
||||
|
||||
|
||||
#MOCK_MODULES = [
|
||||
#'pylab', 'scipy', 'matplotlib', 'matplotlib.pyplot', 'pyfits',
|
||||
#'scipy.constants.constants', 'matplotlib.cm',
|
||||
#'matplotlib.image', 'matplotlib.colors', 'sunpy.cm',
|
||||
#'pandas', 'pandas.io', 'pandas.io.parsers',
|
||||
#'suds', 'matplotlib.ticker', 'matplotlib.colorbar',
|
||||
#'matplotlib.dates', 'scipy.optimize', 'scipy.ndimage',
|
||||
#'matplotlib.figure', 'scipy.ndimage.interpolation', 'bs4']
|
||||
#for mod_name in MOCK_MODULES:
|
||||
#sys.modules[mod_name] = Mock()
|
||||
|
||||
|
||||
#sys.modules['numpy'] = Mock(pi=math.pi, G=6.67364e-11,
|
||||
#ndarray=type('ndarray', (), {}),
|
||||
#dtype=lambda _: Mock(_mock_repr='np.dtype(\'float32\')'))
|
||||
#sys.modules['scipy.constants'] = Mock(pi=math.pi, G=6.67364e-11)
|
||||
#APP_DIR = os.path.normpath(os.path.join(os.getcwd(), '../'))
|
||||
#PACKAGE_DIR1 = os.path.normpath(os.path.join(os.getcwd(), '../'))
|
||||
#sys.path.insert(0, APP_DIR)
|
||||
#sys.path.insert(0, PACKAGE_DIR1)
|
||||
#sys.path.insert(0, os.path.abspath('../GPy'))
|
||||
print "sys.path:", sys.path
|
||||
|
||||
#sys.path.insert(0, os.getcwd() + "/..")
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('..'))
|
||||
#sys.path.insert(0, os.path.abspath('../GPy'))
|
||||
|
||||
#print "sys.path.after:", sys.path
|
||||
|
||||
|
||||
print "Adding path"
|
||||
# If your extensions are in another directory, add it here. If the directory
|
||||
# is relative to the documentation root, use os.path.abspath to make it
|
||||
# absolute, like shown here.
|
||||
#sys.path.append(os.path.abspath('./sphinxext'))
|
||||
sys.path.append(os.path.abspath('sphinxext'))
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
|
|
@ -117,23 +83,24 @@ print "Adding path"
|
|||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
print "Importing extensions"
|
||||
|
||||
extensions = [#'ipython_directive',
|
||||
'sphinx.ext.autodoc', 'sphinx.ext.viewcode',
|
||||
'sphinx.ext.pngmath'
|
||||
extensions = ['sphinx.ext.autodoc',
|
||||
#'sphinx.ext.doctest'
|
||||
'sphinx.ext.viewcode',
|
||||
'sphinx.ext.pngmath',
|
||||
'ipython_directive',
|
||||
'ipython_console_highlighting.py'
|
||||
#'matplotlib.sphinxext.mathmpl',
|
||||
#'matplotlib.sphinxext.only_directives',
|
||||
#'matplotlib.sphinxext.plot_directive',
|
||||
#'ipython_directive'
|
||||
]
|
||||
#'sphinx.ext.doctest',
|
||||
#'ipython_console_highlighting',
|
||||
#'inheritance_diagram',
|
||||
#'numpydoc']
|
||||
]
|
||||
|
||||
print "finished importing"
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Mock out imports with C dependencies because ReadTheDocs can't build them.
|
||||
#############################################################################
|
||||
|
||||
class Mock(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
|
@ -152,23 +119,35 @@ class Mock(object):
|
|||
else:
|
||||
return Mock()
|
||||
|
||||
#sys.path.append("../GPy")
|
||||
#import mock
|
||||
|
||||
print "Mocking"
|
||||
MOCK_MODULES = ['pylab', 'matplotlib', 'sympy', 'sympy.utilities', 'sympy.utilities.codegen', 'sympy.core.cache', 'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser']#'matplotlib', 'matplotlib.color', 'matplotlib.pyplot', 'pylab' ]
|
||||
MOCK_MODULES = ['pylab', 'matplotlib', 'sympy', 'sympy.utilities', 'sympy.utilities.codegen', 'sympy.core.cache', 'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser']
|
||||
#'matplotlib', 'matplotlib.color', 'matplotlib.pyplot', 'pylab' ]
|
||||
for mod_name in MOCK_MODULES:
|
||||
sys.modules[mod_name] = Mock()
|
||||
|
||||
# ----------------------- READTHEDOCS ------------------
|
||||
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
|
||||
|
||||
on_rtd = True
|
||||
if on_rtd:
|
||||
sys.path.append("../GPy")
|
||||
os.system("pwd")
|
||||
os.system("sphinx-apidoc -f -o . ../GPy")
|
||||
#os.system("cd ..")
|
||||
#os.system("cd ./docs")
|
||||
print "I am here"
|
||||
sys.path.append(os.path.abspath('../GPy'))
|
||||
|
||||
import subprocess
|
||||
|
||||
proc = subprocess.Popen("pwd", stdout=subprocess.PIPE, shell=True)
|
||||
(out, err) = proc.communicate()
|
||||
print "program output:", out
|
||||
proc = subprocess.Popen("ls ../", stdout=subprocess.PIPE, shell=True)
|
||||
(out, err) = proc.communicate()
|
||||
print "program output:", out
|
||||
proc = subprocess.Popen("sphinx-apidoc -f -o . ../GPy", stdout=subprocess.PIPE, shell=True)
|
||||
(out, err) = proc.communicate()
|
||||
print "program output:", out
|
||||
#os.system("cd ..")
|
||||
#os.system("cd ./docs")
|
||||
|
||||
print "Compiled files"
|
||||
|
||||
|
|
@ -318,21 +297,21 @@ htmlhelp_basename = 'GPydoc'
|
|||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'GPy.tex', u'GPy Documentation',
|
||||
u'Author', 'manual'),
|
||||
('index', 'GPy.tex', u'GPy Documentation',
|
||||
u'Author', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
|
|
@ -375,9 +354,9 @@ man_pages = [
|
|||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'GPy', u'GPy Documentation',
|
||||
u'Author', 'GPy', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
('index', 'GPy', u'GPy Documentation',
|
||||
u'Author', 'GPy', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
|
|
@ -444,3 +423,5 @@ epub_copyright = u'2013, Author'
|
|||
|
||||
#def setup(app):
|
||||
#app.connect("autodoc-skip-member", skip)
|
||||
|
||||
autodoc_member_order = "source"
|
||||
|
|
|
|||
3
doc/doc-requirements.txt
Normal file
3
doc/doc-requirements.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ipython
|
||||
numpy
|
||||
scipy
|
||||
2366
doc/mock.py
2366
doc/mock.py
File diff suppressed because it is too large
Load diff
|
|
@ -1,2 +0,0 @@
|
|||
from __future__ import print_function
|
||||
|
||||
|
|
@ -1,427 +0,0 @@
|
|||
"""Attempt to generate templates for module reference with Sphinx
|
||||
|
||||
XXX - we exclude extension modules
|
||||
|
||||
To include extension modules, first identify them as valid in the
|
||||
``_uri2path`` method, then handle them in the ``_parse_module`` script.
|
||||
|
||||
We get functions and classes by parsing the text of .py files.
|
||||
Alternatively we could import the modules for discovery, and we'd have
|
||||
to do that for extension modules. This would involve changing the
|
||||
``_parse_module`` method to work via import and introspection, and
|
||||
might involve changing ``discover_modules`` (which determines which
|
||||
files are modules, and therefore which module URIs will be passed to
|
||||
``_parse_module``).
|
||||
|
||||
NOTE: this is a modified version of a script originally shipped with the
|
||||
PyMVPA project, which we've adapted for NIPY use. PyMVPA is an MIT-licensed
|
||||
project."""
|
||||
|
||||
# Stdlib imports
|
||||
import os
|
||||
import re
|
||||
|
||||
# Functions and classes
|
||||
class ApiDocWriter(object):
|
||||
''' Class for automatic detection and parsing of API docs
|
||||
to Sphinx-parsable reST format'''
|
||||
|
||||
# only separating first two levels
|
||||
rst_section_levels = ['*', '=', '-', '~', '^']
|
||||
|
||||
def __init__(self,
|
||||
package_name,
|
||||
rst_extension='.rst',
|
||||
package_skip_patterns=None,
|
||||
module_skip_patterns=None,
|
||||
):
|
||||
''' Initialize package for parsing
|
||||
|
||||
Parameters
|
||||
----------
|
||||
package_name : string
|
||||
Name of the top-level package. *package_name* must be the
|
||||
name of an importable package
|
||||
rst_extension : string, optional
|
||||
Extension for reST files, default '.rst'
|
||||
package_skip_patterns : None or sequence of {strings, regexps}
|
||||
Sequence of strings giving URIs of packages to be excluded
|
||||
Operates on the package path, starting at (including) the
|
||||
first dot in the package path, after *package_name* - so,
|
||||
if *package_name* is ``sphinx``, then ``sphinx.util`` will
|
||||
result in ``.util`` being passed for earching by these
|
||||
regexps. If is None, gives default. Default is:
|
||||
['\.tests$']
|
||||
module_skip_patterns : None or sequence
|
||||
Sequence of strings giving URIs of modules to be excluded
|
||||
Operates on the module name including preceding URI path,
|
||||
back to the first dot after *package_name*. For example
|
||||
``sphinx.util.console`` results in the string to search of
|
||||
``.util.console``
|
||||
If is None, gives default. Default is:
|
||||
['\.setup$', '\._']
|
||||
'''
|
||||
if package_skip_patterns is None:
|
||||
package_skip_patterns = ['\\.tests$']
|
||||
if module_skip_patterns is None:
|
||||
module_skip_patterns = ['\\.setup$', '\\._']
|
||||
self.package_name = package_name
|
||||
self.rst_extension = rst_extension
|
||||
self.package_skip_patterns = package_skip_patterns
|
||||
self.module_skip_patterns = module_skip_patterns
|
||||
|
||||
def get_package_name(self):
|
||||
return self._package_name
|
||||
|
||||
def set_package_name(self, package_name):
|
||||
''' Set package_name
|
||||
|
||||
>>> docwriter = ApiDocWriter('sphinx')
|
||||
>>> import sphinx
|
||||
>>> docwriter.root_path == sphinx.__path__[0]
|
||||
True
|
||||
>>> docwriter.package_name = 'docutils'
|
||||
>>> import docutils
|
||||
>>> docwriter.root_path == docutils.__path__[0]
|
||||
True
|
||||
'''
|
||||
# It's also possible to imagine caching the module parsing here
|
||||
self._package_name = package_name
|
||||
self.root_module = __import__(package_name)
|
||||
self.root_path = self.root_module.__path__[0]
|
||||
self.written_modules = None
|
||||
|
||||
package_name = property(get_package_name, set_package_name, None,
|
||||
'get/set package_name')
|
||||
|
||||
def _get_object_name(self, line):
|
||||
''' Get second token in line
|
||||
>>> docwriter = ApiDocWriter('sphinx')
|
||||
>>> docwriter._get_object_name(" def func(): ")
|
||||
'func'
|
||||
>>> docwriter._get_object_name(" class Klass(object): ")
|
||||
'Klass'
|
||||
>>> docwriter._get_object_name(" class Klass: ")
|
||||
'Klass'
|
||||
'''
|
||||
name = line.split()[1].split('(')[0].strip()
|
||||
# in case we have classes which are not derived from object
|
||||
# ie. old style classes
|
||||
return name.rstrip(':')
|
||||
|
||||
def _uri2path(self, uri):
|
||||
''' Convert uri to absolute filepath
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uri : string
|
||||
URI of python module to return path for
|
||||
|
||||
Returns
|
||||
-------
|
||||
path : None or string
|
||||
Returns None if there is no valid path for this URI
|
||||
Otherwise returns absolute file system path for URI
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> docwriter = ApiDocWriter('sphinx')
|
||||
>>> import sphinx
|
||||
>>> modpath = sphinx.__path__[0]
|
||||
>>> res = docwriter._uri2path('sphinx.builder')
|
||||
>>> res == os.path.join(modpath, 'builder.py')
|
||||
True
|
||||
>>> res = docwriter._uri2path('sphinx')
|
||||
>>> res == os.path.join(modpath, '__init__.py')
|
||||
True
|
||||
>>> docwriter._uri2path('sphinx.does_not_exist')
|
||||
|
||||
'''
|
||||
if uri == self.package_name:
|
||||
return os.path.join(self.root_path, '__init__.py')
|
||||
path = uri.replace('.', os.path.sep)
|
||||
path = path.replace(self.package_name + os.path.sep, '')
|
||||
path = os.path.join(self.root_path, path)
|
||||
# XXX maybe check for extensions as well?
|
||||
if os.path.exists(path + '.py'): # file
|
||||
path += '.py'
|
||||
elif os.path.exists(os.path.join(path, '__init__.py')):
|
||||
path = os.path.join(path, '__init__.py')
|
||||
else:
|
||||
return None
|
||||
return path
|
||||
|
||||
def _path2uri(self, dirpath):
|
||||
''' Convert directory path to uri '''
|
||||
relpath = dirpath.replace(self.root_path, self.package_name)
|
||||
if relpath.startswith(os.path.sep):
|
||||
relpath = relpath[1:]
|
||||
return relpath.replace(os.path.sep, '.')
|
||||
|
||||
def _parse_module(self, uri):
|
||||
''' Parse module defined in *uri* '''
|
||||
filename = self._uri2path(uri)
|
||||
if filename is None:
|
||||
# nothing that we could handle here.
|
||||
return ([],[])
|
||||
f = open(filename, 'rt')
|
||||
functions, classes = self._parse_lines(f)
|
||||
f.close()
|
||||
return functions, classes
|
||||
|
||||
def _parse_lines(self, linesource):
|
||||
''' Parse lines of text for functions and classes '''
|
||||
functions = []
|
||||
classes = []
|
||||
for line in linesource:
|
||||
if line.startswith('def ') and line.count('('):
|
||||
# exclude private stuff
|
||||
name = self._get_object_name(line)
|
||||
if not name.startswith('_'):
|
||||
functions.append(name)
|
||||
elif line.startswith('class '):
|
||||
# exclude private stuff
|
||||
name = self._get_object_name(line)
|
||||
if not name.startswith('_'):
|
||||
classes.append(name)
|
||||
else:
|
||||
pass
|
||||
functions.sort()
|
||||
classes.sort()
|
||||
return functions, classes
|
||||
|
||||
def generate_api_doc(self, uri):
|
||||
'''Make autodoc documentation template string for a module
|
||||
|
||||
Parameters
|
||||
----------
|
||||
uri : string
|
||||
python location of module - e.g 'sphinx.builder'
|
||||
|
||||
Returns
|
||||
-------
|
||||
S : string
|
||||
Contents of API doc
|
||||
'''
|
||||
# get the names of all classes and functions
|
||||
functions, classes = self._parse_module(uri)
|
||||
if not len(functions) and not len(classes):
|
||||
print 'WARNING: Empty -',uri # dbg
|
||||
return ''
|
||||
|
||||
# Make a shorter version of the uri that omits the package name for
|
||||
# titles
|
||||
uri_short = re.sub(r'^%s\.' % self.package_name,'',uri)
|
||||
|
||||
ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
|
||||
|
||||
chap_title = uri_short
|
||||
ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
|
||||
+ '\n\n')
|
||||
|
||||
# Set the chapter title to read 'module' for all modules except for the
|
||||
# main packages
|
||||
if '.' in uri:
|
||||
title = 'Module: :mod:`' + uri_short + '`'
|
||||
else:
|
||||
title = ':mod:`' + uri_short + '`'
|
||||
ad += title + '\n' + self.rst_section_levels[2] * len(title)
|
||||
|
||||
if len(classes):
|
||||
ad += '\nInheritance diagram for ``%s``:\n\n' % uri
|
||||
ad += '.. inheritance-diagram:: %s \n' % uri
|
||||
ad += ' :parts: 3\n'
|
||||
|
||||
ad += '\n.. automodule:: ' + uri + '\n'
|
||||
ad += '\n.. currentmodule:: ' + uri + '\n'
|
||||
multi_class = len(classes) > 1
|
||||
multi_fx = len(functions) > 1
|
||||
if multi_class:
|
||||
ad += '\n' + 'Classes' + '\n' + \
|
||||
self.rst_section_levels[2] * 7 + '\n'
|
||||
elif len(classes) and multi_fx:
|
||||
ad += '\n' + 'Class' + '\n' + \
|
||||
self.rst_section_levels[2] * 5 + '\n'
|
||||
for c in classes:
|
||||
ad += '\n:class:`' + c + '`\n' \
|
||||
+ self.rst_section_levels[multi_class + 2 ] * \
|
||||
(len(c)+9) + '\n\n'
|
||||
ad += '\n.. autoclass:: ' + c + '\n'
|
||||
# must NOT exclude from index to keep cross-refs working
|
||||
ad += ' :members:\n' \
|
||||
' :undoc-members:\n' \
|
||||
' :show-inheritance:\n' \
|
||||
' :inherited-members:\n' \
|
||||
'\n' \
|
||||
' .. automethod:: __init__\n'
|
||||
if multi_fx:
|
||||
ad += '\n' + 'Functions' + '\n' + \
|
||||
self.rst_section_levels[2] * 9 + '\n\n'
|
||||
elif len(functions) and multi_class:
|
||||
ad += '\n' + 'Function' + '\n' + \
|
||||
self.rst_section_levels[2] * 8 + '\n\n'
|
||||
for f in functions:
|
||||
# must NOT exclude from index to keep cross-refs working
|
||||
ad += '\n.. autofunction:: ' + uri + '.' + f + '\n\n'
|
||||
return ad
|
||||
|
||||
def _survives_exclude(self, matchstr, match_type):
|
||||
''' Returns True if *matchstr* does not match patterns
|
||||
|
||||
``self.package_name`` removed from front of string if present
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> dw = ApiDocWriter('sphinx')
|
||||
>>> dw._survives_exclude('sphinx.okpkg', 'package')
|
||||
True
|
||||
>>> dw.package_skip_patterns.append('^\\.badpkg$')
|
||||
>>> dw._survives_exclude('sphinx.badpkg', 'package')
|
||||
False
|
||||
>>> dw._survives_exclude('sphinx.badpkg', 'module')
|
||||
True
|
||||
>>> dw._survives_exclude('sphinx.badmod', 'module')
|
||||
True
|
||||
>>> dw.module_skip_patterns.append('^\\.badmod$')
|
||||
>>> dw._survives_exclude('sphinx.badmod', 'module')
|
||||
False
|
||||
'''
|
||||
if match_type == 'module':
|
||||
patterns = self.module_skip_patterns
|
||||
elif match_type == 'package':
|
||||
patterns = self.package_skip_patterns
|
||||
else:
|
||||
raise ValueError('Cannot interpret match type "%s"'
|
||||
% match_type)
|
||||
# Match to URI without package name
|
||||
L = len(self.package_name)
|
||||
if matchstr[:L] == self.package_name:
|
||||
matchstr = matchstr[L:]
|
||||
for pat in patterns:
|
||||
try:
|
||||
pat.search
|
||||
except AttributeError:
|
||||
pat = re.compile(pat)
|
||||
if pat.search(matchstr):
|
||||
return False
|
||||
return True
|
||||
|
||||
def discover_modules(self):
|
||||
''' Return module sequence discovered from ``self.package_name``
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
None
|
||||
|
||||
Returns
|
||||
-------
|
||||
mods : sequence
|
||||
Sequence of module names within ``self.package_name``
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> dw = ApiDocWriter('sphinx')
|
||||
>>> mods = dw.discover_modules()
|
||||
>>> 'sphinx.util' in mods
|
||||
True
|
||||
>>> dw.package_skip_patterns.append('\.util$')
|
||||
>>> 'sphinx.util' in dw.discover_modules()
|
||||
False
|
||||
>>>
|
||||
'''
|
||||
modules = [self.package_name]
|
||||
# raw directory parsing
|
||||
for dirpath, dirnames, filenames in os.walk(self.root_path):
|
||||
# Check directory names for packages
|
||||
root_uri = self._path2uri(os.path.join(self.root_path,
|
||||
dirpath))
|
||||
for dirname in dirnames[:]: # copy list - we modify inplace
|
||||
package_uri = '.'.join((root_uri, dirname))
|
||||
if (self._uri2path(package_uri) and
|
||||
self._survives_exclude(package_uri, 'package')):
|
||||
modules.append(package_uri)
|
||||
else:
|
||||
dirnames.remove(dirname)
|
||||
# Check filenames for modules
|
||||
for filename in filenames:
|
||||
module_name = filename[:-3]
|
||||
module_uri = '.'.join((root_uri, module_name))
|
||||
if (self._uri2path(module_uri) and
|
||||
self._survives_exclude(module_uri, 'module')):
|
||||
modules.append(module_uri)
|
||||
return sorted(modules)
|
||||
|
||||
def write_modules_api(self, modules,outdir):
|
||||
# write the list
|
||||
written_modules = []
|
||||
for m in modules:
|
||||
api_str = self.generate_api_doc(m)
|
||||
if not api_str:
|
||||
continue
|
||||
# write out to file
|
||||
outfile = os.path.join(outdir,
|
||||
m + self.rst_extension)
|
||||
fileobj = open(outfile, 'wt')
|
||||
fileobj.write(api_str)
|
||||
fileobj.close()
|
||||
written_modules.append(m)
|
||||
self.written_modules = written_modules
|
||||
|
||||
def write_api_docs(self, outdir):
|
||||
"""Generate API reST files.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
outdir : string
|
||||
Directory name in which to store files
|
||||
We create automatic filenames for each module
|
||||
|
||||
Returns
|
||||
-------
|
||||
None
|
||||
|
||||
Notes
|
||||
-----
|
||||
Sets self.written_modules to list of written modules
|
||||
"""
|
||||
if not os.path.exists(outdir):
|
||||
os.mkdir(outdir)
|
||||
# compose list of modules
|
||||
modules = self.discover_modules()
|
||||
self.write_modules_api(modules,outdir)
|
||||
|
||||
def write_index(self, outdir, froot='gen', relative_to=None):
|
||||
"""Make a reST API index file from written files
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path : string
|
||||
Filename to write index to
|
||||
outdir : string
|
||||
Directory to which to write generated index file
|
||||
froot : string, optional
|
||||
root (filename without extension) of filename to write to
|
||||
Defaults to 'gen'. We add ``self.rst_extension``.
|
||||
relative_to : string
|
||||
path to which written filenames are relative. This
|
||||
component of the written file path will be removed from
|
||||
outdir, in the generated index. Default is None, meaning,
|
||||
leave path as it is.
|
||||
"""
|
||||
if self.written_modules is None:
|
||||
raise ValueError('No modules written')
|
||||
# Get full filename path
|
||||
path = os.path.join(outdir, froot+self.rst_extension)
|
||||
# Path written into index is relative to rootpath
|
||||
if relative_to is not None:
|
||||
relpath = outdir.replace(relative_to + os.path.sep, '')
|
||||
else:
|
||||
relpath = outdir
|
||||
idx = open(path,'wt')
|
||||
w = idx.write
|
||||
w('.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n')
|
||||
w('.. toctree::\n\n')
|
||||
for f in self.written_modules:
|
||||
w(' %s\n' % os.path.join(relpath,f))
|
||||
idx.close()
|
||||
|
|
@ -1,497 +0,0 @@
|
|||
"""Extract reference documentation from the NumPy source tree.
|
||||
|
||||
"""
|
||||
|
||||
import inspect
|
||||
import textwrap
|
||||
import re
|
||||
import pydoc
|
||||
from StringIO import StringIO
|
||||
from warnings import warn
|
||||
4
|
||||
class Reader(object):
|
||||
"""A line-based string reader.
|
||||
|
||||
"""
|
||||
def __init__(self, data):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
data : str
|
||||
String with lines separated by '\n'.
|
||||
|
||||
"""
|
||||
if isinstance(data,list):
|
||||
self._str = data
|
||||
else:
|
||||
self._str = data.split('\n') # store string as list of lines
|
||||
|
||||
self.reset()
|
||||
|
||||
def __getitem__(self, n):
|
||||
return self._str[n]
|
||||
|
||||
def reset(self):
|
||||
self._l = 0 # current line nr
|
||||
|
||||
def read(self):
|
||||
if not self.eof():
|
||||
out = self[self._l]
|
||||
self._l += 1
|
||||
return out
|
||||
else:
|
||||
return ''
|
||||
|
||||
def seek_next_non_empty_line(self):
|
||||
for l in self[self._l:]:
|
||||
if l.strip():
|
||||
break
|
||||
else:
|
||||
self._l += 1
|
||||
|
||||
def eof(self):
|
||||
return self._l >= len(self._str)
|
||||
|
||||
def read_to_condition(self, condition_func):
|
||||
start = self._l
|
||||
for line in self[start:]:
|
||||
if condition_func(line):
|
||||
return self[start:self._l]
|
||||
self._l += 1
|
||||
if self.eof():
|
||||
return self[start:self._l+1]
|
||||
return []
|
||||
|
||||
def read_to_next_empty_line(self):
|
||||
self.seek_next_non_empty_line()
|
||||
def is_empty(line):
|
||||
return not line.strip()
|
||||
return self.read_to_condition(is_empty)
|
||||
|
||||
def read_to_next_unindented_line(self):
|
||||
def is_unindented(line):
|
||||
return (line.strip() and (len(line.lstrip()) == len(line)))
|
||||
return self.read_to_condition(is_unindented)
|
||||
|
||||
def peek(self,n=0):
|
||||
if self._l + n < len(self._str):
|
||||
return self[self._l + n]
|
||||
else:
|
||||
return ''
|
||||
|
||||
def is_empty(self):
|
||||
return not ''.join(self._str).strip()
|
||||
|
||||
|
||||
class NumpyDocString(object):
|
||||
def __init__(self,docstring):
|
||||
docstring = textwrap.dedent(docstring).split('\n')
|
||||
|
||||
self._doc = Reader(docstring)
|
||||
self._parsed_data = {
|
||||
'Signature': '',
|
||||
'Summary': [''],
|
||||
'Extended Summary': [],
|
||||
'Parameters': [],
|
||||
'Returns': [],
|
||||
'Raises': [],
|
||||
'Warns': [],
|
||||
'Other Parameters': [],
|
||||
'Attributes': [],
|
||||
'Methods': [],
|
||||
'See Also': [],
|
||||
'Notes': [],
|
||||
'Warnings': [],
|
||||
'References': '',
|
||||
'Examples': '',
|
||||
'index': {}
|
||||
}
|
||||
|
||||
self._parse()
|
||||
|
||||
def __getitem__(self,key):
|
||||
return self._parsed_data[key]
|
||||
|
||||
def __setitem__(self,key,val):
|
||||
if not self._parsed_data.has_key(key):
|
||||
warn("Unknown section %s" % key)
|
||||
else:
|
||||
self._parsed_data[key] = val
|
||||
|
||||
def _is_at_section(self):
|
||||
self._doc.seek_next_non_empty_line()
|
||||
|
||||
if self._doc.eof():
|
||||
return False
|
||||
|
||||
l1 = self._doc.peek().strip() # e.g. Parameters
|
||||
|
||||
if l1.startswith('.. index::'):
|
||||
return True
|
||||
|
||||
l2 = self._doc.peek(1).strip() # ---------- or ==========
|
||||
return l2.startswith('-'*len(l1)) or l2.startswith('='*len(l1))
|
||||
|
||||
def _strip(self,doc):
|
||||
i = 0
|
||||
j = 0
|
||||
for i,line in enumerate(doc):
|
||||
if line.strip(): break
|
||||
|
||||
for j,line in enumerate(doc[::-1]):
|
||||
if line.strip(): break
|
||||
|
||||
return doc[i:len(doc)-j]
|
||||
|
||||
def _read_to_next_section(self):
|
||||
section = self._doc.read_to_next_empty_line()
|
||||
|
||||
while not self._is_at_section() and not self._doc.eof():
|
||||
if not self._doc.peek(-1).strip(): # previous line was empty
|
||||
section += ['']
|
||||
|
||||
section += self._doc.read_to_next_empty_line()
|
||||
|
||||
return section
|
||||
|
||||
def _read_sections(self):
|
||||
while not self._doc.eof():
|
||||
data = self._read_to_next_section()
|
||||
name = data[0].strip()
|
||||
|
||||
if name.startswith('..'): # index section
|
||||
yield name, data[1:]
|
||||
elif len(data) < 2:
|
||||
yield StopIteration
|
||||
else:
|
||||
yield name, self._strip(data[2:])
|
||||
|
||||
def _parse_param_list(self,content):
|
||||
r = Reader(content)
|
||||
params = []
|
||||
while not r.eof():
|
||||
header = r.read().strip()
|
||||
if ' : ' in header:
|
||||
arg_name, arg_type = header.split(' : ')[:2]
|
||||
else:
|
||||
arg_name, arg_type = header, ''
|
||||
|
||||
desc = r.read_to_next_unindented_line()
|
||||
desc = dedent_lines(desc)
|
||||
|
||||
params.append((arg_name,arg_type,desc))
|
||||
|
||||
return params
|
||||
|
||||
|
||||
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`|"
|
||||
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
|
||||
def _parse_see_also(self, content):
|
||||
"""
|
||||
func_name : Descriptive text
|
||||
continued text
|
||||
another_func_name : Descriptive text
|
||||
func_name1, func_name2, :meth:`func_name`, func_name3
|
||||
|
||||
"""
|
||||
items = []
|
||||
|
||||
def parse_item_name(text):
|
||||
"""Match ':role:`name`' or 'name'"""
|
||||
m = self._name_rgx.match(text)
|
||||
if m:
|
||||
g = m.groups()
|
||||
if g[1] is None:
|
||||
return g[3], None
|
||||
else:
|
||||
return g[2], g[1]
|
||||
raise ValueError("%s is not a item name" % text)
|
||||
|
||||
def push_item(name, rest):
|
||||
if not name:
|
||||
return
|
||||
name, role = parse_item_name(name)
|
||||
items.append((name, list(rest), role))
|
||||
del rest[:]
|
||||
|
||||
current_func = None
|
||||
rest = []
|
||||
|
||||
for line in content:
|
||||
if not line.strip(): continue
|
||||
|
||||
m = self._name_rgx.match(line)
|
||||
if m and line[m.end():].strip().startswith(':'):
|
||||
push_item(current_func, rest)
|
||||
current_func, line = line[:m.end()], line[m.end():]
|
||||
rest = [line.split(':', 1)[1].strip()]
|
||||
if not rest[0]:
|
||||
rest = []
|
||||
elif not line.startswith(' '):
|
||||
push_item(current_func, rest)
|
||||
current_func = None
|
||||
if ',' in line:
|
||||
for func in line.split(','):
|
||||
push_item(func, [])
|
||||
elif line.strip():
|
||||
current_func = line
|
||||
elif current_func is not None:
|
||||
rest.append(line.strip())
|
||||
push_item(current_func, rest)
|
||||
return items
|
||||
|
||||
def _parse_index(self, section, content):
|
||||
"""
|
||||
.. index: default
|
||||
:refguide: something, else, and more
|
||||
|
||||
"""
|
||||
def strip_each_in(lst):
|
||||
return [s.strip() for s in lst]
|
||||
|
||||
out = {}
|
||||
section = section.split('::')
|
||||
if len(section) > 1:
|
||||
out['default'] = strip_each_in(section[1].split(','))[0]
|
||||
for line in content:
|
||||
line = line.split(':')
|
||||
if len(line) > 2:
|
||||
out[line[1]] = strip_each_in(line[2].split(','))
|
||||
return out
|
||||
|
||||
def _parse_summary(self):
|
||||
"""Grab signature (if given) and summary"""
|
||||
if self._is_at_section():
|
||||
return
|
||||
|
||||
summary = self._doc.read_to_next_empty_line()
|
||||
summary_str = " ".join([s.strip() for s in summary]).strip()
|
||||
if re.compile('^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str):
|
||||
self['Signature'] = summary_str
|
||||
if not self._is_at_section():
|
||||
self['Summary'] = self._doc.read_to_next_empty_line()
|
||||
else:
|
||||
self['Summary'] = summary
|
||||
|
||||
if not self._is_at_section():
|
||||
self['Extended Summary'] = self._read_to_next_section()
|
||||
|
||||
def _parse(self):
|
||||
self._doc.reset()
|
||||
self._parse_summary()
|
||||
|
||||
for (section,content) in self._read_sections():
|
||||
if not section.startswith('..'):
|
||||
section = ' '.join([s.capitalize() for s in section.split(' ')])
|
||||
if section in ('Parameters', 'Attributes', 'Methods',
|
||||
'Returns', 'Raises', 'Warns'):
|
||||
self[section] = self._parse_param_list(content)
|
||||
elif section.startswith('.. index::'):
|
||||
self['index'] = self._parse_index(section, content)
|
||||
elif section == 'See Also':
|
||||
self['See Also'] = self._parse_see_also(content)
|
||||
else:
|
||||
self[section] = content
|
||||
|
||||
# string conversion routines
|
||||
|
||||
def _str_header(self, name, symbol='-'):
|
||||
return [name, len(name)*symbol]
|
||||
|
||||
def _str_indent(self, doc, indent=4):
|
||||
out = []
|
||||
for line in doc:
|
||||
out += [' '*indent + line]
|
||||
return out
|
||||
|
||||
def _str_signature(self):
|
||||
if self['Signature']:
|
||||
return [self['Signature'].replace('*','\*')] + ['']
|
||||
else:
|
||||
return ['']
|
||||
|
||||
def _str_summary(self):
|
||||
if self['Summary']:
|
||||
return self['Summary'] + ['']
|
||||
else:
|
||||
return []
|
||||
|
||||
def _str_extended_summary(self):
|
||||
if self['Extended Summary']:
|
||||
return self['Extended Summary'] + ['']
|
||||
else:
|
||||
return []
|
||||
|
||||
def _str_param_list(self, name):
|
||||
out = []
|
||||
if self[name]:
|
||||
out += self._str_header(name)
|
||||
for param,param_type,desc in self[name]:
|
||||
out += ['%s : %s' % (param, param_type)]
|
||||
out += self._str_indent(desc)
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def _str_section(self, name):
|
||||
out = []
|
||||
if self[name]:
|
||||
out += self._str_header(name)
|
||||
out += self[name]
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def _str_see_also(self, func_role):
|
||||
if not self['See Also']: return []
|
||||
out = []
|
||||
out += self._str_header("See Also")
|
||||
last_had_desc = True
|
||||
for func, desc, role in self['See Also']:
|
||||
if role:
|
||||
link = ':%s:`%s`' % (role, func)
|
||||
elif func_role:
|
||||
link = ':%s:`%s`' % (func_role, func)
|
||||
else:
|
||||
link = "`%s`_" % func
|
||||
if desc or last_had_desc:
|
||||
out += ['']
|
||||
out += [link]
|
||||
else:
|
||||
out[-1] += ", %s" % link
|
||||
if desc:
|
||||
out += self._str_indent([' '.join(desc)])
|
||||
last_had_desc = True
|
||||
else:
|
||||
last_had_desc = False
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def _str_index(self):
|
||||
idx = self['index']
|
||||
out = []
|
||||
out += ['.. index:: %s' % idx.get('default','')]
|
||||
for section, references in idx.iteritems():
|
||||
if section == 'default':
|
||||
continue
|
||||
out += [' :%s: %s' % (section, ', '.join(references))]
|
||||
return out
|
||||
|
||||
def __str__(self, func_role=''):
|
||||
out = []
|
||||
out += self._str_signature()
|
||||
out += self._str_summary()
|
||||
out += self._str_extended_summary()
|
||||
for param_list in ('Parameters','Returns','Raises'):
|
||||
out += self._str_param_list(param_list)
|
||||
out += self._str_section('Warnings')
|
||||
out += self._str_see_also(func_role)
|
||||
for s in ('Notes','References','Examples'):
|
||||
out += self._str_section(s)
|
||||
out += self._str_index()
|
||||
return '\n'.join(out)
|
||||
|
||||
|
||||
def indent(str,indent=4):
|
||||
indent_str = ' '*indent
|
||||
if str is None:
|
||||
return indent_str
|
||||
lines = str.split('\n')
|
||||
return '\n'.join(indent_str + l for l in lines)
|
||||
|
||||
def dedent_lines(lines):
|
||||
"""Deindent a list of lines maximally"""
|
||||
return textwrap.dedent("\n".join(lines)).split("\n")
|
||||
|
||||
def header(text, style='-'):
|
||||
return text + '\n' + style*len(text) + '\n'
|
||||
|
||||
|
||||
class FunctionDoc(NumpyDocString):
|
||||
def __init__(self, func, role='func', doc=None):
|
||||
self._f = func
|
||||
self._role = role # e.g. "func" or "meth"
|
||||
if doc is None:
|
||||
doc = inspect.getdoc(func) or ''
|
||||
try:
|
||||
NumpyDocString.__init__(self, doc)
|
||||
except ValueError, e:
|
||||
print '*'*78
|
||||
print "ERROR: '%s' while parsing `%s`" % (e, self._f)
|
||||
print '*'*78
|
||||
#print "Docstring follows:"
|
||||
#print doclines
|
||||
#print '='*78
|
||||
|
||||
if not self['Signature']:
|
||||
func, func_name = self.get_func()
|
||||
try:
|
||||
# try to read signature
|
||||
argspec = inspect.getargspec(func)
|
||||
argspec = inspect.formatargspec(*argspec)
|
||||
argspec = argspec.replace('*','\*')
|
||||
signature = '%s%s' % (func_name, argspec)
|
||||
except TypeError, e:
|
||||
signature = '%s()' % func_name
|
||||
self['Signature'] = signature
|
||||
|
||||
def get_func(self):
|
||||
func_name = getattr(self._f, '__name__', self.__class__.__name__)
|
||||
if inspect.isclass(self._f):
|
||||
func = getattr(self._f, '__call__', self._f.__init__)
|
||||
else:
|
||||
func = self._f
|
||||
return func, func_name
|
||||
|
||||
def __str__(self):
|
||||
out = ''
|
||||
|
||||
func, func_name = self.get_func()
|
||||
signature = self['Signature'].replace('*', '\*')
|
||||
|
||||
roles = {'func': 'function',
|
||||
'meth': 'method'}
|
||||
|
||||
if self._role:
|
||||
if not roles.has_key(self._role):
|
||||
print "Warning: invalid role %s" % self._role
|
||||
out += '.. %s:: %s\n \n\n' % (roles.get(self._role,''),
|
||||
func_name)
|
||||
|
||||
out += super(FunctionDoc, self).__str__(func_role=self._role)
|
||||
return out
|
||||
|
||||
|
||||
class ClassDoc(NumpyDocString):
|
||||
def __init__(self,cls,modulename='',func_doc=FunctionDoc,doc=None):
|
||||
if not inspect.isclass(cls):
|
||||
raise ValueError("Initialise using a class. Got %r" % cls)
|
||||
self._cls = cls
|
||||
|
||||
if modulename and not modulename.endswith('.'):
|
||||
modulename += '.'
|
||||
self._mod = modulename
|
||||
self._name = cls.__name__
|
||||
self._func_doc = func_doc
|
||||
|
||||
if doc is None:
|
||||
doc = pydoc.getdoc(cls)
|
||||
|
||||
NumpyDocString.__init__(self, doc)
|
||||
|
||||
@property
|
||||
def methods(self):
|
||||
return [name for name,func in inspect.getmembers(self._cls)
|
||||
if not name.startswith('_') and callable(func)]
|
||||
|
||||
def __str__(self):
|
||||
out = ''
|
||||
out += super(ClassDoc, self).__str__()
|
||||
out += "\n\n"
|
||||
|
||||
#for m in self.methods:
|
||||
# print "Parsing `%s`" % m
|
||||
# out += str(self._func_doc(getattr(self._cls,m), 'meth')) + '\n\n'
|
||||
# out += '.. index::\n single: %s; %s\n\n' % (self._name, m)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
import re, inspect, textwrap, pydoc
|
||||
from docscrape import NumpyDocString, FunctionDoc, ClassDoc
|
||||
|
||||
class SphinxDocString(NumpyDocString):
|
||||
# string conversion routines
|
||||
def _str_header(self, name, symbol='`'):
|
||||
return ['.. rubric:: ' + name, '']
|
||||
|
||||
def _str_field_list(self, name):
|
||||
return [':' + name + ':']
|
||||
|
||||
def _str_indent(self, doc, indent=4):
|
||||
out = []
|
||||
for line in doc:
|
||||
out += [' '*indent + line]
|
||||
return out
|
||||
|
||||
def _str_signature(self):
|
||||
return ['']
|
||||
if self['Signature']:
|
||||
return ['``%s``' % self['Signature']] + ['']
|
||||
else:
|
||||
return ['']
|
||||
|
||||
def _str_summary(self):
|
||||
return self['Summary'] + ['']
|
||||
|
||||
def _str_extended_summary(self):
|
||||
return self['Extended Summary'] + ['']
|
||||
|
||||
def _str_param_list(self, name):
|
||||
out = []
|
||||
if self[name]:
|
||||
out += self._str_field_list(name)
|
||||
out += ['']
|
||||
for param,param_type,desc in self[name]:
|
||||
out += self._str_indent(['**%s** : %s' % (param.strip(),
|
||||
param_type)])
|
||||
out += ['']
|
||||
out += self._str_indent(desc,8)
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def _str_section(self, name):
|
||||
out = []
|
||||
if self[name]:
|
||||
out += self._str_header(name)
|
||||
out += ['']
|
||||
content = textwrap.dedent("\n".join(self[name])).split("\n")
|
||||
out += content
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def _str_see_also(self, func_role):
|
||||
out = []
|
||||
if self['See Also']:
|
||||
see_also = super(SphinxDocString, self)._str_see_also(func_role)
|
||||
out = ['.. seealso::', '']
|
||||
out += self._str_indent(see_also[2:])
|
||||
return out
|
||||
|
||||
def _str_warnings(self):
|
||||
out = []
|
||||
if self['Warnings']:
|
||||
out = ['.. warning::', '']
|
||||
out += self._str_indent(self['Warnings'])
|
||||
return out
|
||||
|
||||
def _str_index(self):
|
||||
idx = self['index']
|
||||
out = []
|
||||
if len(idx) == 0:
|
||||
return out
|
||||
|
||||
out += ['.. index:: %s' % idx.get('default','')]
|
||||
for section, references in idx.iteritems():
|
||||
if section == 'default':
|
||||
continue
|
||||
elif section == 'refguide':
|
||||
out += [' single: %s' % (', '.join(references))]
|
||||
else:
|
||||
out += [' %s: %s' % (section, ','.join(references))]
|
||||
return out
|
||||
|
||||
def _str_references(self):
|
||||
out = []
|
||||
if self['References']:
|
||||
out += self._str_header('References')
|
||||
if isinstance(self['References'], str):
|
||||
self['References'] = [self['References']]
|
||||
out.extend(self['References'])
|
||||
out += ['']
|
||||
return out
|
||||
|
||||
def __str__(self, indent=0, func_role="obj"):
|
||||
out = []
|
||||
out += self._str_signature()
|
||||
out += self._str_index() + ['']
|
||||
out += self._str_summary()
|
||||
out += self._str_extended_summary()
|
||||
for param_list in ('Parameters', 'Attributes', 'Methods',
|
||||
'Returns','Raises'):
|
||||
out += self._str_param_list(param_list)
|
||||
out += self._str_warnings()
|
||||
out += self._str_see_also(func_role)
|
||||
out += self._str_section('Notes')
|
||||
out += self._str_references()
|
||||
out += self._str_section('Examples')
|
||||
out = self._str_indent(out,indent)
|
||||
return '\n'.join(out)
|
||||
|
||||
class SphinxFunctionDoc(SphinxDocString, FunctionDoc):
|
||||
pass
|
||||
|
||||
class SphinxClassDoc(SphinxDocString, ClassDoc):
|
||||
pass
|
||||
|
||||
def get_doc_object(obj, what=None, doc=None):
|
||||
if what is None:
|
||||
if inspect.isclass(obj):
|
||||
what = 'class'
|
||||
elif inspect.ismodule(obj):
|
||||
what = 'module'
|
||||
elif callable(obj):
|
||||
what = 'function'
|
||||
else:
|
||||
what = 'object'
|
||||
if what == 'class':
|
||||
return SphinxClassDoc(obj, '', func_doc=SphinxFunctionDoc, doc=doc)
|
||||
elif what in ('function', 'method'):
|
||||
return SphinxFunctionDoc(obj, '', doc=doc)
|
||||
else:
|
||||
if doc is None:
|
||||
doc = pydoc.getdoc(obj)
|
||||
return SphinxDocString(doc)
|
||||
|
||||
|
|
@ -1,407 +0,0 @@
|
|||
"""
|
||||
Defines a docutils directive for inserting inheritance diagrams.
|
||||
|
||||
Provide the directive with one or more classes or modules (separated
|
||||
by whitespace). For modules, all of the classes in that module will
|
||||
be used.
|
||||
|
||||
Example::
|
||||
|
||||
Given the following classes:
|
||||
|
||||
class A: pass
|
||||
class B(A): pass
|
||||
class C(A): pass
|
||||
class D(B, C): pass
|
||||
class E(B): pass
|
||||
|
||||
.. inheritance-diagram: D E
|
||||
|
||||
Produces a graph like the following:
|
||||
|
||||
A
|
||||
/ \
|
||||
B C
|
||||
/ \ /
|
||||
E D
|
||||
|
||||
The graph is inserted as a PNG+image map into HTML and a PDF in
|
||||
LaTeX.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
try:
|
||||
from hashlib import md5
|
||||
except ImportError:
|
||||
from md5 import md5
|
||||
|
||||
from docutils.nodes import Body, Element
|
||||
from docutils.parsers.rst import directives
|
||||
from sphinx.roles import xfileref_role
|
||||
|
||||
def my_import(name):
|
||||
"""Module importer - taken from the python documentation.
|
||||
|
||||
This function allows importing names with dots in them."""
|
||||
|
||||
mod = __import__(name)
|
||||
components = name.split('.')
|
||||
for comp in components[1:]:
|
||||
mod = getattr(mod, comp)
|
||||
return mod
|
||||
|
||||
class DotException(Exception):
|
||||
pass
|
||||
|
||||
class InheritanceGraph(object):
|
||||
"""
|
||||
Given a list of classes, determines the set of classes that
|
||||
they inherit from all the way to the root "object", and then
|
||||
is able to generate a graphviz dot graph from them.
|
||||
"""
|
||||
def __init__(self, class_names, show_builtins=False):
|
||||
"""
|
||||
*class_names* is a list of child classes to show bases from.
|
||||
|
||||
If *show_builtins* is True, then Python builtins will be shown
|
||||
in the graph.
|
||||
"""
|
||||
self.class_names = class_names
|
||||
self.classes = self._import_classes(class_names)
|
||||
self.all_classes = self._all_classes(self.classes)
|
||||
if len(self.all_classes) == 0:
|
||||
raise ValueError("No classes found for inheritance diagram")
|
||||
self.show_builtins = show_builtins
|
||||
|
||||
py_sig_re = re.compile(r'''^([\w.]*\.)? # class names
|
||||
(\w+) \s* $ # optionally arguments
|
||||
''', re.VERBOSE)
|
||||
|
||||
def _import_class_or_module(self, name):
|
||||
"""
|
||||
Import a class using its fully-qualified *name*.
|
||||
"""
|
||||
try:
|
||||
path, base = self.py_sig_re.match(name).groups()
|
||||
except:
|
||||
raise ValueError(
|
||||
"Invalid class or module '%s' specified for inheritance diagram" % name)
|
||||
fullname = (path or '') + base
|
||||
path = (path and path.rstrip('.'))
|
||||
if not path:
|
||||
path = base
|
||||
try:
|
||||
module = __import__(path, None, None, [])
|
||||
# We must do an import of the fully qualified name. Otherwise if a
|
||||
# subpackage 'a.b' is requested where 'import a' does NOT provide
|
||||
# 'a.b' automatically, then 'a.b' will not be found below. This
|
||||
# second call will force the equivalent of 'import a.b' to happen
|
||||
# after the top-level import above.
|
||||
my_import(fullname)
|
||||
|
||||
except ImportError:
|
||||
raise ValueError(
|
||||
"Could not import class or module '%s' specified for inheritance diagram" % name)
|
||||
|
||||
try:
|
||||
todoc = module
|
||||
for comp in fullname.split('.')[1:]:
|
||||
todoc = getattr(todoc, comp)
|
||||
except AttributeError:
|
||||
raise ValueError(
|
||||
"Could not find class or module '%s' specified for inheritance diagram" % name)
|
||||
|
||||
# If a class, just return it
|
||||
if inspect.isclass(todoc):
|
||||
return [todoc]
|
||||
elif inspect.ismodule(todoc):
|
||||
classes = []
|
||||
for cls in todoc.__dict__.values():
|
||||
if inspect.isclass(cls) and cls.__module__ == todoc.__name__:
|
||||
classes.append(cls)
|
||||
return classes
|
||||
raise ValueError(
|
||||
"'%s' does not resolve to a class or module" % name)
|
||||
|
||||
def _import_classes(self, class_names):
|
||||
"""
|
||||
Import a list of classes.
|
||||
"""
|
||||
classes = []
|
||||
for name in class_names:
|
||||
classes.extend(self._import_class_or_module(name))
|
||||
return classes
|
||||
|
||||
def _all_classes(self, classes):
|
||||
"""
|
||||
Return a list of all classes that are ancestors of *classes*.
|
||||
"""
|
||||
all_classes = {}
|
||||
|
||||
def recurse(cls):
|
||||
all_classes[cls] = None
|
||||
for c in cls.__bases__:
|
||||
if c not in all_classes:
|
||||
recurse(c)
|
||||
|
||||
for cls in classes:
|
||||
recurse(cls)
|
||||
|
||||
return all_classes.keys()
|
||||
|
||||
def class_name(self, cls, parts=0):
|
||||
"""
|
||||
Given a class object, return a fully-qualified name. This
|
||||
works for things I've tested in matplotlib so far, but may not
|
||||
be completely general.
|
||||
"""
|
||||
module = cls.__module__
|
||||
if module == '__builtin__':
|
||||
fullname = cls.__name__
|
||||
else:
|
||||
fullname = "%s.%s" % (module, cls.__name__)
|
||||
if parts == 0:
|
||||
return fullname
|
||||
name_parts = fullname.split('.')
|
||||
return '.'.join(name_parts[-parts:])
|
||||
|
||||
def get_all_class_names(self):
|
||||
"""
|
||||
Get all of the class names involved in the graph.
|
||||
"""
|
||||
return [self.class_name(x) for x in self.all_classes]
|
||||
|
||||
# These are the default options for graphviz
|
||||
default_graph_options = {
|
||||
"rankdir": "LR",
|
||||
"size": '"8.0, 12.0"'
|
||||
}
|
||||
default_node_options = {
|
||||
"shape": "box",
|
||||
"fontsize": 10,
|
||||
"height": 0.25,
|
||||
"fontname": "Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",
|
||||
"style": '"setlinewidth(0.5)"'
|
||||
}
|
||||
default_edge_options = {
|
||||
"arrowsize": 0.5,
|
||||
"style": '"setlinewidth(0.5)"'
|
||||
}
|
||||
|
||||
def _format_node_options(self, options):
|
||||
return ','.join(["%s=%s" % x for x in options.items()])
|
||||
def _format_graph_options(self, options):
|
||||
return ''.join(["%s=%s;\n" % x for x in options.items()])
|
||||
|
||||
def generate_dot(self, fd, name, parts=0, urls={},
|
||||
graph_options={}, node_options={},
|
||||
edge_options={}):
|
||||
"""
|
||||
Generate a graphviz dot graph from the classes that
|
||||
were passed in to __init__.
|
||||
|
||||
*fd* is a Python file-like object to write to.
|
||||
|
||||
*name* is the name of the graph
|
||||
|
||||
*urls* is a dictionary mapping class names to http urls
|
||||
|
||||
*graph_options*, *node_options*, *edge_options* are
|
||||
dictionaries containing key/value pairs to pass on as graphviz
|
||||
properties.
|
||||
"""
|
||||
g_options = self.default_graph_options.copy()
|
||||
g_options.update(graph_options)
|
||||
n_options = self.default_node_options.copy()
|
||||
n_options.update(node_options)
|
||||
e_options = self.default_edge_options.copy()
|
||||
e_options.update(edge_options)
|
||||
|
||||
fd.write('digraph %s {\n' % name)
|
||||
fd.write(self._format_graph_options(g_options))
|
||||
|
||||
for cls in self.all_classes:
|
||||
if not self.show_builtins and cls in __builtins__.values():
|
||||
continue
|
||||
|
||||
name = self.class_name(cls, parts)
|
||||
|
||||
# Write the node
|
||||
this_node_options = n_options.copy()
|
||||
url = urls.get(self.class_name(cls))
|
||||
if url is not None:
|
||||
this_node_options['URL'] = '"%s"' % url
|
||||
fd.write(' "%s" [%s];\n' %
|
||||
(name, self._format_node_options(this_node_options)))
|
||||
|
||||
# Write the edges
|
||||
for base in cls.__bases__:
|
||||
if not self.show_builtins and base in __builtins__.values():
|
||||
continue
|
||||
|
||||
base_name = self.class_name(base, parts)
|
||||
fd.write(' "%s" -> "%s" [%s];\n' %
|
||||
(base_name, name,
|
||||
self._format_node_options(e_options)))
|
||||
fd.write('}\n')
|
||||
|
||||
def run_dot(self, args, name, parts=0, urls={},
|
||||
graph_options={}, node_options={}, edge_options={}):
|
||||
"""
|
||||
Run graphviz 'dot' over this graph, returning whatever 'dot'
|
||||
writes to stdout.
|
||||
|
||||
*args* will be passed along as commandline arguments.
|
||||
|
||||
*name* is the name of the graph
|
||||
|
||||
*urls* is a dictionary mapping class names to http urls
|
||||
|
||||
Raises DotException for any of the many os and
|
||||
installation-related errors that may occur.
|
||||
"""
|
||||
try:
|
||||
dot = subprocess.Popen(['dot'] + list(args),
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
raise DotException("Could not execute 'dot'. Are you sure you have 'graphviz' installed?")
|
||||
except ValueError:
|
||||
raise DotException("'dot' called with invalid arguments")
|
||||
except:
|
||||
raise DotException("Unexpected error calling 'dot'")
|
||||
|
||||
self.generate_dot(dot.stdin, name, parts, urls, graph_options,
|
||||
node_options, edge_options)
|
||||
dot.stdin.close()
|
||||
result = dot.stdout.read()
|
||||
returncode = dot.wait()
|
||||
if returncode != 0:
|
||||
raise DotException("'dot' returned the errorcode %d" % returncode)
|
||||
return result
|
||||
|
||||
class inheritance_diagram(Body, Element):
|
||||
"""
|
||||
A docutils node to use as a placeholder for the inheritance
|
||||
diagram.
|
||||
"""
|
||||
pass
|
||||
|
||||
def inheritance_diagram_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state,
|
||||
state_machine):
|
||||
"""
|
||||
Run when the inheritance_diagram directive is first encountered.
|
||||
"""
|
||||
node = inheritance_diagram()
|
||||
|
||||
class_names = arguments
|
||||
|
||||
# Create a graph starting with the list of classes
|
||||
graph = InheritanceGraph(class_names)
|
||||
|
||||
# Create xref nodes for each target of the graph's image map and
|
||||
# add them to the doc tree so that Sphinx can resolve the
|
||||
# references to real URLs later. These nodes will eventually be
|
||||
# removed from the doctree after we're done with them.
|
||||
for name in graph.get_all_class_names():
|
||||
refnodes, x = xfileref_role(
|
||||
'class', ':class:`%s`' % name, name, 0, state)
|
||||
node.extend(refnodes)
|
||||
# Store the graph object so we can use it to generate the
|
||||
# dot file later
|
||||
node['graph'] = graph
|
||||
# Store the original content for use as a hash
|
||||
node['parts'] = options.get('parts', 0)
|
||||
node['content'] = " ".join(class_names)
|
||||
return [node]
|
||||
|
||||
def get_graph_hash(node):
|
||||
return md5(node['content'] + str(node['parts'])).hexdigest()[-10:]
|
||||
|
||||
def html_output_graph(self, node):
|
||||
"""
|
||||
Output the graph for HTML. This will insert a PNG with clickable
|
||||
image map.
|
||||
"""
|
||||
graph = node['graph']
|
||||
parts = node['parts']
|
||||
|
||||
graph_hash = get_graph_hash(node)
|
||||
name = "inheritance%s" % graph_hash
|
||||
path = '_images'
|
||||
dest_path = os.path.join(setup.app.builder.outdir, path)
|
||||
if not os.path.exists(dest_path):
|
||||
os.makedirs(dest_path)
|
||||
png_path = os.path.join(dest_path, name + ".png")
|
||||
path = setup.app.builder.imgpath
|
||||
|
||||
# Create a mapping from fully-qualified class names to URLs.
|
||||
urls = {}
|
||||
for child in node:
|
||||
if child.get('refuri') is not None:
|
||||
urls[child['reftitle']] = child.get('refuri')
|
||||
elif child.get('refid') is not None:
|
||||
urls[child['reftitle']] = '#' + child.get('refid')
|
||||
|
||||
# These arguments to dot will save a PNG file to disk and write
|
||||
# an HTML image map to stdout.
|
||||
image_map = graph.run_dot(['-Tpng', '-o%s' % png_path, '-Tcmapx'],
|
||||
name, parts, urls)
|
||||
return ('<img src="%s/%s.png" usemap="#%s" class="inheritance"/>%s' %
|
||||
(path, name, name, image_map))
|
||||
|
||||
def latex_output_graph(self, node):
|
||||
"""
|
||||
Output the graph for LaTeX. This will insert a PDF.
|
||||
"""
|
||||
graph = node['graph']
|
||||
parts = node['parts']
|
||||
|
||||
graph_hash = get_graph_hash(node)
|
||||
name = "inheritance%s" % graph_hash
|
||||
dest_path = os.path.abspath(os.path.join(setup.app.builder.outdir, '_images'))
|
||||
if not os.path.exists(dest_path):
|
||||
os.makedirs(dest_path)
|
||||
pdf_path = os.path.abspath(os.path.join(dest_path, name + ".pdf"))
|
||||
|
||||
graph.run_dot(['-Tpdf', '-o%s' % pdf_path],
|
||||
name, parts, graph_options={'size': '"6.0,6.0"'})
|
||||
return '\n\\includegraphics{%s}\n\n' % pdf_path
|
||||
|
||||
def visit_inheritance_diagram(inner_func):
|
||||
"""
|
||||
This is just a wrapper around html/latex_output_graph to make it
|
||||
easier to handle errors and insert warnings.
|
||||
"""
|
||||
def visitor(self, node):
|
||||
try:
|
||||
content = inner_func(self, node)
|
||||
except DotException, e:
|
||||
# Insert the exception as a warning in the document
|
||||
warning = self.document.reporter.warning(str(e), line=node.line)
|
||||
warning.parent = node
|
||||
node.children = [warning]
|
||||
else:
|
||||
source = self.document.attributes['source']
|
||||
self.body.append(content)
|
||||
node.children = []
|
||||
return visitor
|
||||
|
||||
def do_nothing(self, node):
|
||||
pass
|
||||
|
||||
def setup(app):
|
||||
setup.app = app
|
||||
setup.confdir = app.confdir
|
||||
|
||||
app.add_node(
|
||||
inheritance_diagram,
|
||||
latex=(visit_inheritance_diagram(latex_output_graph), do_nothing),
|
||||
html=(visit_inheritance_diagram(html_output_graph), do_nothing))
|
||||
app.add_directive(
|
||||
'inheritance-diagram', inheritance_diagram_directive,
|
||||
False, (1, 100, 0), parts = directives.nonnegative_int)
|
||||
|
|
@ -4,7 +4,6 @@ XXX - See what improvements can be made based on the new (as of Sept 2009)
|
|||
'pycon' lexer for the python console. At the very least it will give better
|
||||
highlighted tracebacks.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Needed modules
|
||||
|
|
@ -113,3 +112,4 @@ def setup(app):
|
|||
#-----------------------------------------------------------------------------
|
||||
# Register the extension as a valid pygments lexer
|
||||
highlighting.lexers['ipython'] = IPythonConsoleLexer()
|
||||
|
||||
|
|
|
|||
|
|
@ -71,14 +71,17 @@ except ImportError:
|
|||
from md5 import md5
|
||||
|
||||
# Third-party
|
||||
import matplotlib
|
||||
try:
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
except ImportError:
|
||||
print "Couldn't find matplotlib"
|
||||
|
||||
import sphinx
|
||||
from docutils.parsers.rst import directives
|
||||
from docutils import nodes
|
||||
from sphinx.util.compat import Directive
|
||||
|
||||
matplotlib.use('Agg')
|
||||
|
||||
# Our own
|
||||
from IPython import Config, InteractiveShell
|
||||
from IPython.core.profiledir import ProfileDir
|
||||
|
|
@ -828,3 +831,5 @@ if __name__=='__main__':
|
|||
os.mkdir('_static')
|
||||
test()
|
||||
print 'All OK? Check figures in _static/'
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,120 +0,0 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
try:
|
||||
from hashlib import md5
|
||||
except ImportError:
|
||||
from md5 import md5
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import directives
|
||||
import warnings
|
||||
|
||||
from matplotlib import rcParams
|
||||
from matplotlib.mathtext import MathTextParser
|
||||
rcParams['mathtext.fontset'] = 'cm'
|
||||
mathtext_parser = MathTextParser("Bitmap")
|
||||
|
||||
# Define LaTeX math node:
|
||||
class latex_math(nodes.General, nodes.Element):
|
||||
pass
|
||||
|
||||
def fontset_choice(arg):
|
||||
return directives.choice(arg, ['cm', 'stix', 'stixsans'])
|
||||
|
||||
options_spec = {'fontset': fontset_choice}
|
||||
|
||||
def math_role(role, rawtext, text, lineno, inliner,
|
||||
options={}, content=[]):
|
||||
i = rawtext.find('`')
|
||||
latex = rawtext[i+1:-1]
|
||||
node = latex_math(rawtext)
|
||||
node['latex'] = latex
|
||||
node['fontset'] = options.get('fontset', 'cm')
|
||||
return [node], []
|
||||
math_role.options = options_spec
|
||||
|
||||
def math_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
latex = ''.join(content)
|
||||
node = latex_math(block_text)
|
||||
node['latex'] = latex
|
||||
node['fontset'] = options.get('fontset', 'cm')
|
||||
return [node]
|
||||
|
||||
# This uses mathtext to render the expression
|
||||
def latex2png(latex, filename, fontset='cm'):
|
||||
latex = "$%s$" % latex
|
||||
orig_fontset = rcParams['mathtext.fontset']
|
||||
rcParams['mathtext.fontset'] = fontset
|
||||
if os.path.exists(filename):
|
||||
depth = mathtext_parser.get_depth(latex, dpi=100)
|
||||
else:
|
||||
try:
|
||||
depth = mathtext_parser.to_png(filename, latex, dpi=100)
|
||||
except:
|
||||
warnings.warn("Could not render math expression %s" % latex,
|
||||
Warning)
|
||||
depth = 0
|
||||
rcParams['mathtext.fontset'] = orig_fontset
|
||||
sys.stdout.write("#")
|
||||
sys.stdout.flush()
|
||||
return depth
|
||||
|
||||
# LaTeX to HTML translation stuff:
|
||||
def latex2html(node, source):
|
||||
inline = isinstance(node.parent, nodes.TextElement)
|
||||
latex = node['latex']
|
||||
name = 'math-%s' % md5(latex).hexdigest()[-10:]
|
||||
|
||||
destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl')
|
||||
if not os.path.exists(destdir):
|
||||
os.makedirs(destdir)
|
||||
dest = os.path.join(destdir, '%s.png' % name)
|
||||
path = os.path.join(setup.app.builder.imgpath, 'mathmpl')
|
||||
|
||||
depth = latex2png(latex, dest, node['fontset'])
|
||||
|
||||
if inline:
|
||||
cls = ''
|
||||
else:
|
||||
cls = 'class="center" '
|
||||
if inline and depth != 0:
|
||||
style = 'style="position: relative; bottom: -%dpx"' % (depth + 1)
|
||||
else:
|
||||
style = ''
|
||||
|
||||
return '<img src="%s/%s.png" %s%s/>' % (path, name, cls, style)
|
||||
|
||||
def setup(app):
|
||||
setup.app = app
|
||||
|
||||
app.add_node(latex_math)
|
||||
app.add_role('math', math_role)
|
||||
|
||||
# Add visit/depart methods to HTML-Translator:
|
||||
def visit_latex_math_html(self, node):
|
||||
source = self.document.attributes['source']
|
||||
self.body.append(latex2html(node, source))
|
||||
def depart_latex_math_html(self, node):
|
||||
pass
|
||||
|
||||
# Add visit/depart methods to LaTeX-Translator:
|
||||
def visit_latex_math_latex(self, node):
|
||||
inline = isinstance(node.parent, nodes.TextElement)
|
||||
if inline:
|
||||
self.body.append('$%s$' % node['latex'])
|
||||
else:
|
||||
self.body.extend(['\\begin{equation}',
|
||||
node['latex'],
|
||||
'\\end{equation}'])
|
||||
def depart_latex_math_latex(self, node):
|
||||
pass
|
||||
|
||||
app.add_node(latex_math, html=(visit_latex_math_html,
|
||||
depart_latex_math_html))
|
||||
app.add_node(latex_math, latex=(visit_latex_math_latex,
|
||||
depart_latex_math_latex))
|
||||
app.add_role('math', math_role)
|
||||
app.add_directive('math', math_directive,
|
||||
True, (0, 0, 0), **options_spec)
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
"""
|
||||
========
|
||||
numpydoc
|
||||
========
|
||||
|
||||
Sphinx extension that handles docstrings in the Numpy standard format. [1]
|
||||
|
||||
It will:
|
||||
|
||||
- Convert Parameters etc. sections to field lists.
|
||||
- Convert See Also section to a See also entry.
|
||||
- Renumber references.
|
||||
- Extract the signature from the docstring, if it can't be determined otherwise.
|
||||
|
||||
.. [1] http://projects.scipy.org/scipy/numpy/wiki/CodingStyleGuidelines#docstring-standard
|
||||
|
||||
"""
|
||||
|
||||
import os, re, pydoc
|
||||
from docscrape_sphinx import get_doc_object, SphinxDocString
|
||||
import inspect
|
||||
|
||||
def mangle_docstrings(app, what, name, obj, options, lines,
|
||||
reference_offset=[0]):
|
||||
if what == 'module':
|
||||
# Strip top title
|
||||
title_re = re.compile(r'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*',
|
||||
re.I|re.S)
|
||||
lines[:] = title_re.sub('', "\n".join(lines)).split("\n")
|
||||
else:
|
||||
doc = get_doc_object(obj, what, "\n".join(lines))
|
||||
lines[:] = str(doc).split("\n")
|
||||
|
||||
if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \
|
||||
obj.__name__:
|
||||
if hasattr(obj, '__module__'):
|
||||
v = dict(full_name="%s.%s" % (obj.__module__, obj.__name__))
|
||||
else:
|
||||
v = dict(full_name=obj.__name__)
|
||||
lines += ['', '.. htmlonly::', '']
|
||||
lines += [' %s' % x for x in
|
||||
(app.config.numpydoc_edit_link % v).split("\n")]
|
||||
|
||||
# replace reference numbers so that there are no duplicates
|
||||
references = []
|
||||
for l in lines:
|
||||
l = l.strip()
|
||||
if l.startswith('.. ['):
|
||||
try:
|
||||
references.append(int(l[len('.. ['):l.index(']')]))
|
||||
except ValueError:
|
||||
print "WARNING: invalid reference in %s docstring" % name
|
||||
|
||||
# Start renaming from the biggest number, otherwise we may
|
||||
# overwrite references.
|
||||
references.sort()
|
||||
if references:
|
||||
for i, line in enumerate(lines):
|
||||
for r in references:
|
||||
new_r = reference_offset[0] + r
|
||||
lines[i] = lines[i].replace('[%d]_' % r,
|
||||
'[%d]_' % new_r)
|
||||
lines[i] = lines[i].replace('.. [%d]' % r,
|
||||
'.. [%d]' % new_r)
|
||||
|
||||
reference_offset[0] += len(references)
|
||||
|
||||
def mangle_signature(app, what, name, obj, options, sig, retann):
|
||||
# Do not try to inspect classes that don't define `__init__`
|
||||
if (inspect.isclass(obj) and
|
||||
'initializes x; see ' in pydoc.getdoc(obj.__init__)):
|
||||
return '', ''
|
||||
|
||||
if not (callable(obj) or hasattr(obj, '__argspec_is_invalid_')): return
|
||||
if not hasattr(obj, '__doc__'): return
|
||||
|
||||
doc = SphinxDocString(pydoc.getdoc(obj))
|
||||
if doc['Signature']:
|
||||
sig = re.sub("^[^(]*", "", doc['Signature'])
|
||||
return sig, ''
|
||||
|
||||
def initialize(app):
|
||||
try:
|
||||
app.connect('autodoc-process-signature', mangle_signature)
|
||||
except:
|
||||
monkeypatch_sphinx_ext_autodoc()
|
||||
|
||||
def setup(app, get_doc_object_=get_doc_object):
|
||||
global get_doc_object
|
||||
get_doc_object = get_doc_object_
|
||||
|
||||
app.connect('autodoc-process-docstring', mangle_docstrings)
|
||||
app.connect('builder-inited', initialize)
|
||||
app.add_config_value('numpydoc_edit_link', None, True)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Monkeypatch sphinx.ext.autodoc to accept argspecless autodocs (Sphinx < 0.5)
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
def monkeypatch_sphinx_ext_autodoc():
|
||||
global _original_format_signature
|
||||
import sphinx.ext.autodoc
|
||||
|
||||
if sphinx.ext.autodoc.format_signature is our_format_signature:
|
||||
return
|
||||
|
||||
print "[numpydoc] Monkeypatching sphinx.ext.autodoc ..."
|
||||
_original_format_signature = sphinx.ext.autodoc.format_signature
|
||||
sphinx.ext.autodoc.format_signature = our_format_signature
|
||||
|
||||
def our_format_signature(what, obj):
|
||||
r = mangle_signature(None, what, None, obj, None, None, None)
|
||||
if r is not None:
|
||||
return r[0]
|
||||
else:
|
||||
return _original_format_signature(what, obj)
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
#
|
||||
# A pair of directives for inserting content that will only appear in
|
||||
# either html or latex.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
from docutils.nodes import Body, Element
|
||||
from docutils.parsers.rst import directives
|
||||
|
||||
class only_base(Body, Element):
|
||||
def dont_traverse(self, *args, **kwargs):
|
||||
return []
|
||||
|
||||
class html_only(only_base):
|
||||
pass
|
||||
|
||||
class latex_only(only_base):
|
||||
pass
|
||||
|
||||
def run(content, node_class, state, content_offset):
|
||||
text = '\n'.join(content)
|
||||
node = node_class(text)
|
||||
state.nested_parse(content, content_offset, node)
|
||||
return [node]
|
||||
|
||||
def html_only_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
return run(content, html_only, state, content_offset)
|
||||
|
||||
def latex_only_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
return run(content, latex_only, state, content_offset)
|
||||
|
||||
def builder_inited(app):
|
||||
if app.builder.name == 'html':
|
||||
latex_only.traverse = only_base.dont_traverse
|
||||
else:
|
||||
html_only.traverse = only_base.dont_traverse
|
||||
|
||||
def setup(app):
|
||||
app.add_directive('htmlonly', html_only_directive, True, (0, 0, 0))
|
||||
app.add_directive('latexonly', latex_only_directive, True, (0, 0, 0))
|
||||
app.add_node(html_only)
|
||||
app.add_node(latex_only)
|
||||
|
||||
# This will *really* never see the light of day As it turns out,
|
||||
# this results in "broken" image nodes since they never get
|
||||
# processed, so best not to do this.
|
||||
# app.connect('builder-inited', builder_inited)
|
||||
|
||||
# Add visit/depart methods to HTML-Translator:
|
||||
def visit_perform(self, node):
|
||||
pass
|
||||
def depart_perform(self, node):
|
||||
pass
|
||||
def visit_ignore(self, node):
|
||||
node.children = []
|
||||
def depart_ignore(self, node):
|
||||
node.children = []
|
||||
|
||||
app.add_node(html_only, html=(visit_perform, depart_perform))
|
||||
app.add_node(html_only, latex=(visit_ignore, depart_ignore))
|
||||
app.add_node(latex_only, latex=(visit_perform, depart_perform))
|
||||
app.add_node(latex_only, html=(visit_ignore, depart_ignore))
|
||||
|
|
@ -1,819 +0,0 @@
|
|||
"""
|
||||
A directive for including a matplotlib plot in a Sphinx document.
|
||||
|
||||
By default, in HTML output, `plot` will include a .png file with a
|
||||
link to a high-res .png and .pdf. In LaTeX output, it will include a
|
||||
.pdf.
|
||||
|
||||
The source code for the plot may be included in one of three ways:
|
||||
|
||||
1. **A path to a source file** as the argument to the directive::
|
||||
|
||||
.. plot:: path/to/plot.py
|
||||
|
||||
When a path to a source file is given, the content of the
|
||||
directive may optionally contain a caption for the plot::
|
||||
|
||||
.. plot:: path/to/plot.py
|
||||
|
||||
This is the caption for the plot
|
||||
|
||||
Additionally, one my specify the name of a function to call (with
|
||||
no arguments) immediately after importing the module::
|
||||
|
||||
.. plot:: path/to/plot.py plot_function1
|
||||
|
||||
2. Included as **inline content** to the directive::
|
||||
|
||||
.. plot::
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.image as mpimg
|
||||
import numpy as np
|
||||
img = mpimg.imread('_static/stinkbug.png')
|
||||
imgplot = plt.imshow(img)
|
||||
|
||||
3. Using **doctest** syntax::
|
||||
|
||||
.. plot::
|
||||
A plotting example:
|
||||
>>> import matplotlib.pyplot as plt
|
||||
>>> plt.plot([1,2,3], [4,5,6])
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
The ``plot`` directive supports the following options:
|
||||
|
||||
format : {'python', 'doctest'}
|
||||
Specify the format of the input
|
||||
|
||||
include-source : bool
|
||||
Whether to display the source code. The default can be changed
|
||||
using the `plot_include_source` variable in conf.py
|
||||
|
||||
encoding : str
|
||||
If this source file is in a non-UTF8 or non-ASCII encoding,
|
||||
the encoding must be specified using the `:encoding:` option.
|
||||
The encoding will not be inferred using the ``-*- coding -*-``
|
||||
metacomment.
|
||||
|
||||
context : bool
|
||||
If provided, the code will be run in the context of all
|
||||
previous plot directives for which the `:context:` option was
|
||||
specified. This only applies to inline code plot directives,
|
||||
not those run from files.
|
||||
|
||||
nofigs : bool
|
||||
If specified, the code block will be run, but no figures will
|
||||
be inserted. This is usually useful with the ``:context:``
|
||||
option.
|
||||
|
||||
Additionally, this directive supports all of the options of the
|
||||
`image` directive, except for `target` (since plot will add its own
|
||||
target). These include `alt`, `height`, `width`, `scale`, `align` and
|
||||
`class`.
|
||||
|
||||
Configuration options
|
||||
---------------------
|
||||
|
||||
The plot directive has the following configuration options:
|
||||
|
||||
plot_include_source
|
||||
Default value for the include-source option
|
||||
|
||||
plot_pre_code
|
||||
Code that should be executed before each plot.
|
||||
|
||||
plot_basedir
|
||||
Base directory, to which ``plot::`` file names are relative
|
||||
to. (If None or empty, file names are relative to the
|
||||
directoly where the file containing the directive is.)
|
||||
|
||||
plot_formats
|
||||
File formats to generate. List of tuples or strings::
|
||||
|
||||
[(suffix, dpi), suffix, ...]
|
||||
|
||||
that determine the file format and the DPI. For entries whose
|
||||
DPI was omitted, sensible defaults are chosen.
|
||||
|
||||
plot_html_show_formats
|
||||
Whether to show links to the files in HTML.
|
||||
|
||||
plot_rcparams
|
||||
A dictionary containing any non-standard rcParams that should
|
||||
be applied before each plot.
|
||||
|
||||
plot_apply_rcparams
|
||||
By default, rcParams are applied when `context` option is not used in
|
||||
a plot directive. This configuration option overrides this behaviour
|
||||
and applies rcParams before each plot.
|
||||
|
||||
plot_working_directory
|
||||
By default, the working directory will be changed to the directory of
|
||||
the example, so the code can get at its data files, if any. Also its
|
||||
path will be added to `sys.path` so it can import any helper modules
|
||||
sitting beside it. This configuration option can be used to specify
|
||||
a central directory (also added to `sys.path`) where data files and
|
||||
helper modules for all code are located.
|
||||
|
||||
plot_template
|
||||
Provide a customized template for preparing resturctured text.
|
||||
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import sys, os, glob, shutil, imp, warnings, cStringIO, re, textwrap, \
|
||||
traceback, exceptions
|
||||
|
||||
from docutils.parsers.rst import directives
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst.directives.images import Image
|
||||
align = Image.align
|
||||
import sphinx
|
||||
|
||||
sphinx_version = sphinx.__version__.split(".")
|
||||
# The split is necessary for sphinx beta versions where the string is
|
||||
# '6b1'
|
||||
sphinx_version = tuple([int(re.split('[a-z]', x)[0])
|
||||
for x in sphinx_version[:2]])
|
||||
|
||||
try:
|
||||
# Sphinx depends on either Jinja or Jinja2
|
||||
import jinja2
|
||||
def format_template(template, **kw):
|
||||
return jinja2.Template(template).render(**kw)
|
||||
except ImportError:
|
||||
import jinja
|
||||
def format_template(template, **kw):
|
||||
return jinja.from_string(template, **kw)
|
||||
|
||||
import matplotlib
|
||||
import matplotlib.cbook as cbook
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import _pylab_helpers
|
||||
|
||||
__version__ = 2
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Relative pathnames
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# os.path.relpath is new in Python 2.6
|
||||
try:
|
||||
from os.path import relpath
|
||||
except ImportError:
|
||||
# Copied from Python 2.7
|
||||
if 'posix' in sys.builtin_module_names:
|
||||
def relpath(path, start=os.path.curdir):
|
||||
"""Return a relative version of a path"""
|
||||
from os.path import sep, curdir, join, abspath, commonprefix, \
|
||||
pardir
|
||||
|
||||
if not path:
|
||||
raise ValueError("no path specified")
|
||||
|
||||
start_list = abspath(start).split(sep)
|
||||
path_list = abspath(path).split(sep)
|
||||
|
||||
# Work out how much of the filepath is shared by start and path.
|
||||
i = len(commonprefix([start_list, path_list]))
|
||||
|
||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||
if not rel_list:
|
||||
return curdir
|
||||
return join(*rel_list)
|
||||
elif 'nt' in sys.builtin_module_names:
|
||||
def relpath(path, start=os.path.curdir):
|
||||
"""Return a relative version of a path"""
|
||||
from os.path import sep, curdir, join, abspath, commonprefix, \
|
||||
pardir, splitunc
|
||||
|
||||
if not path:
|
||||
raise ValueError("no path specified")
|
||||
start_list = abspath(start).split(sep)
|
||||
path_list = abspath(path).split(sep)
|
||||
if start_list[0].lower() != path_list[0].lower():
|
||||
unc_path, rest = splitunc(path)
|
||||
unc_start, rest = splitunc(start)
|
||||
if bool(unc_path) ^ bool(unc_start):
|
||||
raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
|
||||
% (path, start))
|
||||
else:
|
||||
raise ValueError("path is on drive %s, start on drive %s"
|
||||
% (path_list[0], start_list[0]))
|
||||
# Work out how much of the filepath is shared by start and path.
|
||||
for i in range(min(len(start_list), len(path_list))):
|
||||
if start_list[i].lower() != path_list[i].lower():
|
||||
break
|
||||
else:
|
||||
i += 1
|
||||
|
||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||
if not rel_list:
|
||||
return curdir
|
||||
return join(*rel_list)
|
||||
else:
|
||||
raise RuntimeError("Unsupported platform (no relpath available!)")
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Registration hook
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
def plot_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
return run(arguments, content, options, state_machine, state, lineno)
|
||||
plot_directive.__doc__ = __doc__
|
||||
|
||||
def _option_boolean(arg):
|
||||
if not arg or not arg.strip():
|
||||
# no argument given, assume used as a flag
|
||||
return True
|
||||
elif arg.strip().lower() in ('no', '0', 'false'):
|
||||
return False
|
||||
elif arg.strip().lower() in ('yes', '1', 'true'):
|
||||
return True
|
||||
else:
|
||||
raise ValueError('"%s" unknown boolean' % arg)
|
||||
|
||||
def _option_format(arg):
|
||||
return directives.choice(arg, ('python', 'doctest'))
|
||||
|
||||
def _option_align(arg):
|
||||
return directives.choice(arg, ("top", "middle", "bottom", "left", "center",
|
||||
"right"))
|
||||
|
||||
def mark_plot_labels(app, document):
|
||||
"""
|
||||
To make plots referenceable, we need to move the reference from
|
||||
the "htmlonly" (or "latexonly") node to the actual figure node
|
||||
itself.
|
||||
"""
|
||||
for name, explicit in document.nametypes.iteritems():
|
||||
if not explicit:
|
||||
continue
|
||||
labelid = document.nameids[name]
|
||||
if labelid is None:
|
||||
continue
|
||||
node = document.ids[labelid]
|
||||
if node.tagname in ('html_only', 'latex_only'):
|
||||
for n in node:
|
||||
if n.tagname == 'figure':
|
||||
sectname = name
|
||||
for c in n:
|
||||
if c.tagname == 'caption':
|
||||
sectname = c.astext()
|
||||
break
|
||||
|
||||
node['ids'].remove(labelid)
|
||||
node['names'].remove(name)
|
||||
n['ids'].append(labelid)
|
||||
n['names'].append(name)
|
||||
document.settings.env.labels[name] = \
|
||||
document.settings.env.docname, labelid, sectname
|
||||
break
|
||||
|
||||
def setup(app):
|
||||
setup.app = app
|
||||
setup.config = app.config
|
||||
setup.confdir = app.confdir
|
||||
|
||||
options = {'alt': directives.unchanged,
|
||||
'height': directives.length_or_unitless,
|
||||
'width': directives.length_or_percentage_or_unitless,
|
||||
'scale': directives.nonnegative_int,
|
||||
'align': _option_align,
|
||||
'class': directives.class_option,
|
||||
'include-source': _option_boolean,
|
||||
'format': _option_format,
|
||||
'context': directives.flag,
|
||||
'nofigs': directives.flag,
|
||||
'encoding': directives.encoding
|
||||
}
|
||||
|
||||
app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
|
||||
app.add_config_value('plot_pre_code', None, True)
|
||||
app.add_config_value('plot_include_source', False, True)
|
||||
app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
|
||||
app.add_config_value('plot_basedir', None, True)
|
||||
app.add_config_value('plot_html_show_formats', True, True)
|
||||
app.add_config_value('plot_rcparams', {}, True)
|
||||
app.add_config_value('plot_apply_rcparams', False, True)
|
||||
app.add_config_value('plot_working_directory', None, True)
|
||||
app.add_config_value('plot_template', None, True)
|
||||
|
||||
app.connect('doctree-read', mark_plot_labels)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Doctest handling
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
def contains_doctest(text):
|
||||
try:
|
||||
# check if it's valid Python as-is
|
||||
compile(text, '<string>', 'exec')
|
||||
return False
|
||||
except SyntaxError:
|
||||
pass
|
||||
r = re.compile(r'^\s*>>>', re.M)
|
||||
m = r.search(text)
|
||||
return bool(m)
|
||||
|
||||
def unescape_doctest(text):
|
||||
"""
|
||||
Extract code from a piece of text, which contains either Python code
|
||||
or doctests.
|
||||
|
||||
"""
|
||||
if not contains_doctest(text):
|
||||
return text
|
||||
|
||||
code = ""
|
||||
for line in text.split("\n"):
|
||||
m = re.match(r'^\s*(>>>|\.\.\.) (.*)$', line)
|
||||
if m:
|
||||
code += m.group(2) + "\n"
|
||||
elif line.strip():
|
||||
code += "# " + line.strip() + "\n"
|
||||
else:
|
||||
code += "\n"
|
||||
return code
|
||||
|
||||
def split_code_at_show(text):
|
||||
"""
|
||||
Split code at plt.show()
|
||||
|
||||
"""
|
||||
|
||||
parts = []
|
||||
is_doctest = contains_doctest(text)
|
||||
|
||||
part = []
|
||||
for line in text.split("\n"):
|
||||
if (not is_doctest and line.strip() == 'plt.show()') or \
|
||||
(is_doctest and line.strip() == '>>> plt.show()'):
|
||||
part.append(line)
|
||||
parts.append("\n".join(part))
|
||||
part = []
|
||||
else:
|
||||
part.append(line)
|
||||
if "\n".join(part).strip():
|
||||
parts.append("\n".join(part))
|
||||
return parts
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Template
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
|
||||
TEMPLATE = """
|
||||
{{ source_code }}
|
||||
|
||||
{{ only_html }}
|
||||
|
||||
{% if source_link or (html_show_formats and not multi_image) %}
|
||||
(
|
||||
{%- if source_link -%}
|
||||
`Source code <{{ source_link }}>`__
|
||||
{%- endif -%}
|
||||
{%- if html_show_formats and not multi_image -%}
|
||||
{%- for img in images -%}
|
||||
{%- for fmt in img.formats -%}
|
||||
{%- if source_link or not loop.first -%}, {% endif -%}
|
||||
`{{ fmt }} <{{ dest_dir }}/{{ img.basename }}.{{ fmt }}>`__
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
{% for img in images %}
|
||||
.. figure:: {{ build_dir }}/{{ img.basename }}.png
|
||||
{%- for option in options %}
|
||||
{{ option }}
|
||||
{% endfor %}
|
||||
|
||||
{% if html_show_formats and multi_image -%}
|
||||
(
|
||||
{%- for fmt in img.formats -%}
|
||||
{%- if not loop.first -%}, {% endif -%}
|
||||
`{{ fmt }} <{{ dest_dir }}/{{ img.basename }}.{{ fmt }}>`__
|
||||
{%- endfor -%}
|
||||
)
|
||||
{%- endif -%}
|
||||
|
||||
{{ caption }}
|
||||
{% endfor %}
|
||||
|
||||
{{ only_latex }}
|
||||
|
||||
{% for img in images %}
|
||||
.. image:: {{ build_dir }}/{{ img.basename }}.pdf
|
||||
{% endfor %}
|
||||
|
||||
{{ only_texinfo }}
|
||||
|
||||
{% for img in images %}
|
||||
.. image:: {{ build_dir }}/{{ img.basename }}.png
|
||||
{%- for option in options %}
|
||||
{{ option }}
|
||||
{% endfor %}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
"""
|
||||
|
||||
exception_template = """
|
||||
.. htmlonly::
|
||||
|
||||
[`source code <%(linkdir)s/%(basename)s.py>`__]
|
||||
|
||||
Exception occurred rendering plot.
|
||||
|
||||
"""
|
||||
|
||||
# the context of the plot for all directives specified with the
|
||||
# :context: option
|
||||
plot_context = dict()
|
||||
|
||||
class ImageFile(object):
|
||||
def __init__(self, basename, dirname):
|
||||
self.basename = basename
|
||||
self.dirname = dirname
|
||||
self.formats = []
|
||||
|
||||
def filename(self, format):
|
||||
return os.path.join(self.dirname, "%s.%s" % (self.basename, format))
|
||||
|
||||
def filenames(self):
|
||||
return [self.filename(fmt) for fmt in self.formats]
|
||||
|
||||
def out_of_date(original, derived):
|
||||
"""
|
||||
Returns True if derivative is out-of-date wrt original,
|
||||
both of which are full file paths.
|
||||
"""
|
||||
return (not os.path.exists(derived) or
|
||||
(os.path.exists(original) and
|
||||
os.stat(derived).st_mtime < os.stat(original).st_mtime))
|
||||
|
||||
class PlotError(RuntimeError):
|
||||
pass
|
||||
|
||||
def run_code(code, code_path, ns=None, function_name=None):
|
||||
"""
|
||||
Import a Python module from a path, and run the function given by
|
||||
name, if function_name is not None.
|
||||
"""
|
||||
|
||||
# Change the working directory to the directory of the example, so
|
||||
# it can get at its data files, if any. Add its path to sys.path
|
||||
# so it can import any helper modules sitting beside it.
|
||||
|
||||
pwd = os.getcwd()
|
||||
old_sys_path = list(sys.path)
|
||||
if setup.config.plot_working_directory is not None:
|
||||
try:
|
||||
os.chdir(setup.config.plot_working_directory)
|
||||
except OSError as err:
|
||||
raise OSError(str(err) + '\n`plot_working_directory` option in'
|
||||
'Sphinx configuration file must be a valid '
|
||||
'directory path')
|
||||
except TypeError as err:
|
||||
raise TypeError(str(err) + '\n`plot_working_directory` option in '
|
||||
'Sphinx configuration file must be a string or '
|
||||
'None')
|
||||
sys.path.insert(0, setup.config.plot_working_directory)
|
||||
elif code_path is not None:
|
||||
dirname = os.path.abspath(os.path.dirname(code_path))
|
||||
os.chdir(dirname)
|
||||
sys.path.insert(0, dirname)
|
||||
|
||||
# Redirect stdout
|
||||
stdout = sys.stdout
|
||||
sys.stdout = cStringIO.StringIO()
|
||||
|
||||
# Reset sys.argv
|
||||
old_sys_argv = sys.argv
|
||||
sys.argv = [code_path]
|
||||
|
||||
try:
|
||||
try:
|
||||
code = unescape_doctest(code)
|
||||
if ns is None:
|
||||
ns = {}
|
||||
if not ns:
|
||||
if setup.config.plot_pre_code is None:
|
||||
exec "import numpy as np\nfrom matplotlib import pyplot as plt\n" in ns
|
||||
else:
|
||||
exec setup.config.plot_pre_code in ns
|
||||
if "__main__" in code:
|
||||
exec "__name__ = '__main__'" in ns
|
||||
exec code in ns
|
||||
if function_name is not None:
|
||||
exec function_name + "()" in ns
|
||||
except (Exception, SystemExit), err:
|
||||
raise PlotError(traceback.format_exc())
|
||||
finally:
|
||||
os.chdir(pwd)
|
||||
sys.argv = old_sys_argv
|
||||
sys.path[:] = old_sys_path
|
||||
sys.stdout = stdout
|
||||
return ns
|
||||
|
||||
def clear_state(plot_rcparams):
|
||||
plt.close('all')
|
||||
matplotlib.rc_file_defaults()
|
||||
matplotlib.rcParams.update(plot_rcparams)
|
||||
|
||||
def render_figures(code, code_path, output_dir, output_base, context,
|
||||
function_name, config):
|
||||
"""
|
||||
Run a pyplot script and save the low and high res PNGs and a PDF
|
||||
in outdir.
|
||||
|
||||
Save the images under *output_dir* with file names derived from
|
||||
*output_base*
|
||||
"""
|
||||
# -- Parse format list
|
||||
default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200}
|
||||
formats = []
|
||||
plot_formats = config.plot_formats
|
||||
if isinstance(plot_formats, (str, unicode)):
|
||||
plot_formats = eval(plot_formats)
|
||||
for fmt in plot_formats:
|
||||
if isinstance(fmt, str):
|
||||
formats.append((fmt, default_dpi.get(fmt, 80)))
|
||||
elif type(fmt) in (tuple, list) and len(fmt)==2:
|
||||
formats.append((str(fmt[0]), int(fmt[1])))
|
||||
else:
|
||||
raise PlotError('invalid image format "%r" in plot_formats' % fmt)
|
||||
|
||||
# -- Try to determine if all images already exist
|
||||
|
||||
code_pieces = split_code_at_show(code)
|
||||
|
||||
# Look for single-figure output files first
|
||||
# Look for single-figure output files first
|
||||
all_exists = True
|
||||
img = ImageFile(output_base, output_dir)
|
||||
for format, dpi in formats:
|
||||
if out_of_date(code_path, img.filename(format)):
|
||||
all_exists = False
|
||||
break
|
||||
img.formats.append(format)
|
||||
|
||||
if all_exists:
|
||||
return [(code, [img])]
|
||||
|
||||
# Then look for multi-figure output files
|
||||
results = []
|
||||
all_exists = True
|
||||
for i, code_piece in enumerate(code_pieces):
|
||||
images = []
|
||||
for j in xrange(1000):
|
||||
if len(code_pieces) > 1:
|
||||
img = ImageFile('%s_%02d_%02d' % (output_base, i, j), output_dir)
|
||||
else:
|
||||
img = ImageFile('%s_%02d' % (output_base, j), output_dir)
|
||||
for format, dpi in formats:
|
||||
if out_of_date(code_path, img.filename(format)):
|
||||
all_exists = False
|
||||
break
|
||||
img.formats.append(format)
|
||||
|
||||
# assume that if we have one, we have them all
|
||||
if not all_exists:
|
||||
all_exists = (j > 0)
|
||||
break
|
||||
images.append(img)
|
||||
if not all_exists:
|
||||
break
|
||||
results.append((code_piece, images))
|
||||
|
||||
if all_exists:
|
||||
return results
|
||||
|
||||
# We didn't find the files, so build them
|
||||
|
||||
results = []
|
||||
if context:
|
||||
ns = plot_context
|
||||
else:
|
||||
ns = {}
|
||||
|
||||
for i, code_piece in enumerate(code_pieces):
|
||||
if not context or config.plot_apply_rcparams:
|
||||
clear_state(config.plot_rcparams)
|
||||
run_code(code_piece, code_path, ns, function_name)
|
||||
|
||||
images = []
|
||||
fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()
|
||||
for j, figman in enumerate(fig_managers):
|
||||
if len(fig_managers) == 1 and len(code_pieces) == 1:
|
||||
img = ImageFile(output_base, output_dir)
|
||||
elif len(code_pieces) == 1:
|
||||
img = ImageFile("%s_%02d" % (output_base, j), output_dir)
|
||||
else:
|
||||
img = ImageFile("%s_%02d_%02d" % (output_base, i, j),
|
||||
output_dir)
|
||||
images.append(img)
|
||||
for format, dpi in formats:
|
||||
try:
|
||||
figman.canvas.figure.savefig(img.filename(format), dpi=dpi)
|
||||
except Exception,err:
|
||||
raise PlotError(traceback.format_exc())
|
||||
img.formats.append(format)
|
||||
|
||||
results.append((code_piece, images))
|
||||
|
||||
if not context or config.plot_apply_rcparams:
|
||||
clear_state(config.plot_rcparams)
|
||||
|
||||
return results
|
||||
|
||||
def run(arguments, content, options, state_machine, state, lineno):
|
||||
# The user may provide a filename *or* Python code content, but not both
|
||||
if arguments and content:
|
||||
raise RuntimeError("plot:: directive can't have both args and content")
|
||||
|
||||
document = state_machine.document
|
||||
config = document.settings.env.config
|
||||
nofigs = options.has_key('nofigs')
|
||||
|
||||
options.setdefault('include-source', config.plot_include_source)
|
||||
context = options.has_key('context')
|
||||
|
||||
rst_file = document.attributes['source']
|
||||
rst_dir = os.path.dirname(rst_file)
|
||||
|
||||
if len(arguments):
|
||||
if not config.plot_basedir:
|
||||
source_file_name = os.path.join(setup.app.builder.srcdir,
|
||||
directives.uri(arguments[0]))
|
||||
else:
|
||||
source_file_name = os.path.join(setup.confdir, config.plot_basedir,
|
||||
directives.uri(arguments[0]))
|
||||
|
||||
# If there is content, it will be passed as a caption.
|
||||
caption = '\n'.join(content)
|
||||
|
||||
# If the optional function name is provided, use it
|
||||
if len(arguments) == 2:
|
||||
function_name = arguments[1]
|
||||
else:
|
||||
function_name = None
|
||||
|
||||
with open(source_file_name, 'r') as fd:
|
||||
code = fd.read()
|
||||
output_base = os.path.basename(source_file_name)
|
||||
else:
|
||||
source_file_name = rst_file
|
||||
code = textwrap.dedent("\n".join(map(str, content)))
|
||||
counter = document.attributes.get('_plot_counter', 0) + 1
|
||||
document.attributes['_plot_counter'] = counter
|
||||
base, ext = os.path.splitext(os.path.basename(source_file_name))
|
||||
output_base = '%s-%d.py' % (base, counter)
|
||||
function_name = None
|
||||
caption = ''
|
||||
|
||||
base, source_ext = os.path.splitext(output_base)
|
||||
if source_ext in ('.py', '.rst', '.txt'):
|
||||
output_base = base
|
||||
else:
|
||||
source_ext = ''
|
||||
|
||||
# ensure that LaTeX includegraphics doesn't choke in foo.bar.pdf filenames
|
||||
output_base = output_base.replace('.', '-')
|
||||
|
||||
# is it in doctest format?
|
||||
is_doctest = contains_doctest(code)
|
||||
if options.has_key('format'):
|
||||
if options['format'] == 'python':
|
||||
is_doctest = False
|
||||
else:
|
||||
is_doctest = True
|
||||
|
||||
# determine output directory name fragment
|
||||
source_rel_name = relpath(source_file_name, setup.confdir)
|
||||
source_rel_dir = os.path.dirname(source_rel_name)
|
||||
while source_rel_dir.startswith(os.path.sep):
|
||||
source_rel_dir = source_rel_dir[1:]
|
||||
|
||||
# build_dir: where to place output files (temporarily)
|
||||
build_dir = os.path.join(os.path.dirname(setup.app.doctreedir),
|
||||
'plot_directive',
|
||||
source_rel_dir)
|
||||
# get rid of .. in paths, also changes pathsep
|
||||
# see note in Python docs for warning about symbolic links on Windows.
|
||||
# need to compare source and dest paths at end
|
||||
build_dir = os.path.normpath(build_dir)
|
||||
|
||||
if not os.path.exists(build_dir):
|
||||
os.makedirs(build_dir)
|
||||
|
||||
# output_dir: final location in the builder's directory
|
||||
dest_dir = os.path.abspath(os.path.join(setup.app.builder.outdir,
|
||||
source_rel_dir))
|
||||
if not os.path.exists(dest_dir):
|
||||
os.makedirs(dest_dir) # no problem here for me, but just use built-ins
|
||||
|
||||
# how to link to files from the RST file
|
||||
dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),
|
||||
source_rel_dir).replace(os.path.sep, '/')
|
||||
build_dir_link = relpath(build_dir, rst_dir).replace(os.path.sep, '/')
|
||||
source_link = dest_dir_link + '/' + output_base + source_ext
|
||||
|
||||
# make figures
|
||||
try:
|
||||
results = render_figures(code, source_file_name, build_dir, output_base,
|
||||
context, function_name, config)
|
||||
errors = []
|
||||
except PlotError, err:
|
||||
reporter = state.memo.reporter
|
||||
sm = reporter.system_message(
|
||||
2, "Exception occurred in plotting %s\n from %s:\n%s" % (output_base,
|
||||
source_file_name, err),
|
||||
line=lineno)
|
||||
results = [(code, [])]
|
||||
errors = [sm]
|
||||
|
||||
# Properly indent the caption
|
||||
caption = '\n'.join(' ' + line.strip()
|
||||
for line in caption.split('\n'))
|
||||
|
||||
# generate output restructuredtext
|
||||
total_lines = []
|
||||
for j, (code_piece, images) in enumerate(results):
|
||||
if options['include-source']:
|
||||
if is_doctest:
|
||||
lines = ['']
|
||||
lines += [row.rstrip() for row in code_piece.split('\n')]
|
||||
else:
|
||||
lines = ['.. code-block:: python', '']
|
||||
lines += [' %s' % row.rstrip()
|
||||
for row in code_piece.split('\n')]
|
||||
source_code = "\n".join(lines)
|
||||
else:
|
||||
source_code = ""
|
||||
|
||||
if nofigs:
|
||||
images = []
|
||||
|
||||
opts = [':%s: %s' % (key, val) for key, val in options.items()
|
||||
if key in ('alt', 'height', 'width', 'scale', 'align', 'class')]
|
||||
|
||||
only_html = ".. only:: html"
|
||||
only_latex = ".. only:: latex"
|
||||
only_texinfo = ".. only:: texinfo"
|
||||
|
||||
if j == 0:
|
||||
src_link = source_link
|
||||
else:
|
||||
src_link = None
|
||||
|
||||
result = format_template(
|
||||
config.plot_template or TEMPLATE,
|
||||
dest_dir=dest_dir_link,
|
||||
build_dir=build_dir_link,
|
||||
source_link=src_link,
|
||||
multi_image=len(images) > 1,
|
||||
only_html=only_html,
|
||||
only_latex=only_latex,
|
||||
only_texinfo=only_texinfo,
|
||||
options=opts,
|
||||
images=images,
|
||||
source_code=source_code,
|
||||
html_show_formats=config.plot_html_show_formats,
|
||||
caption=caption)
|
||||
|
||||
total_lines.extend(result.split("\n"))
|
||||
total_lines.extend("\n")
|
||||
|
||||
if total_lines:
|
||||
state_machine.insert_input(total_lines, source=source_file_name)
|
||||
|
||||
# copy image files to builder's output directory, if necessary
|
||||
if not os.path.exists(dest_dir):
|
||||
cbook.mkdirs(dest_dir)
|
||||
|
||||
for code_piece, images in results:
|
||||
for img in images:
|
||||
for fn in img.filenames():
|
||||
destimg = os.path.join(dest_dir, os.path.basename(fn))
|
||||
if fn != destimg:
|
||||
shutil.copyfile(fn, destimg)
|
||||
|
||||
# copy script (if necessary)
|
||||
target_name = os.path.join(dest_dir, output_base + source_ext)
|
||||
with open(target_name, 'w') as f:
|
||||
if source_file_name == rst_file:
|
||||
code_escaped = unescape_doctest(code)
|
||||
else:
|
||||
code_escaped = code
|
||||
f.write(code_escaped)
|
||||
|
||||
return errors
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
*************************************
|
||||
Gaussian process regression tutorial
|
||||
*************************************
|
||||
|
||||
.. ipython:: python
|
||||
|
||||
print "Hello world"
|
||||
X = [[1, 10], [1, 20], [1, -2]]
|
||||
|
||||
We will see in this tutorial the basics for building a 1 dimensional and a 2 dimensional Gaussian process regression model, also known as a kriging model.
|
||||
|
||||
We first import the libraries we will need: ::
|
||||
|
|
|
|||
13
setup.py
13
setup.py
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import os
|
||||
from numpy.distutils.core import Extension, setup
|
||||
from sphinx.setup_command import BuildDoc
|
||||
#from sphinx.setup_command import BuildDoc
|
||||
|
||||
# Version number
|
||||
version = '0.1.3'
|
||||
|
|
@ -19,16 +19,19 @@ setup(name = 'GPy',
|
|||
license = "BSD 3-clause",
|
||||
keywords = "machine-learning gaussian-processes kernels",
|
||||
url = "http://ml.sheffield.ac.uk/GPy/",
|
||||
packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples'],
|
||||
packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples', 'GPy.likelihoods'],
|
||||
package_dir={'GPy': 'GPy'},
|
||||
package_data = {'GPy': ['GPy/examples']},
|
||||
py_modules = ['GPy.__init__'],
|
||||
long_description=read('README.md'),
|
||||
#ext_modules = [Extension(name = 'GPy.kern.lfmUpsilonf2py',
|
||||
# sources = ['GPy/kern/src/lfmUpsilonf2py.f90'])],
|
||||
install_requires=['mock', 'sympy', 'numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1'],
|
||||
setup_requires=['sphinx'],
|
||||
cmdclass = {'build_sphinx': BuildDoc},
|
||||
install_requires=['sympy', 'numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1'],
|
||||
extras_require = {
|
||||
'docs':['Sphinx', 'ipython'],
|
||||
},
|
||||
#setup_requires=['sphinx'],
|
||||
#cmdclass = {'build_sphinx': BuildDoc},
|
||||
classifiers=[
|
||||
"Development Status :: 1 - Alpha",
|
||||
"Topic :: Machine Learning",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue