无处不在,我为这个功能得到了很大的成果......它应该很简单,但我现在看不到它.
double prob_calculator_t::pimpl_t::B_full_term() const
{
double result = 0.0;
for (uint32_t j=0, j_end=U; j<j_end; j++)
{
uint32_t inhabited_columns = doc->row_sums[j];
// DEBUG
cout << "inhabited_columns: " << inhabited_columns << endl;
cout << "log_of_sum[j]: " << log_of_sum[j] << endl;
cout << "sum_of_log[j]: " << sum_of_log[j] << endl;
// end DEBUG
result += ( -inhabited_columns * log( log_of_sum[j] ) + sum_of_log[ j ] );
cout << "result: " << result << endl;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
跟踪在哪里:
inhabited_columns: 1
log_of_sum[j]: 110.56
sum_of_log[j]: …Run Code Online (Sandbox Code Playgroud) 由于某种原因,我有一个无限期失败的事务,我想在里面使用跟踪指令.例如,要在执行此片段中的事务之前打印MVar的状态:
data_out <- atomically $ do
rtg_state <- takeTMVar ready_to_go
JobDescr hashid url <- T.readTBChan next_job_descr
case rtg_state of
Ready_RTG n -> do
putTMVar ready_to_go $ Processing_RTG n
putTMVar start_harvester_browser hashid
putTMVar next_test_url_to_check_chan hashid
putTMVar next_harvest_url hashid
return (n,hashid,url)
_ -> retry
Run Code Online (Sandbox Code Playgroud)
这会使程序出现段错误还是错过行为?
目前我正在使用ihaskell来了解一些库.IHaskell仍然是危险的,我做不到:
-- This doesn't work: ":ext PackageImports", the kernel hangs
-- This doesn't work: "{-# LANGUAGE PackageImports #-}", the kernel hangs
import Codec.Crypto.RSA.Pure
import qualified "crypto-api" Crypto.Random as CR
import Control.Monad.CryptoRandom
Run Code Online (Sandbox Code Playgroud)
没有"PackageImports",我收到一条错误消息:
Ambiguous interface for ‘Crypto.Random’: it was found in multiple packages: crypto-api-0.13.2 cryptonite-0.7
Run Code Online (Sandbox Code Playgroud)
我的问题是,ghci中是否有一个冒号命令可以让我隐藏密码包?
我在Haskell中使用ReadP为文件中的数字列表做了一个非常简单的解析器.它工作,但它很慢......这种类型的解析器的这种正常行为还是我做错了什么?
import Text.ParserCombinators.ReadP
import qualified Data.IntSet as IntSet
import Data.Char
setsReader :: ReadP [ IntSet.IntSet ]
setsReader =
setReader `sepBy` ( char '\n' )
innocentWhitespace :: ReadP ()
innocentWhitespace =
skipMany $ (char ' ') <++ (char '\t' )
setReader :: ReadP IntSet.IntSet
setReader = do
innocentWhitespace
int_list <- integerReader `sepBy1` innocentWhitespace
innocentWhitespace
return $ IntSet.fromList int_list
integerReader :: ReadP Int
integerReader = do
digits <- many1 $ satisfy isDigit
return $ read digits
readClusters:: String -> IO [ IntSet.IntSet …Run Code Online (Sandbox Code Playgroud) 我想在C/C++中为numpy数组分配数字,并将它们作为numpy数组传递给python.我可以使用PyArray_SimpleNewFromData.
问题是我还想注册一个当numpy数组引用计数器达到零时应该从Python调用的函数,这将调用C端的一些析构函数语义...这是我需要的一个伪示例:
float* arr; PyObject* np_arr; void (*destructor)(float* arr);
// ... C-allocate array on arr, ...
// ...
// ... initialize destructor with some suitable value, and then:
np_arr = /* ... create the array to wrap arr,
and to use destructor on some meaningful way ... */
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法吗?
我在Haskell中实现了Smith-Waterman算法,但是我遇到了运行时错误:<<loop>>
在我的实现中,我正在尝试使用Haskell的惰性,所以我使用不可变数组resarray来存储延迟和递归存根,它们也引用数组本身(在依赖链中resarray取决于zippedList哪个取决于cellDef哪个取决于哪个依赖于cell哪个on resarray ).每个单元格指的是索引较小的单元格,因此计算应该是可行的...尽管它不是那样的.
作为概念证明,我在ghci中尝试了以下内容:
let arr = listArray (0,3) [0, arr ! 0, arr ! 1, arr ! 2 ]
Run Code Online (Sandbox Code Playgroud)
它起作用了.然而,由于某些未知原因,我的计算时间越长越严格.
这是我的代码(完整版本,连同测试脚本,在这里):
buildSWArray::
WordSequence ->
WordSequence ->
SWMatrix
buildSWArray ws1 ws2 = let
rows = arrLen ws1
cols = arrLen ws2
im = matToLinearIndex rows cols
mi = linToMatIndex rows cols
totsize = rows * cols
ixarr = [0 .. (totsize-1)]
cell i j …Run Code Online (Sandbox Code Playgroud) 我有一个异类型列表(或者至少是我的想法):
data Nul
data Bits b otherBits where
BitsLst :: b -> otherBits -> Bits b otherBits
NoMoreBits :: Bits b Nul
Run Code Online (Sandbox Code Playgroud)
现在,给定一个输入类型b,我想通过所有Bits类型的板b并总结它们,忽略其他类型的板b' /= b:
class Monoid r => EncodeBit b r | b -> r where
encodeBit :: b -> r
class AbstractFoldable aMulti r where
manyFold :: r -> aMulti -> r
instance (EncodeBit b r, AbstractFoldable otherBits r) =>
AbstractFoldable (Bits b otherBits ) r where
manyFold r0 (BitsLst …Run Code Online (Sandbox Code Playgroud) 我想使用Kmett的镜头库来访问特定键下的(键,值)列表的元素.换句话说,我想用更惯用的东西替换这个代码,也许更短:
type Headers = [ (ByteString, ByteString) ]
headerLens ::
Functor f =>
ByteString ->
(Maybe ByteString -> f (Maybe ByteString)) ->
Headers ->
f Headers
headerLens header_name f headers
| old_header_value <- fetchHeader headers header_name = fmap
(\ new_header_value ->
replaceHeaderValue
headers
header_name
new_header_value
)
(f old_header_value )
Run Code Online (Sandbox Code Playgroud)
支持函数的定义如下:
-- | Looks for a given header and returns the value, if any
fetchHeader :: Headers -> ByteString -> Maybe ByteString
fetchHeader headers header_name =
snd <$> find …Run Code Online (Sandbox Code Playgroud) 对不起,如果问题看起来有点微不足道......那不适合我.我很乐意写下以下的monad:
type SB i a = ReaderT ( AlgRO i ) (State ( AlgState i ) ) a
Run Code Online (Sandbox Code Playgroud)
这是一个表现良好的monad.ReaderT是monad变换器,State是状态monad,AlgRO和AlgState分别是i中用于可变和只读状态的参数化数据类型.现在,如果我想用newtype制作一个整洁的monad变换器,就像这样:
newtype SbT m i a = SbT {
runSbT:: m ( SB i a )
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?我甚至无法将绑定方法(Monad类型组合)放在一起,更不用说"MonadTrans"的"提升"...我想自动推导可能有所帮助,但我想了解它在这种情况下是如何工作的.
提前致谢.
浏览器可以通过SOCKS 5代理DNS请求.我不明白这个过程是如何工作的.
如我错了请纠正我.在正常的DNS操作中,程序通过其操作系统进行DNS解析,而操作系统又配置为访问特定的DNS服务器并在那里进行查询.因此,在正常操作中,浏览器不应该自己通过网络进行DNS查询.
现在,使用SOCKS代理,浏览器需要自己进行查询.浏览器如何知道代理隧道另一端将存在哪个DNS服务器?