[R] rep with bigz in gmp

Peter Ehlers ehlers at ucalgary.ca
Thu Mar 29 02:16:01 CEST 2012


On 2012-03-27 21:03, Kohske Takahashi wrote:
> Hi
>
> With package:gmp, is this an expected behavior?
>
>> rep(1:3, rep(3, 3))
> [1] 1 1 1 2 2 2 3 3 3
>
>> rep(as.bigz(1:3), rep(3, 3))
> Big Integer ('bigz') object of length 9:
> [1] 1 2 3 1 2 3 1 2 3
>
> This code is used inside `outer`, so more worse
>
>> outer(1:3, 1:3, `*`)
>       [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    2    4    6
> [3,]    3    6    9
>
>> outer(as.bigz(1:3), as.bigz(1:3), `*`)
> Big Integer ('bigz') 3 x 3 matrix:
>       [,1] [,2] [,3]
> [1,] 1    1    1
> [2,] 4    4    4
> [3,] 9    9    9
>
> of course, here is a workaround:
>
>> outer(as.bigz(1:3), as.numeric(as.bigz(1:3)), `*`)
> Big Integer ('bigz') 3 x 3 matrix:
>       [,1] [,2] [,3]
> [1,] 1    2    3
> [2,] 2    4    6
> [3,] 3    6    9
>
> thanks in advance.
>
> kohske
>

You'll notice that gmp has its own rep functions, rep.bigz
and rep.bigq. The help file shows that the 'times' argument
should be an integer, which presumably excludes a vector of
integers (cf ?rep.bigz and ?rep).

Arguably, it might be (marginally) worthwhile for rep.bigz
to spit out a warning message (something like that from if()
when that function is fed a condition of length > 1).

Peter Ehlers



More information about the R-help mailing list