小编dhu*_*dhu的帖子

可以使用arc diff来排​​除Phabricator中的某些文件吗?

某些C++文件是系统生成的,无需查看.此外,这些文件相当大,有时会导致"请求超出容量限制".查看它的更好地方是比较新架构和旧架构文件.这些文件是提交的一部分,所以我不想对它们使用.gitignore.

这是我在互联网上找到的关于此的另一篇文章,但它没有帮助.http://www.quora.com/Can-I-use-arc-diff-to-exclude-some-files-in-Phabricator

git phabricator

7
推荐指数
1
解决办法
5252
查看次数

如何编写代码在C++中进行条件模板实例化

我正在编写一个在size_t上参数化的类模板,

template<size_t k>
class MyClass {...}
Run Code Online (Sandbox Code Playgroud)

参数k应该真的小于10,在这种情况下,如果它超出了这个范围,我希望它不能编译.我怎么能在C++ 11及更高版本中做到这一点?

MyClass<1> instance1; // ok
MyClass<2> instance2; // ok
MyClass<100> instance100; // fail to compile
Run Code Online (Sandbox Code Playgroud)

c++ templates

4
推荐指数
2
解决办法
180
查看次数

如何在 Haskell 中对这种递归结构进行建模?

我正在尝试通过 Haskell 类型系统对 kdb/q“原子和列表”进行建模。

在 kdb/q 中,所有数据都是由原子构建的。原子是特定数据类型的不可约值。Int、boolean 和 char 是原子的例子。列表是从原子构建的有序集合。由于 q 是一种向量语言,大多数内置操作都是原子的,因此它会递归到参数结构中,直到到达原子。

例如:

(1;2;3) 是一个简单的整数列表 1, 2, 3

(1.0;2;(3;4;5)) 是 1.0(float), 2(int) 的一般列表,以及简单的 int 列表 (3;4;5)

neg 是一个否定一个数字的函数。例如:

负 1 产生 -1

负 -1.0 产生 1f

负 (1.0;2;(3;4;5)) 产生 (-1f;-2;(-3;-4;-5))。

这就是激励我尝试在 Haskell 类型中模拟这种行为的原因。数据类型应该由原子类型和一个列表组成。

以下是我目前所拥有的简化版本。我还进一步尝试使其成为可折叠和可遍历的实例。

data Atom = I Int
          | C Char
          | D Double 
          deriving Show

data Q a = QAtom a 
         | QList [Q a]
         deriving Show

instance Functor Q where
    fmap f (QAtom a) = QAtom (f …
Run Code Online (Sandbox Code Playgroud)

haskell algebraic-data-types kdb traversable

2
推荐指数
1
解决办法
156
查看次数

为什么本机 python 列表上的 for 循环比 numpy 数组上的 for 循环快

我正在阅读介绍高性能 Python 中的numpy 的章节,并在我自己的计算机上使用代码。偶然地,我用 for 循环运行了 numpy 版本,发现与原生 python 循环相比,结果出奇地慢。

代码的简化版本如下,其中我定义了一个带有 0 的二维数组 X 和另一个带有 1 的二维数组 Y,然后重复将 Y 添加到 X,概念上为 X += Y。

import time
import numpy as np

grid_shape = (1024, 1024)

def simple_loop_comparison():
    xmax, ymax = grid_shape

    py_grid = [[0]*ymax for x in range(xmax)]
    py_ones = [[1]*ymax for x in range(xmax)]

    np_grid = np.zeros(grid_shape)
    np_ones = np.ones(grid_shape)

    def add_with_loop(grid, add_grid, xmax, ymax):
        for x in range(xmax):
            for y in range(ymax):
                grid[x][y] += add_grid[x][y]

    repeat = …
Run Code Online (Sandbox Code Playgroud)

python memory performance for-loop numpy

1
推荐指数
1
解决办法
2670
查看次数

使用 C++ 中的 RAII 在线程包装类中移动语义

我试图让一个围绕 std::thread 的 RAII 包装类在 C++ 中工作。

#include <iostream>
#include <thread>
#include <vector>

using std::cout;
using std::endl;

void threadFunction()
{
    for (int i = 0; i < 20; ++i) {
        cout << "thread function pointer executing..." << i << endl;
    }
}



// RAII wrapper that supports automatic join
class ThreadJoinRAII
{
    std::thread thread_;
public:
    ThreadJoinRAII(std::thread&& t):thread_(std::move(t)) 
    // ThreadJoinRAII()
    {
        cout << "ThreadJoinRAII ctor" << endl;
    }

    //ThreadJoinRAII(const ThreadJoinRAII& other) = delete;
    //ThreadJoinRAII& operator=(const ThreadJoinRAII& other) = delete;

    //ThreadJoinRAII(ThreadJoinRAII&& other):thread_(std::move(other.thread_)) …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading move most-vexing-parse

1
推荐指数
1
解决办法
81
查看次数