

Dear all,
I just noticed that the 0.9 update for FrF2 did not work out for Mac OS due to an error in an example that ran without error on all other platforms. I do not find any reason for this. In the past, umlauts or tab characters have sometimes been an issue, but I didn't find any of these. The function definition is
FrF2(nruns = NULL, nfactors = NULL, factor.names = if (!is.null(nfactors)) {
if (nfactors <= 50) Letters[1:nfactors] else
paste("F", 1:nfactors, sep = "")} else NULL,
default.levels = c(1, 1), generators = NULL, resolution = NULL,
estimable = NULL, max.nfree2fis = FALSE,
randomize = TRUE, seed = NULL, ...){...}
and the simplest call to this function fails:
FrF2(8,4)
gives the custom error message "nruns must be a power of 2.", which is generated in the first check within function FrF2:
if (!is.null(nruns)){
k < floor(log2(nruns))
if (!2^k==nruns) stop("nruns must be a power of 2.")}
Would the Mac (different from all other systems) require FrF2(nruns=8, nfactors=4) ? Or what else could be the issue here ?
Thanks for any pointers!
Regards, Ulrike


Ulrike Grömping wrote:
> Dear all,
>
> I just noticed that the 0.9 update for FrF2 did not work out for Mac OS due
> to an error in an example that ran without error on all other platforms. I
> do not find any reason for this. In the past, umlauts or tab characters have
> sometimes been an issue, but I didn't find any of these. The function
> definition is
>
> FrF2(nruns = NULL, nfactors = NULL, factor.names = if (!is.null(nfactors)) {
> if (nfactors <= 50) Letters[1:nfactors] else
> paste("F", 1:nfactors, sep = "")} else NULL,
> default.levels = c(1, 1), generators = NULL, resolution = NULL,
> estimable = NULL, max.nfree2fis = FALSE,
> randomize = TRUE, seed = NULL, ...){...}
>
> and the simplest call to this function fails:
> FrF2(8,4)
> gives the custom error message "nruns must be a power of 2.", which is
> generated in the first check within function FrF2:
>
> if (!is.null(nruns)){
> k < floor(log2(nruns))
> if (!2^k==nruns) stop("nruns must be a power of 2.")}
Probably a rounding issue on different platforms?
I guess the test should be something like:
if (!is.null(nruns)){
if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
stop("nruns must be a power of 2.")
}
Uwe
> Would the Mac (different from all other systems) require FrF2(nruns=8,
> nfactors=4) ? Or what else could be the issue here ?
>
> Thanks for any pointers!
>
> Regards, Ulrike
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel


On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote:
> >gives the custom error message "nruns must be a power of 2.", which is
> >generated in the first check within function FrF2:
> >
> > if (!is.null(nruns)){
> > k < floor(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
>
>
> Probably a rounding issue on different platforms?
> I guess the test should be something like:
>
> if (!is.null(nruns)){
> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
> stop("nruns must be a power of 2.")
> }
Probably, k is needed also later. Assumig that 2^k works correctly,
the following could be sufficient
if (!is.null(nruns)){
k < round(log2(nruns))
if (!2^k==nruns) stop("nruns must be a power of 2.")}
In order to test the assumption, one can use
x < 2^(0:100 + 0) # use double exponent to be sure
all(x == floor(x))
Powers of two are represented exactly, since they have only one significant bit.
Petr.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel


Thanks, Uwe, I think that's it!
I'll include your fix in the next update.
Regards, Ulrike
 Original Message 
From: Uwe Ligges < [hidden email]>
To: Ulrike Grömping < [hidden email]>
Cc: [hidden email]
Sent: Tue, 24 Mar 2009 14:45:57 +0100
Subject: Re: [Rd] Error in FrF2 example on Mac OS
> Ulrike Grömping wrote:
> > Dear all,
> >
> > I just noticed that the 0.9 update for FrF2 did not work out for Mac OS due
> > to an error in an example that ran without error on all other platforms. I
> > do not find any reason for this. In the past, umlauts or tab characters have
> > sometimes been an issue, but I didn't find any of these. The function
> > definition is
> >
> > FrF2(nruns = NULL, nfactors = NULL, factor.names = if (!is.null(nfactors)) {
> > if (nfactors <= 50) Letters[1:nfactors] else
> > paste("F", 1:nfactors, sep = "")} else NULL,
> > default.levels = c(1, 1), generators = NULL, resolution = NULL,
> > estimable = NULL, max.nfree2fis = FALSE,
> > randomize = TRUE, seed = NULL, ...){...}
> >
> > and the simplest call to this function fails:
> > FrF2(8,4)
> > gives the custom error message "nruns must be a power of 2.", which is
> > generated in the first check within function FrF2:
> >
> > if (!is.null(nruns)){
> > k < floor(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
>
> Probably a rounding issue on different platforms?
> I guess the test should be something like:
>
> if (!is.null(nruns)){
> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
> stop("nruns must be a power of 2.")
> }
>
> Uwe
>
> > Would the Mac (different from all other systems) require FrF2(nruns=8,
> > nfactors=4) ? Or what else could be the issue here ?
> >
> > Thanks for any pointers!
> >
> > Regards, Ulrike
 End of Original Message 
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel


Petr Savicky wrote
On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote:
> >gives the custom error message "nruns must be a power of 2.", which is
> >generated in the first check within function FrF2:
> >
> > if (!is.null(nruns)){
> > k < floor(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
>
>
> Probably a rounding issue on different platforms?
> I guess the test should be something like:
>
> if (!is.null(nruns)){
> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
> stop("nruns must be a power of 2.")
> }
Probably, k is needed also later. Assumig that 2^k works correctly,
the following could be sufficient
if (!is.null(nruns)){
k < round(log2(nruns))
if (!2^k==nruns) stop("nruns must be a power of 2.")}
In order to test the assumption, one can use
x < 2^(0:100 + 0) # use double exponent to be sure
all(x == floor(x))
Powers of two are represented exactly, since they have only one significant bit.
Petr.
Yes, round instead of floor should also do the job, if rounding is the issue. But then, with powers of 2 indeed being represented exactly (I would expect even on Macs), maybe rounding is not the issue? I have no possibility to check this, since I do not have access to a Mac with R installed. On my windows machine,
all(log2(x)==floor(log2(x)))
with x as defined above yields TRUE.
Regards, Ulrike


On Tue, Mar 24, 2009 at 07:41:31AM 0700, Ulrike Grömping wrote:
> > Probably, k is needed also later. Assumig that 2^k works correctly,
> > the following could be sufficient
> >
> > if (!is.null(nruns)){
> > k < round(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
> >
> > In order to test the assumption, one can use
> >
> > x < 2^(0:100 + 0) # use double exponent to be sure
> > all(x == floor(x))
> >
> > Powers of two are represented exactly, since they have only one
> > significant bit.
> >
> > Petr.
> >
>
> Yes, round instead of floor should also do the job, if rounding is the
> issue. But then, with powers of 2 indeed being represented exactly (I would
> expect even on Macs), maybe rounding is not the issue? I have no possibility
> to check this, since I do not have access to a Mac with R installed. On my
> windows machine,
> all(log2(x)==floor(log2(x)))
> with x as defined above yields TRUE.
Christophe Dutang tested this on Mac with the result
> x < 2^(0:100 + 0)
> all(x == floor(x))
[1] TRUE
> all(log2(x) == floor(log2(x)))
[1] TRUE
> x
[1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01
[6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02
[11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04
[16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05
[21] 1.048576e+06 2.097152e+06 4.194304e+06 8.388608e+06 1.677722e+07
[26] 3.355443e+07 6.710886e+07 1.342177e+08 2.684355e+08 5.368709e+08
[31] 1.073742e+09 2.147484e+09 4.294967e+09 8.589935e+09 1.717987e+10
...
Without an analysis of the error directly on Mac, it is hard to guess, what
is the problem. What could also be tested is, whether the input nruns is an
integer or not. Either strictly,
if (nruns != floor(nruns)) stop("nruns not an integer")
or with some tolerance
nruns0 < nruns
nruns < round(nruns)
if (!isTRUE(all.equal(nruns, nruns0))) stop("nruns not an integer")
Petr.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel


Petr Savicky wrote
On Tue, Mar 24, 2009 at 07:41:31AM 0700, Ulrike Grömping wrote:
> > Probably, k is needed also later. Assumig that 2^k works correctly,
> > the following could be sufficient
> >
> > if (!is.null(nruns)){
> > k < round(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
> >
> > In order to test the assumption, one can use
> >
> > x < 2^(0:100 + 0) # use double exponent to be sure
> > all(x == floor(x))
> >
> > Powers of two are represented exactly, since they have only one
> > significant bit.
> >
> > Petr.
> >
>
> Yes, round instead of floor should also do the job, if rounding is the
> issue. But then, with powers of 2 indeed being represented exactly (I would
> expect even on Macs), maybe rounding is not the issue? I have no possibility
> to check this, since I do not have access to a Mac with R installed. On my
> windows machine,
> all(log2(x)==floor(log2(x)))
> with x as defined above yields TRUE.
Christophe Dutang tested this on Mac with the result
> x < 2^(0:100 + 0)
> all(x == floor(x))
[1] TRUE
> all(log2(x) == floor(log2(x)))
[1] TRUE
> x
[1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01
[6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02
[11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04
[16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05
[21] 1.048576e+06 2.097152e+06 4.194304e+06 8.388608e+06 1.677722e+07
[26] 3.355443e+07 6.710886e+07 1.342177e+08 2.684355e+08 5.368709e+08
[31] 1.073742e+09 2.147484e+09 4.294967e+09 8.589935e+09 1.717987e+10
...
Without an analysis of the error directly on Mac, it is hard to guess, what
is the problem. What could also be tested is, whether the input nruns is an
integer or not. Either strictly,
if (nruns != floor(nruns)) stop("nruns not an integer")
or with some tolerance
nruns0 < nruns
nruns < round(nruns)
if (!isTRUE(all.equal(nruns, nruns0))) stop("nruns not an integer")
Petr.
______________________________________________
Rdevel@rproject.org mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel
Thanks for this test report, sounds as though rounding may not be the issue here. I've uploaded the version with round instead of floor anyway, together with a few more bug fixes, and I'll see what happens with the Mac checks on CRAN. With Mac users being a minority, I'm not willing to complicate things for other platforms in order to accomodate Mac fixes that I can't even check myself. But I don't think that this can be all that complicated. If rounding is not the root cause, someone will certainly come up with another idea. I'll report back, whether the rounding error approach solved the problem.
Regards, Ulrike


On Mar 24, 2009, at 10:41 , Ulrike Grömping wrote:
>
>
> Petr Savicky wrote:
>>
>> On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote:
>>>> gives the custom error message "nruns must be a power of 2.",
>>>> which is
>>>> generated in the first check within function FrF2:
>>>>
>>>> if (!is.null(nruns)){
>>>> k < floor(log2(nruns))
>>>> if (!2^k==nruns) stop("nruns must be a power of 2.")}
>>>
>>>
>>> Probably a rounding issue on different platforms?
>>> I guess the test should be something like:
>>>
>>> if (!is.null(nruns)){
>>> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
>>> stop("nruns must be a power of 2.")
>>> }
>>
>> Probably, k is needed also later. Assumig that 2^k works correctly,
>> the following could be sufficient
>>
>> if (!is.null(nruns)){
>> k < round(log2(nruns))
>> if (!2^k==nruns) stop("nruns must be a power of 2.")}
>>
>> In order to test the assumption, one can use
>>
>> x < 2^(0:100 + 0) # use double exponent to be sure
>> all(x == floor(x))
>>
>> Powers of two are represented exactly, since they have only one
>> significant bit.
>>
>> Petr.
>>
>
> Yes, round instead of floor should also do the job, if rounding is the
> issue. But then, with powers of 2 indeed being represented exactly
> (I would
> expect even on Macs), maybe rounding is not the issue? I have no
> possibility
> to check this, since I do not have access to a Mac with R installed.
> On my
> windows machine,
> all(log2(x)==floor(log2(x)))
> with x as defined above yields TRUE.
>
What you're missing is that you cannot rely on log2 to give you an
integer. The test above bears no relevance to your problem  this is
not about representing 2^x  this is about log2 which you cannot
expect to satisfy log2(2^b) == b numerically since it could as well be
computed log(x)/log(2) which is not exactly representable. Use round
and all is well :).
> which(floor(log2(2^x))!=x)
[1] 4 7 8 13 14 15 25 27 29 49 53 57 64 97
> which(round(log2(2^x))!=x)
integer(0)
Cheers,
Simon
>
> View this message in context: http://www.nabble.com/ErrorinFrF2exampleonMacOStp22675998p22681913.html> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rdevel>
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel


 Original Message 
From: Simon Urbanek < [hidden email]>
To: Ulrike Grömping < [hidden email]>
Cc: [hidden email]
Sent: Wed, 25 Mar 2009 10:32:59 0400
Subject: Re: [Rd] Error in FrF2 example on Mac OS
> On Mar 24, 2009, at 10:41 , Ulrike Grömping wrote:
>
> >
> >
> > Petr Savicky wrote:
> >>
> >> On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote:
> >>>> gives the custom error message "nruns must be a power of 2.",
> >>>> which is
> >>>> generated in the first check within function FrF2:
> >>>>
> >>>> if (!is.null(nruns)){
> >>>> k < floor(log2(nruns))
> >>>> if (!2^k==nruns) stop("nruns must be a power of 2.")}
> >>>
> >>>
> >>> Probably a rounding issue on different platforms?
> >>> I guess the test should be something like:
> >>>
> >>> if (!is.null(nruns)){
> >>> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
> >>> stop("nruns must be a power of 2.")
> >>> }
> >>
> >> Probably, k is needed also later. Assumig that 2^k works correctly,
> >> the following could be sufficient
> >>
> >> if (!is.null(nruns)){
> >> k < round(log2(nruns))
> >> if (!2^k==nruns) stop("nruns must be a power of 2.")}
> >>
> >> In order to test the assumption, one can use
> >>
> >> x < 2^(0:100 + 0) # use double exponent to be sure
> >> all(x == floor(x))
> >>
> >> Powers of two are represented exactly, since they have only one
> >> significant bit.
> >>
> >> Petr.
> >>
> >
> > Yes, round instead of floor should also do the job, if rounding is the
> > issue. But then, with powers of 2 indeed being represented exactly
> > (I would
> > expect even on Macs), maybe rounding is not the issue? I have no
> > possibility
> > to check this, since I do not have access to a Mac with R installed.
> > On my
> > windows machine,
> > all(log2(x)==floor(log2(x)))
> > with x as defined above yields TRUE.
> >
>
> What you're missing is that you cannot rely on log2 to give you an
> integer. The test above bears no relevance to your problem  this is
> not about representing 2^x  this is about log2 which you cannot
> expect to satisfy log2(2^b) == b numerically since it could as well be
> computed log(x)/log(2) which is not exactly representable. Use round
> and all is well :).
>
> > which(floor(log2(2^x))!=x)
> [1] 4 7 8 13 14 15 25 27 29 49 53 57 64 97
> > which(round(log2(2^x))!=x)
> integer(0)
>
> Cheers,
> Simon
>
Yes, round did indeed solve the problem, it just surprises me that the Mac is
so different from the other (binary) animals.
Regards,
Ulrike
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rdevel

