我试图理解迭代器的实现,在玩源时,我看到了这样的说法:
typedef output_iterator_tag iterator_category;
Run Code Online (Sandbox Code Playgroud)
我不明白这个typedef是如何在课堂上工作的?它提供的副作用是什么?谁能跟我走过这个?
我正在为Linux 2.6.36编写PCI驱动程序.
这是我的代码.我的问题是,如果我想将此驱动程序用于PCIe设备,是否需要进行一些修改?
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <asm-generic/signal.h>
#undef debug
// ATTENTION copied from /uboot_for_mpc/arch/powerpc/include/asm/signal.h
// Maybe it don't work with that
//____________________________________________________________
#define SA_INTERRUPT 0x20000000 /* dummy -- ignored */
#define SA_SHIRQ 0x04000000
//____________________________________________________________
#define pci_module_init pci_register_driver // function is obsoleted
// Hardware specific part
#define MY_VENDOR_ID 0x5333
#define MY_DEVICE_ID 0x8e40
#define MAJOR_NR 240
#define DRIVER_NAME "PCI-Driver"
static unsigned long ioport=0L, iolen=0L, memstart=0L, memlen=0L,flag0,flag1,flag2,temp=0L;
// private_data
struct _instance_data {
int counter; // …Run Code Online (Sandbox Code Playgroud) bash中的典型提示,例如:
PS1="\u@\h:\w\$ "
Run Code Online (Sandbox Code Playgroud)
您可以使用显示后台作业的数量\j,例如:
PS1="\u@\h:\w [\j]\$ "
Run Code Online (Sandbox Code Playgroud)
这是有用的,因为我偶尔会忘记我有一个停止的工作,只有当它从shell手动注销时才会注意到它.
但是,95%的时间,后台作业计数为0并在提示中显示它是多余的.
如何在提示中显示作业计数,但前提是它非零?
我正在使用numpy和以下数据(所有矩阵的所有单元都是非负的):
>>> X1.shape
(59022, 16)
>>> X3.shape
(59022, 84122)
>>> ind.shape
(59022,)
>>> np.max( ind )
59021
>>> np.min( ind )
0
>>> len( set ( ind.tolist() ) )
59022
Run Code Online (Sandbox Code Playgroud)
简而言之,ind只是一种重新排列矩阵中行的方法.问题在于,当重新排列较小阵列(X1)中的行时,根据需要,较大阵列(X2)上的相同操作导致低于某一点的所有行为零.这是我做的:
>>> np.nonzero( np.sum( X3, axis=1 ) )[0].shape
(59022,)
Run Code Online (Sandbox Code Playgroud)
现在让我们看看如果行重新排列会发生什么:
>>> np.nonzero( np.sum( X3[ ind, : ], axis=1 ) )[0].shape
(7966,)
Run Code Online (Sandbox Code Playgroud)
但对于较小的矩阵,一切正常:
>>> np.nonzero( np.sum( X1, axis=1 ) )[0].shape
(59022,)
>>> np.nonzero( np.sum( X1[ ind, : ], axis=1 ) )[0].shape
(59022,)
Run Code Online (Sandbox Code Playgroud)
我猜我可以尝试的一件事是使用稀疏矩阵,但我只是想知道我是否可以使这个东西工作.我有256GB的RAM,所以我不认为内存是一个约束.谢谢你的提示!
C++标准中有什么东西阻止我重载超类的功能吗?
从这对课开始:
class A { // super class
int x;
public:
void foo (int y) {x = y;} // original definition
};
class B : public A { // derived class
int x2;
public:
void foo (int y, int z) {x2 = y + z;} // overloaded
};
Run Code Online (Sandbox Code Playgroud)
我可以B::foo()轻松打电话:
B b;
b.foo (1, 2); // [1]
Run Code Online (Sandbox Code Playgroud)
但如果我试着打电话A::foo()......
B b;
b.foo (12); // [2]
Run Code Online (Sandbox Code Playgroud)
...我收到编译器错误:
test.cpp: In function 'void bar()':
test.cpp:18: error: no matching function for call …Run Code Online (Sandbox Code Playgroud) 我正在"玩"C++中的虚拟继承,我想知道如何布置类对象.我有这三个班:
class A {
private:
int a;
public:
A() {this->a = 47;}
virtual void setInt(int x) {this->a = x;}
virtual int getInt() {return this->a;}
~A() {this->a = 0;}
};
class B {
private:
int b;
public:
B() {b = 48;}
virtual void setInt(int x) {this->b = x;}
virtual int getInt() {return this->b;}
~B() {b = 0;}
};
class C : public A, public B {
private:
int c;
public:
C() {c = 49;}
virtual void setInt(int x) {this->c = x;} …Run Code Online (Sandbox Code Playgroud) 所以,假设我有一个包含2个进程的MPI程序,排名为0,排名为1.
int i[20], j[20], temp, size;
Run Code Online (Sandbox Code Playgroud)
在排名0的过程中,我有
for(temp=0; temp<20; temp++)
i[temp] = temp;
MPI_Send(i, 15, MPI_INT, 1, 1, MPI_COMM_WORLD);
Run Code Online (Sandbox Code Playgroud)
然后让我们说排名为1的过程就可以了
// At this point, size is declared, but not assigned any value.
MPI_Recv(j,size, MPI_INT, 0, 1, MPI_COMM_WORLD):
cout << "I have received " << size << " elements" ;
Run Code Online (Sandbox Code Playgroud)
我的问题是,在上述声明中,是否需要声明"大小"?或者MPI_Recv以某种方式"知道"它正在接收15个元素,并自动设置size = 15?如果未定义大小,代码会发生什么?
基本上,我的问题是,我向不同级别的处理器发送不同数量的元素,所有消息都来自0级.我想知道我是否应该首先发送大小,然后准备处理器以接收那么多元素,或者如果我可以发送数组,那么进程会自动从那里选择大小.
我们在LCD.c中有这个声明:
unsigned char LCD[8][64] = {((unsigned char) 0)};
Run Code Online (Sandbox Code Playgroud)
在LCD.h中我们希望有类似的东西:
extern unsigned char LCD[][];
Run Code Online (Sandbox Code Playgroud)
我们收到此错误:
Error[Pe098]: an array may not have elements of this type
Run Code Online (Sandbox Code Playgroud) 假设我有
Eigen::VectorXd x; //{1,2,3,4,5,6,7,8}
Run Code Online (Sandbox Code Playgroud)
和
Eigen::VectorXd ind_vec; //{0,2,4,5}
Run Code Online (Sandbox Code Playgroud)
有没有办法轻松提取ind_vecx 的元素?
就像是:
x.extract(ind_vec) returning {1, 3, 5, 6}
Run Code Online (Sandbox Code Playgroud)