Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtools commands are limited by matsize #24

Open
mcaceresb opened this issue Nov 1, 2017 · 2 comments
Open

Gtools commands are limited by matsize #24

mcaceresb opened this issue Nov 1, 2017 · 2 comments

Comments

@mcaceresb
Copy link
Owner

mcaceresb commented Nov 1, 2017

The maximum number of variables that can be passed to gtools commands is the maximum value of matsize in the user's system.

disp c(matsize)

Will show the user how many variables can be used with gtools. This limitation is due to the way Stata's C API is designed. I use matrices to pass various necessary information to and from C, so this limitation will almost certainly not change unless the Stata C API changes.

So, for example, the following fails in Stata/IC:

. clear

. set obs 10
obs was 0, now 10

. forvalues i = 1/800 {
  2.     gen x`i' = _n
  3. }
 
. * This is fine

. gisid x*

. gen x801 = 10
 
. * But now this fails

. gisid x*

# variables > matsize (801 > 800). Tried to run

    set matsize 801

but the command failed. Try setting matsize manually.
r(908);
@mcaceresb
Copy link
Owner Author

There is actually a fix for this, which blows my mind and am somewhat hesitant to implement. Error:

matrix a = J(1, 20000, 1)

No error (!!!)

mata st_matrix("a", J(1, 20000, 1))

The latter, howver, takes 8 seconds (!) and does seem to consume a lot more memory than it should. It seems that matrix for whatever reason is very slow and memory hungry. Both of these are instantaneous:

mata a = J(1, 20000, 1)
set obs 20000
gen a = 1

@mcaceresb
Copy link
Owner Author

Another fix: Save from mata to tempfile; implement function in C: sf_read_vector_tempfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant