python表达式的c++返回类型不明确

2024-04-20 02:07:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解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和translator函数中定义的 在Translation.cc中。nBestTotalLogLik&;nBestNext都返回类类型LogProbabilityLogProbability有各种重载,其中非重载返回数字类型,例如:

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

我的问题是,在第math.exp(logLik - nBest.logLikTotal)行中,表达式logLik - nBest.logLikTotal如何计算为exp()要处理的数值?你知道吗


Tags: pyselfmathresultlefttranslatorjointnbest