how can we estimate memory requirements for nchoosek?

조회 수: 1 (최근 30일)
Andy
Andy 2018년 7월 29일
편집: dpb 2018년 8월 4일
nchoosek is a memory intensive command ... to the point it can easily kneel down your system ... or get something back as the below:
Error using nchoosek>combs (line 175) Out of memory. Type HELP MEMORY for your options.
Error in nchoosek>combs (line 174) Q = combs(v(k+1:n),m-1);
Error in nchoosek>combs (line 174) Q = combs(v(k+1:n),m-1);
Error in nchoosek (line 132) c = combs(v,k);
Error in NChooseKR (line 7) parfor i = kRange
  댓글 수: 1
Stephen23
Stephen23 2018년 7월 29일
편집: Stephen23 2018년 7월 29일
Original question:
"how can we estimate memory requirements for nchoosek?"
Number of combinations * number of elements per combination * bytes per element

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2018년 7월 29일
>> help nchoosek
nchoosek Binomial coefficient or all combinations.
...
nchoosek(V,K) where V is a vector of length N, produces a matrix
with N!/K!(N-K)! rows and K columns. Each row of the result has K of
the elements in the vector V. This syntax is only practical for
situations where N is less than about 15.
...
TMW writes documentation for a reason...
  댓글 수: 4
Andy
Andy 2018년 8월 4일
편집: dpb 2018년 8월 4일
Nonetheless in our case there ARE many equal sequences of values so compression could make sense. But I don't see anything baked in that could do this, is it?
dpb
dpb 2018년 8월 4일
편집: dpb 2018년 8월 4일
>> nchoosek(int16(1:5),3)
ans =
10×3 int16 matrix
...
>> whos ans
Name Size Bytes Class Attributes
ans 10x3 60 int16
>> nchoosek((1:5),3)
ans =
...
>> whos ans
Name Size Bytes Class Attributes
ans 10x3 240 double
>>
Is 4:1; uint8 would be 8:1 and handle values up to 255; as implemented it may require double() first I don't know and there's still the issue of the specific recursive algorithm used that probably could be improved on.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by