Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-29 Thread Mauricio Vargas
dear community

I started moving the last pieces of Stata code I had to RcppArmadillo. If
you are interested in macroeconomics, please check
https://github.com/pachamaltese/inputoutput.


I still have pending the DM thing, but at least I ported economics-area
specific functions that didn't exist in R.

best,

——
*Mauricio 'Pachá' Vargas Sepúlveda*
Site: pacha.dev
Blog: pacha.dev/blog


On Wed, Mar 25, 2020 at 1:15 PM Dirk Eddelbuettel  wrote:

>
> On 25 March 2020 at 12:55, Mauricio Vargas wrote:
> | And once again, I never used Rcpp on a scale that is not "elemental".
>
> But that is/was true for everybody else as well!
>
> You would be well advised to do a little "finger exercise".  Copy all
> CSparse
> files into src/, and create a single accessor doing the transformation you
> desire.  Then you at least have a reference case to check against any other
> external solution (you still ask other people to create for you). And next
> time things will be less initimidating because you will have had the
> "finger
> exercise" experience!
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
>
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Dirk Eddelbuettel

On 25 March 2020 at 12:55, Mauricio Vargas wrote:
| And once again, I never used Rcpp on a scale that is not "elemental".

But that is/was true for everybody else as well!

You would be well advised to do a little "finger exercise".  Copy all CSparse
files into src/, and create a single accessor doing the transformation you
desire.  Then you at least have a reference case to check against any other
external solution (you still ask other people to create for you). And next
time things will be less initimidating because you will have had the "finger
exercise" experience!

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Mauricio Vargas
Thanks a lot.

After reading that DM decomposition can be eventually be added to Matrix,
the toyectic package becomes useless by definition,
so that repo is discarded right away.

It could be great to have Matrix::dulmage_mendelsohn() to do something
similar as what you would do in octave/matlab/python.

And once again, I never used Rcpp on a scale that is not "elemental".

Best,

——
*Mauricio 'Pachá' Vargas Sepúlveda*
Site: pacha.dev
Blog: pacha.dev/blog


On Wed, Mar 25, 2020 at 10:18 AM Dirk Eddelbuettel  wrote:

>
> Mauricio,
>
> On 25 March 2020 at 10:06, Mauricio Vargas wrote:
> | Dear Dr. Maechler
> |
> | Thanks a lot.
> |
> | You can find the code here:
> |
> https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs_dmperm.c
> |
> | And this part is already in Matrix:
> | https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs.h
> |
> | You are right about the tangent with respect to Rcpp.
> |
> | So far, I cannot make it work in R, but it works from shell, so I really
> | appreciate your interest to make the code reproducible.
>
> You should be able to find several articles at the Rcpp Gallery that show
> hot
> to do that.  You can "practice" with functions from packages that are
> already
> exported as Martin may be able to export one for you.  To expect Martin,
> who
> doesn't even code much in C++, to fix your package for you may not be an
> entirely realistic, or fair, expectation.
>
> Dirk
>
> |
> | Best,
> |
> | —
> |
> | *Mauricio Vargas Sepúlveda 帕夏*
> | Do you like Data Science? visit pacha.hk
> | 你爱科学数据专吗?你走pacha.hk
> |
> |
> | On Wed, Mar 25, 2020 at 8:36 AM Martin Maechler <
> maech...@stat.math.ethz.ch>
> | wrote:
> |
> | >
> | > Dear Mauricio  (et al),
> | >
> | > I'm the maintainer of the 'Matrix' package (and just reading
> | > digests of Rcpp-devel, hence no "proper reply").
> | >
> | > This looks quite interesting and relevant to me,
> | > and I'd be interested to add this decomposition to the Matrix
> | > package, so would be happy if you already have code for parts of
> | > it.
> | >
> | > As CSparce, Matrix uses simple C though, and hence this posting
> | > is only peripherally related to Rcpp.
> | >
> | > Best regards,
> | >
> | > Martin Maechler
> | > ETH Zurich and  R Core team
> | >
> | >
> | > > Date: Wed, 25 Mar 2020 01:22:16 -0300
> | > > From: Mauricio Vargas 
> | > > To: rcpp-de...@r-forge.wu-wien.ac.at
> | > > Subject: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via
> Rcpp
> | >
> | > > Dear community
> | >
> | > > Dr. Eddelbuettel suggested me to ask here.
> | >
> | > > I am trying to implement *Dulmage-Mendelsohn decomposition* in R.
> | > CSparse
> | > > already has a function to do this, and it's not exported in
> Matrix
> | > so I
> | > > took the C files and tried to use them in  R.
> | >
> | > > I decided to sketch this into an R Package with Rcpp:
> | > > https://github.com/pachamaltese/dulmagemendelsohn
> | >
> | > > The final goal is to find a permutation matrix, so that the
> original
> | > matrix
> | > > is rearranged into a block diagonal matrix:
> | >
> | > > matrix_input <- matrix(
> | > > c(0,0,7,0,0,
> | > > 0,0,0,0,3,
> | > > 5,0,0,1,0,
> | > > 0,0,2,0,0,
> | > > 0,1,0,0,0),
> | > > ncol = 5, nrow = 5
> | > > )
> | >
> | > > dm_decomposition <- function(matrix_input) {
> | > > # the actual decomposition happens here
> | > > # ... "MAGIC" ...
> | >
> | > > # but here is an example output
> | > > matrix(
> | > > c(0,7,0,0,0,
> | > > 5,0,1,0,0,
> | > > 0,2,0,0,0,
> | > > 0,0,0,0,3,
> | > > 0,0,0,1,0),
> | > > ncol = 5, nrow = 5
> | > > )
> | > > }
> | >
> | > > dm_decomposition(matrix_input)
> | >
> | > > Can you please provide me some guidance to get this working?
> | >
> | > > I am by no means a C/C++ expert, I just have experience with
> | > statistics an
> | > > writing R packages.
> | >
> | >
> | > > *Mauricio Vargas Sepúlveda 帕夏*
> | > > Do you like Data Science? visit pacha.hk
> | >
> | > > -- next part --
> | > > An HTML attachment was scrubbed...
> | > > URL: <
> | >
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200325/d88b3c55/attachment-0001.html
> | > >
> | >
> | ___
> | Rcpp-devel mailing list
> | Rcpp-devel@lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
>
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Dirk Eddelbuettel

Mauricio,

On 25 March 2020 at 10:06, Mauricio Vargas wrote:
| Dear Dr. Maechler
| 
| Thanks a lot.
| 
| You can find the code here:
| https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs_dmperm.c
| 
| And this part is already in Matrix:
| https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs.h
| 
| You are right about the tangent with respect to Rcpp.
| 
| So far, I cannot make it work in R, but it works from shell, so I really
| appreciate your interest to make the code reproducible.

You should be able to find several articles at the Rcpp Gallery that show hot
to do that.  You can "practice" with functions from packages that are already
exported as Martin may be able to export one for you.  To expect Martin, who
doesn't even code much in C++, to fix your package for you may not be an
entirely realistic, or fair, expectation.

Dirk

| 
| Best,
| 
| —
| 
| *Mauricio Vargas Sepúlveda 帕夏*
| Do you like Data Science? visit pacha.hk
| 你爱科学数据专吗?你走pacha.hk
| 
| 
| On Wed, Mar 25, 2020 at 8:36 AM Martin Maechler 
| wrote:
| 
| >
| > Dear Mauricio  (et al),
| >
| > I'm the maintainer of the 'Matrix' package (and just reading
| > digests of Rcpp-devel, hence no "proper reply").
| >
| > This looks quite interesting and relevant to me,
| > and I'd be interested to add this decomposition to the Matrix
| > package, so would be happy if you already have code for parts of
| > it.
| >
| > As CSparce, Matrix uses simple C though, and hence this posting
| > is only peripherally related to Rcpp.
| >
| > Best regards,
| >
| > Martin Maechler
| > ETH Zurich and  R Core team
| >
| >
| > > Date: Wed, 25 Mar 2020 01:22:16 -0300
| > > From: Mauricio Vargas 
| > > To: rcpp-de...@r-forge.wu-wien.ac.at
| > > Subject: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp
| >
| > > Dear community
| >
| > > Dr. Eddelbuettel suggested me to ask here.
| >
| > > I am trying to implement *Dulmage-Mendelsohn decomposition* in R.
| > CSparse
| > > already has a function to do this, and it's not exported in Matrix
| > so I
| > > took the C files and tried to use them in  R.
| >
| > > I decided to sketch this into an R Package with Rcpp:
| > > https://github.com/pachamaltese/dulmagemendelsohn
| >
| > > The final goal is to find a permutation matrix, so that the original
| > matrix
| > > is rearranged into a block diagonal matrix:
| >
| > > matrix_input <- matrix(
| > > c(0,0,7,0,0,
| > > 0,0,0,0,3,
| > > 5,0,0,1,0,
| > > 0,0,2,0,0,
| > > 0,1,0,0,0),
| > > ncol = 5, nrow = 5
| > > )
| >
| > > dm_decomposition <- function(matrix_input) {
| > > # the actual decomposition happens here
| > > # ... "MAGIC" ...
| >
| > > # but here is an example output
| > > matrix(
| > > c(0,7,0,0,0,
| > > 5,0,1,0,0,
| > > 0,2,0,0,0,
| > > 0,0,0,0,3,
| > > 0,0,0,1,0),
| > > ncol = 5, nrow = 5
| > > )
| > > }
| >
| > > dm_decomposition(matrix_input)
| >
| > > Can you please provide me some guidance to get this working?
| >
| > > I am by no means a C/C++ expert, I just have experience with
| > statistics an
| > > writing R packages.
| >
| >
| > > *Mauricio Vargas Sepúlveda 帕夏*
| > > Do you like Data Science? visit pacha.hk
| >
| > > -- next part --
| > > An HTML attachment was scrubbed...
| > > URL: <
| > 
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200325/d88b3c55/attachment-0001.html
| > >
| >
| ___
| Rcpp-devel mailing list
| Rcpp-devel@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Mauricio Vargas
Dear Dr. Maechler

Thanks a lot.

You can find the code here:
https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs_dmperm.c

And this part is already in Matrix:
https://github.com/pachamaltese/dulmagemendelsohn/blob/master/src/cs.h

You are right about the tangent with respect to Rcpp.

So far, I cannot make it work in R, but it works from shell, so I really
appreciate your interest to make the code reproducible.

Best,

—

*Mauricio Vargas Sepúlveda 帕夏*
Do you like Data Science? visit pacha.hk
你爱科学数据专吗?你走pacha.hk


On Wed, Mar 25, 2020 at 8:36 AM Martin Maechler 
wrote:

>
> Dear Mauricio  (et al),
>
> I'm the maintainer of the 'Matrix' package (and just reading
> digests of Rcpp-devel, hence no "proper reply").
>
> This looks quite interesting and relevant to me,
> and I'd be interested to add this decomposition to the Matrix
> package, so would be happy if you already have code for parts of
> it.
>
> As CSparce, Matrix uses simple C though, and hence this posting
> is only peripherally related to Rcpp.
>
> Best regards,
>
> Martin Maechler
> ETH Zurich and  R Core team
>
>
> > Date: Wed, 25 Mar 2020 01:22:16 -0300
> > From: Mauricio Vargas 
> > To: rcpp-de...@r-forge.wu-wien.ac.at
> > Subject: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp
>
> > Dear community
>
> > Dr. Eddelbuettel suggested me to ask here.
>
> > I am trying to implement *Dulmage-Mendelsohn decomposition* in R.
> CSparse
> > already has a function to do this, and it's not exported in Matrix
> so I
> > took the C files and tried to use them in  R.
>
> > I decided to sketch this into an R Package with Rcpp:
> > https://github.com/pachamaltese/dulmagemendelsohn
>
> > The final goal is to find a permutation matrix, so that the original
> matrix
> > is rearranged into a block diagonal matrix:
>
> > matrix_input <- matrix(
> > c(0,0,7,0,0,
> > 0,0,0,0,3,
> > 5,0,0,1,0,
> > 0,0,2,0,0,
> > 0,1,0,0,0),
> > ncol = 5, nrow = 5
> > )
>
> > dm_decomposition <- function(matrix_input) {
> > # the actual decomposition happens here
> > # ... "MAGIC" ...
>
> > # but here is an example output
> > matrix(
> > c(0,7,0,0,0,
> > 5,0,1,0,0,
> > 0,2,0,0,0,
> > 0,0,0,0,3,
> > 0,0,0,1,0),
> > ncol = 5, nrow = 5
> > )
> > }
>
> > dm_decomposition(matrix_input)
>
> > Can you please provide me some guidance to get this working?
>
> > I am by no means a C/C++ expert, I just have experience with
> statistics an
> > writing R packages.
>
>
> > *Mauricio Vargas Sepúlveda 帕夏*
> > Do you like Data Science? visit pacha.hk
>
> > -- next part --
> > An HTML attachment was scrubbed...
> > URL: <
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200325/d88b3c55/attachment-0001.html
> >
>
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Dirk Eddelbuettel

On 25 March 2020 at 12:36, Martin Maechler wrote:
| 
| Dear Mauricio  (et al),
| 
| I'm the maintainer of the 'Matrix' package (and just reading
| digests of Rcpp-devel, hence no "proper reply").

Nice! In the StackOverflow thread leading up to this, I actualy mentioned
that the CSparse files that the OP desires are already in Matrix.

Maybe you can export the (C-level) function(s) he needs. If you set up normal
export in Matrix, we can pick it up pretty easily. There are some other
packages using it, inter alia expm where Vincent did this with some gentle
guidance from me (though he chose to not credit me, oh well). I see you
maintain that now too...
 
| This looks quite interesting and relevant to me,
| and I'd be interested to add this decomposition to the Matrix
| package, so would be happy if you already have code for parts of
| it.
| 
| As CSparce, Matrix uses simple C though, and hence this posting
| is only peripherally related to Rcpp.

For package interop Rcpp can help as well. I have two simple packages
(RApiDatetime, RApiSerialize) exporting C level code which other (Rcpp-using)
packages import. They provide working examples which Mauricio could
study/copy. We have also the grandfather of them all at the C level (matrix +
lme4) and a few more (zoo + xts) plus surely a few I do not remember now...

Dirk
 
| Best regards,
| 
| Martin Maechler
| ETH Zurich and  R Core team
| 
| 
| > Date: Wed, 25 Mar 2020 01:22:16 -0300
| > From: Mauricio Vargas 
| > To: rcpp-de...@r-forge.wu-wien.ac.at
| > Subject: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp
| 
| > Dear community
| 
| > Dr. Eddelbuettel suggested me to ask here.
| 
| > I am trying to implement *Dulmage-Mendelsohn decomposition* in R. 
CSparse
| > already has a function to do this, and it's not exported in Matrix so I
| > took the C files and tried to use them in  R.
| 
| > I decided to sketch this into an R Package with Rcpp:
| > https://github.com/pachamaltese/dulmagemendelsohn
| 
| > The final goal is to find a permutation matrix, so that the original 
matrix
| > is rearranged into a block diagonal matrix:
| 
| > matrix_input <- matrix(
| > c(0,0,7,0,0,
| > 0,0,0,0,3,
| > 5,0,0,1,0,
| > 0,0,2,0,0,
| > 0,1,0,0,0),
| > ncol = 5, nrow = 5
| > )
| 
| > dm_decomposition <- function(matrix_input) {
| > # the actual decomposition happens here
| > # ... "MAGIC" ...
| 
| > # but here is an example output
| > matrix(
| > c(0,7,0,0,0,
| > 5,0,1,0,0,
| > 0,2,0,0,0,
| > 0,0,0,0,3,
| > 0,0,0,1,0),
| > ncol = 5, nrow = 5
| > )
| > }
| 
| > dm_decomposition(matrix_input)
| 
| > Can you please provide me some guidance to get this working?
| 
| > I am by no means a C/C++ expert, I just have experience with statistics 
an
| > writing R packages.
| 
| 
| > *Mauricio Vargas Sepúlveda 帕夏*
| > Do you like Data Science? visit pacha.hk
| 
| > -- next part --
| > An HTML attachment was scrubbed...
| > URL: 

| ___
| Rcpp-devel mailing list
| Rcpp-devel@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

2020-03-25 Thread Martin Maechler

Dear Mauricio  (et al),

I'm the maintainer of the 'Matrix' package (and just reading
digests of Rcpp-devel, hence no "proper reply").

This looks quite interesting and relevant to me,
and I'd be interested to add this decomposition to the Matrix
package, so would be happy if you already have code for parts of
it.

As CSparce, Matrix uses simple C though, and hence this posting
is only peripherally related to Rcpp.

Best regards,

Martin Maechler
ETH Zurich and  R Core team


> Date: Wed, 25 Mar 2020 01:22:16 -0300
> From: Mauricio Vargas 
> To: rcpp-de...@r-forge.wu-wien.ac.at
> Subject: [Rcpp-devel] Dulmage-Mendelsohn decomposition in R via Rcpp

> Dear community

> Dr. Eddelbuettel suggested me to ask here.

> I am trying to implement *Dulmage-Mendelsohn decomposition* in R. CSparse
> already has a function to do this, and it's not exported in Matrix so I
> took the C files and tried to use them in  R.

> I decided to sketch this into an R Package with Rcpp:
> https://github.com/pachamaltese/dulmagemendelsohn

> The final goal is to find a permutation matrix, so that the original 
matrix
> is rearranged into a block diagonal matrix:

> matrix_input <- matrix(
> c(0,0,7,0,0,
> 0,0,0,0,3,
> 5,0,0,1,0,
> 0,0,2,0,0,
> 0,1,0,0,0),
> ncol = 5, nrow = 5
> )

> dm_decomposition <- function(matrix_input) {
> # the actual decomposition happens here
> # ... "MAGIC" ...

> # but here is an example output
> matrix(
> c(0,7,0,0,0,
> 5,0,1,0,0,
> 0,2,0,0,0,
> 0,0,0,0,3,
> 0,0,0,1,0),
> ncol = 5, nrow = 5
> )
> }

> dm_decomposition(matrix_input)

> Can you please provide me some guidance to get this working?

> I am by no means a C/C++ expert, I just have experience with statistics an
> writing R packages.


> *Mauricio Vargas Sepúlveda 帕夏*
> Do you like Data Science? visit pacha.hk

> -- next part --
> An HTML attachment was scrubbed...
> URL: 

___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel