I would like to use the libLAS C/C++ library functions within R to import, analyse, export terrestrial lidar data. libLAS is a C/C++ library for reading and writing the very common LAS LiDAR format ( http://liblas.org/index.html ).
Would it be possible to use the Rcpp package to run this library (or other packages)? http://dirk.eddelbuettel.com/code/rcpp.html
Or should I compile and install it in order to use it following the compilation instructions http://liblas.org/compilation.html ? I am working on a MacOSx 10.6.5. As such I could also use it within Open Source GIS GRASS as described in the following wiki http://grass.osgeo.org/wiki/LIDAR#Micro-tutorial_for_LAS_data_import .
All advice is welcome related to reading and processing LIDAR data with R/GRASS.
Thanks,
Jan
For the question
Would it be possible to use the Rcpp
package to run this library (or other
packages)?
the answer is whopping Yup! as using it for glueing R to a given C/C++ library was pretty much the reason Rcpp was written for. Come and see the documentation and/or the rcpp-devel list for examples. There is some exciting new stuff happening with Rcpp modules but you can also get going the old-fashioned way of writing your wrapper. Rcpp makes mapping and R and C++ types (in both directions) a lot easier.
Related
I know there are ways of using Tensorflow in C++ they even have a documentation for it but I can seem to be able to get the library for it. I've checked the build from source instructions but it seems to builds a pip package rather than a library I can link to my project. I also found a tutorial but when I tried it out I ran out of memory and my computer crashed. My question is, how can I actually get the C++ library to work on my project? I do have these requirements, I have to work on windows with Visual Studio in C++. What I would love to is if I could get a pre-compiled DLL that I could just link but I haven't found such a thing and I'm open to other alternatives.
I can't comment so I am writing this as an answer.
If you don't mind using Keras, you could use the package frugally deep. I haven't seen a library myself either, but I came across frugally deep and it seemed easy to implement. I am currently trying to use it, so I cannot guarantee it will work.
You could check out neural2D from here:
https://github.com/davidrmiller/neural2d
It is a neural network implementation without any dependent libraries (all written from scratch).
I would say that the best option is to use cppflow, an easy wrapper that I created to use Tensorflow from C++ easily.
You won't need to install anything, just download the TF C API, and place it somewhere in your computer. You can take a look to the docs to see how to do it, and how to use the library.
The answer seems to be that it is hard :-(
Try this to start. You can follow the latest instructions for building from source on Windows up to the point of building the pip package. But don't do that - do this/these instead:
bazel -config=opt //tensorflow:tensorflow.dll
bazel -config=opt //tensorflow:tensorflow.lib
bazel -config=opt tensorflow:install_headers
That much seems to work fine. The problems really start when you try to use Any of the header files - you will probably get compilation errors, at least with TF version >= 2.0. I have tried:
Build the label_image example (instructions in the readme.md file)
It builds and runs fine on Windows, meaning all the headers and source are there somewhere
Try incorporating that source into Windows console executable: runs into compiler errors due to conflicts with std::min & std::max, probably due to Windows SDK.
Include c_api.h in a Windows console application: won't compile.
Include TF-Lite header files: won't compile.
There is little point investing the lengthy compile time in the first two bazel commands if you can't get the headers to compile :-(
You may have time to invest in resolving these errors; I don't. At this stage Tensorflow lacks sufficient support for Windows C++ to rely on it, particularly in a commercial setting. I suggest exploring these options instead:
If TF-Lite is an option, watch this
Windows ML/Direct ML (requires conversion of TF models to ONNX format)
CPPFlow
Frugally Deep
Keras2CPP
UPDATE: having explored the list above, I eventually found the following worked best in my context (real-time continuous item recognition):
convert models to ONNX format (use tf2onnx or keras2onnx
use Microsoft's ONNX runtime
Even though Microsoft recommends using DirectML where milliseconds matter, the performance of ONNX runtime using DirectML as an execution provider means we can run a 224x224 RGB image through our Intel GPU in around 20ms, which is quick enough for us. But it was still hard finding our way to this answer
I have Tensorflow with python api and got these checkpoint model file:
model.ckpt-17763.data-00000-of-00001
model.ckpt-17763.index
model.ckpt-17763.meta
But I want a C/C++ shared library (.so file) when integrating into production. So I need to load these model file and inference with C++ code and compile to a shared library. Is there some tutorial or sample for doing this?
You can write c++ code to load and use your graph with the instructions given here.
You can use the files here to make a Cmake project with tensorflow outside the TF repository, and compile your library.
However, you'll still need the .ckpt files next to your .so, I don't know how to intergate them inside it.
There are a lot of questions about that on S.O., and a few tutorials (see the two cited in this answer) but since tensorflow is evolving fast, they quickly become outdated, and it's always a bit of struggle to get it to work properly (totally feasible, and getting easier, though).
I am developing part of my R package in C++ using Rcpp and I need to use a Linear Programming Solver.
After comparing some benchmarks using the solvers implementation into R (lpSolveAPI, Rglpk, Rsymphony and so on) I have decided to use GLPK. However, I have found no good way to use it in my C++ code developing under Windows.
Simply put, there is no simple way to just install GLPK and call it using something like
#include <glpk.h>
and I have found no implementations in R packages so that I can use a shortcut using Rcpp attributes like
// [[Rcpp::depends(package)]]
Any ideas?
I'm sure you are aware of the Rglpk package and its predecessor glpk. Often in these cases, it's helpful to stand on the shoulders of those that came before us. Having said that, we gleam from the package sources the following:
The source of Rglpk requires a pre-existing system install, does not enable linking, and is specific to Linux.
The source of glpk installs the library headers directly in R and it seems to also provide direct wrappers into the library.
Given the current implementations and your requirements, you would basically have to create an RcppGLPK package. This is primarily because no one really has a solution for what you need. I would highly suggest that you look at how RcppGSL is structured.
I'm trying to figure out how to set up Eclipse so that I can write R projects and packages which contain C++ code also.
Of course I could make separate R and C++ projects, compile the C++ code, copy the .dll to R project and use it in R using dyn.load function, but what If I want to build an R package which contains C++ source codes? I could again have separate C++ and R projects, put copy the C++ codes into the src folder of my R package, and I guess using R package builder within StatET perspective would work properly? But I'm wondering can I make just one R package project and embed C++ code inside of that project so that I get the benefits of the C++ perspective, ie. color codings of the code etc?
I know someone will mention Rcpp, but that is not an option here. I'm trying to learn C++ and how to combine it with R in a hard way first.
I'm using both Linux and Windows.
edit: Just to clarify, I want to know how I can set up Eclipse so that it understands both R and C++ codes at the same time, ie. both codes have color codings etc.
I am as much as fan of the editor war's as anybody else but you misunderstand. Take what you wrote:
I'm trying to learn C++ and how to combine it with R in a hard way
first.
So read "Writing R Extensions" carefully, and redo the examples. On the command-line. Then learn how to use a Makefile.
It is about the code and the compiler invocation. Whether you write the code in vi, Emacs, or Eclipse does not matter if you do not understand how to call the compiler, or how to write your code. So your intent is right: learn these basics.
Once you grok all that plumming you are ready to insert appropriate declarations into your Eclipse/StatET configurations.
(And if you want to cheat I could point you to the contributed cmake files in the RInside package.)
Okay it seems that I had poorly installed Eclipse which caused some problems. The answer to my question is that I can work in StatET perspective and it automatically understands C++ code if the filename extension is of form .c or .cpp. I can then compile the code by using R CMD SHLIB or R CMD INSTALL, if the code is part of some package.
I am working on a large open source C++ program that uses the R standalone library (libRmath, Ubuntu/Debian package r-mathlib). I want to remove this dependency: I'd like to include the source code from the R standalone library in my source tree, without the entire R source code. Can this be done?
Unfortunately, the R standalone library seems tightly coupled to the rest of the R code. In the standard R source tarball, the same configure script is used for the main package and the standalone library. This configure script doesn't play well on different platforms. I am hoping that the standalone library is available as its own "standalone" source tree.
Related note: I've looked at the Rinside library, particularly via this thread. I think the method I am describing would make distribution easier, for 2 reasons: 1) users that already have R installed won't have to reconfigure their installation (and can maintain a different version as their default installation); 2) users without R won't have to install it.
Update: fixed a typo - I'd originally referred to Rinside as Rinclude
A few points for you:
Can this be done? Of course it can, just copy and paste the code for r-mathlib into your project. The licensing for that library is a very liberal LGPL. Now, is it a good idea? I don't think so. Shared libraries have upside in that you get bugfixes, easier and shorter build etc/
Seems tightly coupled to the rest of the R code. No, that is factually incorrect. The whole point of r-mathlib is that you can depend just on it. I think it may still needs R headers on your system but if you define the MATHLIB_STANDALONE variable. E.g., on my Ubuntu box I just did gcc -o /tmp/rmathTest /usr/share/doc/r-mathlib/examples/test.c -lRmath -lm and the resulting binary depends on libRmath alone, not libR.
Configure script doesn't play well on other platforms. That is a bold statement, don't make it anywhere near Prof Ripley. R is amazingly portable, and I fear your claim is a little lacking in empirical basics here.
What you are after can be done in different ways, and has been done in different ways.
And yes there is ample documentation as well. Start with 'Writing R Extensions' and 'R Admin + Inst' and by all means come back with follow-up questions.
Lastly, in case you change your mind and you do want R inside C++, you may want to consider RInside as well. That does however create a depedencies on R, Rcpp and RInside itself.