Skip to content

out of memory?

8 messages · Brian Ripley, Javier Muñoz Criado, news_vkhamenya@chat.ru +2 more

#
Hello r-help,

why call:

#----------
outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0,.0001,m[r,c]) )
#----------

for matrix m with only 1000 rows and 2 columns forces my PC to use
more than 250Mb(!) of virtual memory?  strange...
#
On Thu, 22 Mar 2001 news_vkhamenya at chat.ru wrote:

            
Um, a strange use of outer. Try

m[m <= 0] <- 0.0001

for an efficient solution.
#
Hello Brian D. Ripley and r-help,
Thursday, March 22, 2001, 11:49:55 AM, you wrote:
PBDR> Um, a strange use of outer. Try

PBDR> m[m <= 0] <- 0.0001

PBDR> for an efficient solution.

thank you for a good solution, it helps. but what if I need
#--------
outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0, some_f(m[r,c]), m[r,c]) )
#-------
?

P.S. however, "out of virtual memory" stil there... and is not
     motivated yet. Maybe it is some kind of bug
#
news_vkhamenya at chat.ru writes:
m[m <= 0] <- some_f(m[m <= 0])

*provided* that some_f vectorizes properly. You may need

m[m <= 0] <- sapply(m[m <= 0], some_f)
Experiment with a smaller matrix, and you'll see the error of your ways:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    1    1    1    1    6    6    6    6     6
 [2,]    2    2    2    2    2    7    7    7    7     7
 [3,]    3    3    3    3    3    8    8    8    8     8
 [4,]    4    4    4    4    4    9    9    9    9     9
 [5,]    5    5    5    5    5   10   10   10   10    10
 [6,]    1    1    1    1    1    6    6    6    6     6
 [7,]    2    2    2    2    2    7    7    7    7     7
 [8,]    3    3    3    3    3    8    8    8    8     8
 [9,]    4    4    4    4    4    9    9    9    9     9
[10,]    5    5    5    5    5   10   10   10   10    10
     [,1] [,2]
[1,]    1    1
[2,]    2    2
[3,]    3    3
[4,]    4    4
[5,]    5    5

(If there is a bug, it is in array() not complaining when its data=
argument is getting truncated).
#
At 08:49 22/03/01 +0000, Prof Brian D Ripley wrote:
I have also had problems with outer:
[,1]      [,2]
[1,] -0.4678067 0.6257795
[2,]  1.3981146 0.6273542
[3,] -0.3987765 1.6764002
[,1]  [,2] 
[1,] "1 1" "1 2"
[2,] "2 1" "2 2"
[3,] "3 1" "3 2"
[,1]       [,2]
[1,] -0.4678067 -0.4678067
[2,]  1.3981146  1.3981146
[3,] -0.3987765 -0.3987765

I should get m here, but I get first column twice.

(R 1.2.2, w95)



---------------------------------------------------
Javier Mu?oz Criado                         
Delegado Provincial                          
Instituto Nacional de Estad?stica
C/ Cura 7 - 02071 Albacete - Espa?a
Tel 967 219 230 - Fax 967 216 649
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hello Peter,
Thursday, March 22, 2001, 2:38:48 PM, you wrote:
PDB> (If there is a bug, it is in array() not complaining when its data=
PDB> argument is getting truncated).

did you refered to following bug:

#-----------------
[1] 11 13 13
Warning message: 
longer object length
        is not a multiple of shorter object length in: 1:3 + 10:11
[1] 0.0000000 0.2890648 0.4771213
#-----------------

which plays its role in

#...
robj <- array(FUN(X, Y, ...), c(dX, dY))
#...

of outer source?
#
"Valery A.Khamenya" <news_vkhamenya at chat.ru> writes:
No, this one
[,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
One might have expected a warning that the array isn't big enough to
hold the data, but the behaviour *is* compatible with Splus 3.4....
#
PD> "Valery A.Khamenya" <news_vkhamenya at chat.ru> writes:
    >> Hello Peter,
    >>
>> Thursday, March 22, 2001, 2:38:48 PM, you wrote:
>> 
    >> 
    PDB> (If there is a bug, it is in array() not complaining when its
    PDB> data= argument is getting truncated).
    >>  did you refered to following bug:
    >> 
    >> #-----------------
    >> > "+"(1:3,10:11)
    >> [1] 11 13 13
    >> Warning message: 
    >> longer object length
    >>         is not a multiple of shorter object length in: 1:3 + 10:11 
    >> > log(1:3,10:11)
    >> [1] 0.0000000 0.2890648 0.4771213
    >> > 
    >> #-----------------
    >> 
    >> which plays its role in
    >> 
    >> #...
    >> robj <- array(FUN(X, Y, ...), c(dX, dY))
    >> #...
    >> 
    >> of outer source?

    PD> No, this one
    PD> > array(1:12,c(2,3))
    PD>      [,1] [,2] [,3]
    PD> [1,]    1    3    5
    PD> [2,]    2    4    6
    PD> >

    PD> One might have expected a warning that the array isn't big enough
    PD> to hold the data, but the behaviour *is* compatible with Splus
    PD> 3.4....

and Splus 5.1, and in S+ its even a documented feature...

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._