G*****h 发帖数: 33134 | 1 用 C 吧
这俩文件不大呀,整数的话,A 80MB B 160MB 空间就都读内存里了
然后就傻 loop 也不会花太久 |
|
o**n 发帖数: 1249 | 2 借机问一个问题。我有一个较大的二维矩阵,是(x,y)坐标矩阵,float type,x,y都没
有规则顺序。我再建一个x,y mesh grid的矩阵,间距是均匀的或有一定规律比如线性
增加等,要把前面那个乱的(x,y)矩阵放入grid里,会有多个(x,y)落在同一个grid的情
况,把每个grid中有的(x,y)在原矩阵中的行列index记录下来。其实就是个二维monte
carlo的东西。我现在也是用loop硬来,目前用matlab,用C肯定快一些。数组也不是特
别大,run一次大概几分钟时间,但我要做很多次这个事情,想请教大家更好的方法。 |
|
y***d 发帖数: 2330 | 3 你是说 loop grid 花时间?弄个 dirty set 就行了吧 ...都不用,算 xy 的 grid 时
候记录 index 就成了?
monte |
|
o**n 发帖数: 1249 | 4 我去查查dirty set。
我没太搞懂你说的第二个
我现在是两层loop grid,用matlab的矩阵比较把index搞出来,类似
for jx=1:nx
ix = xt>x(jx) & xt<=x(jx)+dx;
for jy=1:ny
iy = yt>y(jy) & yt<=y(jy)+dy;
ixy = ix&iy;
#use ixy to process data ...
end
end
xt,yt是(x,y)坐标的二维数据nx*ny,其实是我有一个矩阵数据A,每个数据点对应一个
(x,y)坐标,A(i,j) -> (x,y)。上面code中的x,y是新建的均匀grid,每个间距dx,dy。
我不太理解你说的意思。 |
|
o**n 发帖数: 1249 | 5 我猜如果我用matlab里矩阵的比较时,比如A(i,j)>B(i,j)返回所有满足条件的数据行
列index,应该用的是很优化的算发,我的理解是matlab建议用户尽量用矩阵形式避免
用loop就是他内部优化的结果。但我要对每个grid点和原数据都做一次这个比较,所以
费时,请参见我贴出的code。 |
|
G*****7 发帖数: 1759 | 6 i m gonna repeat what ppl said in programming:
1) if you have to explicitly do for-loop and linearly search for the
interval membership, use mex to embed c/cpp code in matlab.
2) if you got time, check out the search acceleration data structures
provided by, say cgal, such as segment tree, and write mex+cpp code that
takes advantage of that. |
|
c********e 发帖数: 383 | 7 dont know how smart compiler is:
for example:
my_map::iter iter;
for (iter = map.upper_bound(key);
iter != map.lower_bound (key);
++iter)
{
//traverse element, all const/irrelavant func to map
}
will the lower_bound call be optimized when loop-invariant is turned on?
what about this case?
my_map::iter iter;
for (iter = map.upper_bound(key);
iter != map.lower_bound (key); |
|
s*******d 发帖数: 59 | 8 single loop's performance is worse |
|
p*******5 发帖数: 14 | 9 how to output all permutations for a given list?
w/o recursion.
list length is not known so nest loop also not possible. |
|
g*******y 发帖数: 1930 | 10 there's a way to implement N nested loops. It's been discussed before.
The idea is to use an array a[N],
for(int i0=0;i0!=a0;i0++){
for(int i1=0;i1!=a1;i1++){
...
}
}
is equivalent to:
int b[N]; // b[i] can be 0,1,...a[i]-1
do{
//do something
int i;
for(i=0;i!=N;i++){
if(b[i] == a[i]-1){
b[i] == 0;
}else{
b[i]++;break;
}
if(i==N) break;
}while(1); |
|
r****x 发帖数: 3613 | 11 sorry, my problem is I try to load files with loop, each file contains diffe
rent size of array. I need to analyse each file then proceed to next one. wh
en the first array is finished, the 2nd array just adds into the first one,
until the dimensions mismatch. Do you have any solution to this problem? |
|
r****x 发帖数: 3613 | 12 matlab, reading txt files, data seperated by column, I have to use regexp re
ad data. One major problem is I don't know how many rows in each file, thus
I can only use 'while' to read one file. To loop these files, the rows are a
dded one after another, don't know when to stop. |
|
r****t 发帖数: 10904 | 13 有没有比较巧妙的 macro 可以 unroll for loop 呢? compiler #pragma unroll 失
败了,手工 unroll 发现很值得。
我写了这个,但是编译的时候错误是:
error: identifier "forloop" is undefined
#define forloop(n) if (n>0) do_something_with_n(n) ; forloop(n-1) |
|
d****p 发帖数: 685 | 14 You can do that with boost's BOOST_PP_REPEAT in boost preprocessor lib.
sth like
#define RUN_FUNC_IN_LOOP(unused, loopCount, funcToRun) funcToRun(n);
where funcToRun looks like void funcToRun(int n)
So the loop is BOOST_PP_REPEAT(1000, RUN_FUNC_IN_LOOP, yourFunc)
But it is a bad idea since the code is unreadable to most people.And if the
n is large ... |
|
r****t 发帖数: 10904 | 15 啊。。cpp 原来不让 recusion 的?cpp 不够灵活,template class 有内存上的问题
,写起
来不容易, compiler (nvcc) 还不一定支持。搜 "preprocessor loop" 很多都指向
boost 这个 preprossesor, 不过这部分程序没法用 boost, 看来还是用个 template
engine 来生成代码好了。
this,
provides
if
like:
and
variables. |
|
w*********s 发帖数: 277 | 16 编程新手,请不吝赐教!
for(unsigned int idx = 9; idx >= 0; idx--) {
cout << "index is " << idx << endl;
}
这么简单的都没调通,很郁闷。这个loop不能terminate,即使idx已经是负数了。
最原始的本意是作为vector的index,所以用的vector::size_type,发现不能
terminate,所以就换成unsigned int试试,仍然不terminate。
谢谢指点! |
|
z****e 发帖数: 2024 | 17 *p1 step size 1, *p2 step size 2, to find node where the two meet.
then, set p1 to head, and drive p1 and p2 to move on 1 step each time
simultaneously.
when p1 meet p2 again, that's the starting point of the loop.
用同余可以证明。 |
|
i*****s 发帖数: 438 | 18 I was reading CSAPP2 and couldn't get this example
(regarding singed/unsigned integer):
#define DELTA sizeof(int)
int i;
for (i = CNT; i-DELTA >= 0; i-= DELTA)
. . .
the for() loop will not stop?
Thanks. |
|
G*****7 发帖数: 1759 | 19 1) sort a and b.
2) dont do loops in matlab. mex-ize the code. |
|
t********e 发帖数: 1169 | 20 1) 不要用matlab写400b的loop...
2)20m lines完全可以全部放入内存,用hash都行了, 40m的运算量 |
|
p*****2 发帖数: 21240 | 21 这个loop用C/Java等等很容易写。scala就不行了,只能需求非for的方法了。
for (int i = 1; i <= n; i *= m) |
|
A*******t 发帖数: 443 | 22 haskell里面就没有for loop这个东西 |
|
p*****2 发帖数: 21240 | 23
如果用纯FP来写,感觉开发效率也未必高。比如没有loop,需要recursion,而且为了
防止stack overflow要写尾递归,开发效率应该就降低不少才对。感觉混合写比较好。
scala确实代码量下降,相应的bug也会减少。这个确实是个大优势。 |
|
o******n 发帖数: 511 | 24 谢谢楼上各位,我周末忘记来回帖了。我后来用了二楼链接里一个例子的办法,绕过前
30000个文件再执行hmmbuild命令,就好了。
我本来的问题是,文件名是bactNOG00001,bactNOG00002等等,怎么在for loop里在这
些文件名里用上类似i=1,i=i+1的计数器。6,7楼的回复就是这个意思。:) |
|
d********t 发帖数: 9628 | 25 其实是有三层的dict要全部print出来,似乎一层层loop太慢。 |
|
|
W***o 发帖数: 6519 | 27 一方面我觉得是因为loopback 的strong loop 是个商业公司,免费用户不喜欢 |
|
T******7 发帖数: 1419 | 28 spring 是一个event loop一直在跑么?然后处理各种event? |
|
b***e 发帖数: 1419 | 29 不是。if you want single thread event loop model, take a look at vert.x. |
|
c******f 发帖数: 243 | 30 你说的是netty吧, 一个event loop |
|
w*****n 发帖数: 94 | 31 I have an iso file, and would like to read its contend without
recording it to CDR. In linux, it is
mount -o loop
But, i dont know how to do it on solaris 8 for intel.
Found the answer from deja.com:
# lofiadm -a /home/mike_s/RH6.0/sparc.iso
/dev/lofi/1
# mount -F hsfs -o ro /dev/lofi/1 /mnt |
|
b***l 发帖数: 15 | 32 I used this approach in a while loop to do the same thing. But I am wondering
if there is a short cut other than this way.
Thanks any way.
large,
anything |
|
l******g 发帖数: 1145 | 33 用过Fisher的,不错,叫Combi loop
现在都tip过一下火直接挑⋯⋯ |
|
w*********e 发帖数: 286 | 34 如题,在做一个筛选,需要从大量数据中找到一些outlier,用matlab写了一个for loop
,每次把找到的sample写进一个vector,有没有比较方便的函数?现在是先定义一个初
始变量为[],然后concatenate一下,总感觉效率不高,速度太慢。。。。 |
|
e*********6 发帖数: 3453 | 35 你说慢在哪里?从算法看应该是O(n)应该就是最好了。如果觉得要反复擦写内存,就数
数有几个outliner,再开辟空间,再过一次
loop |
|
s******s 发帖数: 13035 | 36 不用matlab。不过outlier比较多的话,这种append操作很慢的。
一般是给个大数组,填满了就扩一倍继续
loop |
|
f*******9 发帖数: 74 | 37 你这个问题简单得很,根本就不是loop的问题,就是一个逻辑索引的技巧而已,如3楼
所指,newVector = data(indexOfOutliers)。建议你好好学习一下Matlab的帮助文档。
话说回来,Matlab的向量化(vectorized)操作效率很高,比C的for循环还要快。而在
Matlab里面用for循环的话是最慢的。R和Matlab相似。 |
|
|
g**s 发帖数: 79 | 39 我现在要通过C 程序实现Discrete Costas Loop.
我看懂了数学模型,但是还是不知道怎样实现,参数也不知道怎么选取。
谁有好的资料可以推荐一下吗? |
|
x*****d 发帖数: 427 | 40 what is a loop? what is a group? |
|
l*******s 发帖数: 65 | 41 【 以下文字转载自 Chemistry 讨论区 】
发信人: lenovodos (lenovodos), 信区: Chemistry
标 题: 测magnetic hysteresis loop的仪器在哪儿买?
发信站: BBS 未名空间站 (Sun Jan 11 12:30:57 2009)
主要是测magnetic nanoparticles or magnetic thin film,
有没有人知道这方面信息的, 谢谢? |
|
w****1 发帖数: 4931 | 42 loop quantum gravity is nonsense.:)) |
|
m**z 发帖数: 5 | 43 Who happens to have experience in loop formula or function in Excel or STAT?
I have a very large data set, need to construct 3 new variables using Excel
or STAT. The data is attached (the variables with empty cells are
constructed, and the values to be calculated for each Venture_firm).Please
help me out asap. Your suggestion or any input will be much appreciated. |
|
o******6 发帖数: 538 | 44 ☆─────────────────────────────────────☆
zhongdianshi (brb) 于 (Tue Sep 1 14:34:52 2009, 美东) 提到:
我从别人那里拿到这样一个CODE:
do i = 1 to 10;
if
sterkm(i) ='46' then do;
dxmonth = modx(i);
dxyear = yrdx(i);
i= 10; /*take first breast cancer dx; end loop*/
end;
end;
其中的i=10是什么意思?如果没有这个,好象很容易理解。
我发信去问,解释如下:还是不明白,请赐教,多谢!!!
1。In this example, you're looking for the first diagnosis with breast
cancer, as explained in the comment /*take first breast |
|
r*****n 发帖数: 92 | 45 Can you loop outside data or proc steps?
Namely, can you repeat the same data or proc step
based on some parameters?
Thanks! |
|
S******y 发帖数: 1123 | 46 I have a sorted data in R. I am trying to cut tiles/deciles based on
cumulative weights.
My code is below -- but how can I get rid of this loop (which might not be a
good coding practice here) ?
Thanks.
#------------------------------------------
#dat - R data frame (already sorted by variable of interest)
#n - number of obs
#tile - a vector of length n showing which tile the obs belongs to
#n_tile - number of tiles (i.e. deciles if it is 10)
#--------------------------------------
#R code -- |
|