cmdline problem with using booleans

952 views
Skip to first unread message

Afroze Ibrahim

unread,
May 20, 2014, 7:55:47 AM5/20/14
to tor...@googlegroups.com
Im trying to use comman line arguments, which work fine except when expecting a boolean input.

For example if torch code is:
adaptiveLR = true
cmd=torch.CmdLine();
cmd:option('-adaptive',adaptiveLR,'diminishing learning rate');

And I give the command line argument:
-adaptive false

I get an error:
invalid argument: false

Usage: [options]
  -adaptive diminishing learning rate [true]


I think it is happening because the command line is interpreting the <false> as a string and not boolean. Any way to get around this?

Thanks!

soumith

unread,
May 20, 2014, 6:45:07 PM5/20/14
to torch7 on behalf of abes

Maybe use 0/1?

--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+un...@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at http://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

Afroze Ibrahim

unread,
May 20, 2014, 6:57:31 PM5/20/14
to tor...@googlegroups.com
It turns out only "null" and "false" values are considered as false booleans while all rest (including 0 and 1) are considered true. So I can't use them...
I can obviously check specifically for integer 0 or 1 and interpret them myself as true and false, but I'm just wondering if there is a proper way to deal with booleans?


On Wednesday, May 21, 2014 12:45:07 AM UTC+2, smth chntla wrote:

Maybe use 0/1?

Nicholas Leonard

unread,
May 21, 2014, 7:44:09 PM5/21/14
to tor...@googlegroups.com
When you specify a boolean value, you should use a default of false.

That way when you want to turn the switch on, you just specify:
th myfile.lua --adaptive

Which turns adaptive=true.

Afroze Ibrahim

unread,
May 22, 2014, 5:05:18 AM5/22/14
to tor...@googlegroups.com
Perfect. Thanks!:)

黄晓嗣

unread,
Aug 20, 2015, 8:54:14 AM8/20/15
to torch7
Thank you! It really helps!

在 2014年5月22日星期四 UTC+8上午7:44:09,Nicholas Leonard写道:

Mata Fu

unread,
Jan 19, 2017, 1:29:54 PM1/19/17
to torch7
Thank you! it really helps!

在 2014年5月22日星期四 UTC+2上午1:44:09,Nicholas Leonard写道:

Junho Cho

unread,
Jan 28, 2017, 6:15:36 AM1/28/17
to torch7
good tip

2014년 5월 20일 화요일 오후 8시 55분 47초 UTC+9, Afroze Ibrahim 님의 말:

suhas pillai

unread,
May 20, 2017, 10:10:10 PM5/20/17
to torch7
Thanks ...that helps

Shangxuan Wu

unread,
Jun 14, 2017, 2:19:17 AM6/14/17
to torch7
Thanks!


On Wednesday, May 21, 2014 at 4:44:09 PM UTC-7, Nicholas Leonard wrote:
Reply all
Reply to author
Forward
0 new messages