小编Pip*_*ppi的帖子

Pycuda中memcpy_htod和to_gpu的区别?

我正在学习PyCUDA,在浏览pycuda.gpuarray的文档时,我对pycuda.driver.memcpy_htod(也是_dtoh)和pycuda.gpuarray.to_gpu(也是get)函数之间的区别感到困惑.根据gpuarray 文档,.get().

例如,将self的内容传输到数组或新分配的numpy.ndarray.如果给出了数组,则它必须具有正确的大小(不一定是形状)和dtype.如果未给出,则pagelocked指定是否为新阵列分配页锁定.

这是说.get()的实现方式与pycuda.driver.memcpy_dtoh完全相同吗?不知何故,我认为我错误地解释了它.

cuda gpu numpy pycuda

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

在Python中使用reshape重塑数组

我有一个如下所示的数组:

array([[0, 0, 0, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [2, 2, 2, 2, 2, 2, 2, 2],
       [3, 3, 3, 3, 3, 3, 3, 3],
       [4, 4, 4, 4, 4, 4, 4, 4],
       [5, 5, 5, 5, 5, 5, 5, 5],
       [6, 6, 6, 6, 6, 6, 6, 6],
       [7, 7, 7, 7, 7, 7, 7, 7]])
Run Code Online (Sandbox Code Playgroud)

如何使用重塑将其分成4个卡盘,使其看起来像

array([[[0, 0, 0, 0],  
       [1, 1, 1, 1],  
       [2, 2, 2, 2],  
       [3, 3, …
Run Code Online (Sandbox Code Playgroud)

python numpy shape reshape

3
推荐指数
2
解决办法
9884
查看次数

reactor.connectTCP可以在twisted.run扭曲的python之后发生吗?

我想在反应堆运行后添加更多的协议和工厂.我找不到说这是允许的文件.当我在reactor.connectTCP之前创建reactor.run时,程序在工厂中挂起buildProtocol.在reactor.run之后是否可以将reactor.connectTCP添加到反应器中?

python twisted twisted.internet

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

Fortran Derived Type:

I am confused by the following example:

TYPE :: car 
    real :: x,  u ! position, velocity
    real :: y,  v ! 
    real :: z,  w !  
    real,dimension(3) :: uvw_0    ! initial uvw
END TYPE

TYPE (car), pointer:: mercedes
TYPE (car), DIMENSION(m,n,q,r), TARGET :: mercedes_ay 
Run Code Online (Sandbox Code Playgroud)

It looks like an implementation of object, but what does

TYPE (car), DIMENSION(m,n,q,r), TARGET :: mercedes_ay 
Run Code Online (Sandbox Code Playgroud)

关于TYPE(car) - DIMENSION(m,n,q,r)引用了哪些变量?mercedes_ay(1,1,1,1)是什么意思?梅赛德斯(1,1,1,1)是什么意思?

object fortran90 derived-types

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

如何为一组对重载比较运算符?

如何重载并将<(小于)比较器传递给一组整数对?这是我目前的代码:

class A{
public:
    typedef std::pair<int, int> pair_type;  

    bool operator<(const pair_type& a, const pair_type& b){ 
        if (a.first < b.first) return true;
        else if ( (a.first == b.first) && (a.second < b.second) ) return true;
        else return false;
    }

private:
    std::set< pair_type > edge_;
};
Run Code Online (Sandbox Code Playgroud)

如果我尝试编译此代码,那么我会收到以下错误:

error: 'bool A::operator<(const pair_type&, const pair_type&)' must take exactly one argument
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

c++ overloading set comparator std-pair

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

可以在子例程的主体中取消分配和分配Fortran子例程的输入参数吗?

更新:我修改过的代码如下所示:

program run_module_test
    use module_test
    implicit none   

    TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)

    call update(xyzArray)
    write(6,*)'xyzArray',xyzArray

end program run_module_test

module module_test
    implicit none

    TYPE :: newXYZ
        real(4) :: x, u
        real(4) :: y, v
        real(4) :: z, w
        real(4),dimension(3) :: uvw     
    END TYPE

    integer(4) :: shape = 3

contains

    subroutine update(xyzArray)

    integer(4) :: i
    TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)
    allocate( xyzArray(shape) ) 

    do i = 1, shape
        xyzArray(i)%x = 0
        xyzArray(i)%y = 0
        xyzArray(i)%z = 0
        xyzArray(i)%u = 0
        xyzArray(i)%v = …
Run Code Online (Sandbox Code Playgroud)

arrays fortran allocation subroutine

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

来自Git或编辑器的奇怪行为:在结账时添加了符号?

我在分支v上,然后我切换到主分支,然后切换回分支v.当我再次编译时,编译失败,因为我的代码中出现了一个奇怪的符号:

在此输入图像描述

我正在使用OS X Lion和textWrangler的最新版本,我很确定我没有偶然添加它.这是Git或textWrangler的错吗?

UPDATE

合并后添加了一些git:

在此输入图像描述

git

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

如果一个数组在循环中重新分配并且从未在Fortran中释放,会发生什么?

我想知道以下代码对内存的作用:

program A

While (t < large number)
 allocate(a)
 ...

end program
Run Code Online (Sandbox Code Playgroud)

"allocate(a)"是指在每次迭代时引用相同的内存位置,如果在程序结束之前没有使用deallocate(a),是否存在内存泄漏?

fortran

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

函数内的STL容器何时将其数据保存在C++中?

我有一个函数,可以在向量容器中存储素数列表.在每次调用函数时,容器大小保持不变或增长.

bool prime(int n)
{
    ...
    static vector<int> v;
    vector <int>::iterator Iter;
    ...
    v.push_back(n);
}


int main()
{
    int num = 0;
    for (int i = 2; i <= n; ++i) {
      if (prime(i)) {
        ++num;
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么存储在示例中有效.这个程序是否依赖?

c++ containers vector

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

如何编写一个在输入文件列表上运行的python脚本?

我有一个程序,它接受一个输入文件:

python subprogram.py < input.txt > out.txt
Run Code Online (Sandbox Code Playgroud)

如果我有许多输入文件,我如何编写一个python程序在这些输入上运行并产生一个输出?我相信该程序应该像:

python program.py < input_1.txt input_2.txt > out.txt 
Run Code Online (Sandbox Code Playgroud)

程序本身应该类似于:

from subprogram import MyClass
import sys

if __name__ == '__main__':
    myclass = MyClass()
    myclass.run()
Run Code Online (Sandbox Code Playgroud)

python import parsing class input

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