不清楚C ++返回类型为python表达式

时间:2018-08-06 08:38:03

标签: python c++

我试图了解C ++与python的接口:

第170行的g2p.py中有以下代码(为清楚起见已清除):

nBest = translator.nBestInit(left)
logLik, result = translator.nBestNext(nBest)
posterior = math.exp(logLik - nBest.logLikTotal) // ***This is the line in question***
print('%f' % (posterior))

使用第759行的sequitur.py

def nBestInit(self, left):
    left = self.sequitur.leftInventory.parse(left)
    result = self.translator.nBestInit(left)
    result.thisown = True
    result.logLikBest = self.translator.nBestBestLogLik(result)
    result.logLikTotal = self.translator.nBestTotalLogLik(result)
    return result

def nBestNext(self, nBestContext):
    logLik, joint = self.translator.nBestNext(nBestContext)
    joint = self.unpackJoint(joint)
    left, right = self.jointToLeftRight(joint)
    return logLik, right

在此脚本中,LogLik在Probability.hh和翻译器函数中定义  在Translation.cc中。 nBestTotalLogLiknBestNext都返回类类型LogProbabilityLogProbability有各种重载,均不会返回数值类型,例如:

inline LogProbability operator-(const LogProbability &lhs, const LogProbability &rhs)

我的问题是,在math.exp(logLik - nBest.logLikTotal)行中,如何将表达式logLik - nBest.logLikTotal评估为数值以供exp()处理?

0 个答案:

没有答案
相关问题