# Re: [Rd] non user-friendly error for chol2inv functions

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri, 29 Aug 2008 15:27:01 +0200

>>>>> "TH" == Ted Harding <Ted.Harding_at_manchester.ac.uk> >>>>> on Fri, 29 Aug 2008 14:21:05 +0100 (BST) writes:

```    TH> On 29-Aug-08 13:00:01, Martin Maechler wrote:
>>>>>>> "cd" == christophe dutang <dutangc_at_gmail.com>
>>>>>>> on Fri, 29 Aug 2008 14:28:42 +0200 writes:
```

>>
```    cd> Yes, I do not cast the first argument as a matrix with
cd> as.matrix function.
cd> Maybe we could detail the error message if the first
cd> argument
cd> is a numeric?
```

>>

cd> error(_("'a' is a numeric and must be coerced to a numeric     cd> matrix"));
>>
>> Merci, Christophe. Yes, we *could* do that.
>> Alternatively, I think I will just make it work in that case,
>> since I see that
>> qr(), chol(), svd(), solve() all
>> treat a numeric (of length 1) as a 1 x 1 matrix automatically.
```    TH> I was about to draw attention to this "inconsistency"!
TH> While one is about it, might it not be useful also to do
TH> the converse: Treat a 1x1 matrix as a scalar in appropriate
TH> contexts?

```

TH> E.g.

```    TH> a <- 4
TH> A <- matrix(4,1,1)
TH> B <- matrix(c(1,2,3,4),2,2)
TH> a*B
TH> #      [,1] [,2]
TH> # [1,]    4   12
TH> # [2,]    8   16

TH> a+B
TH> #      [,1] [,2]
```

TH> # [1,] 5 7
TH> # [2,] 6 8
```    TH> A*B
TH> # Error in A * B : non-conformable arrays
TH> A+B
TH> # Error in A + B : non-conformable arrays

```

TH> Ted.

I can only speak for myself and my own taste, but I'd clearly not want that the above would just work.

I could agree of having it work *WITH A WARNING* ... particularly if there were more good arguments along your line of thought..

Martin

>>

>> De rien!
>> Martin
>>
cd> 2008/8/29 Martin Maechler <maechler_at_stat.math.ethz.ch>
>>
>> >> >>>>> "cd" == christophe dutang <dutangc@gmail.com>
>> >> >>>>> on Fri, 29 Aug 2008 12:44:18 +0200 writes:
>> >>
cd> Hi,
cd> In function chol2inv with the option LINPACK set to false
>> (default),
>> >> it

cd> raises an error when the matrix is 1x1 matrix (i.e. just a
>> real)
>> >> saying
>> >>

cd> 'a' must be a numeric matrix
>> >>
>> >> It is very helpful, but you have to read and understand it.
>> >> I'm pretty sure you did not provide a 1 x 1 matrix.
>> >>
>> >> Here's an example showing how things works :
>> >>
>> >> > m <- matrix(4,1,1)
>> >> > cm <- chol(m)
>> >> > cm
>> >> [,1]
>> >> [1,] 2
>> >> > chol2inv(cm)
>> >> [,1]
>> >> [1,] 0.25
>> >> >
>> >>
>> >> Martin Maechler, ETH Zurich
>> >>
>> >>
cd> This error is raised by the underlying C function
>> (modLa_chol2inv in

cd> function Lapack.c). Everything is normal, but I wonder if we
>> could
>> >> have

cd> another behavior when we pass a 1x1 matrix. I spent time this
>> >> morning

>> >>

>> >>

cd> Christophe
>> >>

cd> [[alternative HTML version deleted]]
>> >>

```    cd> ______________________________________________
```
cd> R-devel_at_r-project.org mailing list     cd> https://stat.ethz.ch/mailman/listinfo/r-devel
>> >>
>>

cd> [[alternative HTML version deleted]]
>>
```    cd> ______________________________________________
```
cd> R-devel_at_r-project.org mailing list     cd> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> ______________________________________________
>> R-devel_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
```    TH> --------------------------------------------------------------------
TH> E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk>
TH> Fax-to-email: +44 (0)870 094 0861
TH> Date: 29-Aug-08                                       Time: 14:16:03
TH> ------------------------------ XFMail ------------------------------

TH> ______________________________________________
```
TH> R-devel_at_r-project.org mailing list     TH> https://stat.ethz.ch/mailman/listinfo/r-devel

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 29 Aug 2008 - 13:29:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Aug 2008 - 16:38:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.