Using GMP in Eigen3 [closed] - eigen

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am working on some sample program and trying to use matrix functionalities offered by Eigen3 library.
I want to store high precision integer variable(mpz_t) in a (100,100) matrix. For storing integer, there is already inbuilt data type MatrixXd. Similarly, just wanted it for high precision variables. Please share some advices.
Thanks.

Basically, all you need to do is declare a Matrix<mpz_class,Dynamic,Dynamic> matrix. The mpz_class type is a c++ wrapper around mpz_t such that it behaves like any scalar type.
Here is an example:
#include <Eigen/Core>
#include <gmpxx.h>
using namespace Eigen;
typedef Matrix<mpz_class,Dynamic,Dynamic> MatrixXz;
int main() {
MatrixXz A(10,10), B(10,10), C(10,10);
A.fill(111);
B.fill(222);
C = 2*A + B;
}

Related

Can not understand about vector function in C++ stl and differences [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am not able to figure out difference between vector<set <int >> v(26) and vector<set < int > > v[26]. Please if possible explain how they work and how are they different with example.
Both are invalid declarations. One is an illegal declaration of one vector with 26 elements and the other is an illegal declaration of an array of 26 vectors.
set is a class template and needs a type to be used.
Example:
vector<set<int>> v(26); // a vector with 26 sets of int
vector<set<int>> v[26]; // an array of 26 vectors of set of ints

How does Ruby generate random numbers using [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So when using, for example, rand(10), how does ruby generate the random number? I have very little knowlege about random number generation techniques, so I would like to get to know them better.
Ruby is open-source. I'll demonstrate how to locate the PRNG (pseudo random number generator) code, as there's no way to generate truly random numbers using a deterministic CPU.
Looking at the repository, we see a suspiciously-named file, random.c. Looking inside, it's in C, but that's ok, it has comments. The first function is genrand_real, calling genrand_int32, which takes a struct MT. This function is defined in mt19937.c and looking at that file, it uses bitwise operations to get the next state of the random number generator and applies more bitwise operators to generate the number desired.

How can create a vector of Point Cloud as Buffer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
What the efficient way to create a vector of point clouds used as a buffer in order to store multi-scanning point clouds
Starting C++11, you can use std::vector as an RAII buffer.
Instead of allocating the space yourself using new and then having to delete the pointer to avoid memory leaks, you can simply create an std::vector and pre-allocate it so that it can be used a a buffer:
(some of this is some pseudo code since I'm not familiar with point clouds)
#include <vector>
constexpr unsigned int numberOfPoints = 100;
std::vector<point_clouds> buffer(numberOfPoints);
scan_point_clound_func(buffer.data(), buffer.size());
point_cloud p = buffer[0];

How to create a function that returns a random number from the LEVY distribution in Lua? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
As the title says, is there an easy function I can make in Lua that draws a random number based on the Levy probability density function?
I'm planning on using Levy-flight to make particles explore (make large steps) in a search space more efficiently.
Use rejection sampling on the graph of the Lévy PDF [answer from user: lhf]
Example of code:
function rejectionSampling()
repeat
local x = random.uniform(1)
local y = random.uniform(1.5) -- PDF maximum peak at x=1/3 --> y~1.45
fx = math.sqrt(1/(2*math.pi))*math.exp(-1/(2*x))/(x^1.5) --PDF
until y < fx
return x
end
Use rejection sampling on the graph of the Lévy PDF.
one solution could be :
give a lecture to John Nolan RobustAnalysis
buy/try the C library, here is the documentation.
use luaJit ffi library and map c functions and data structure to lua.
...it's no difficult but you need time.
Outside lua (yes I know the question was on lua), but you could try an interaction between lua and Wolfram Mathematica, where stable distribution are built-in.

simple bcrypt library for C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm looking for a simple to use cross-platform bcrypt library for C. I've searched around a couple places but nothing seems to compares to the ease of use of:
http://bcrypt.codeplex.com/SourceControl/changeset/view/1eef0262901c#BCrypt.Net.Test%2fTestBCrypt.cs
Why are all the C implementations of this a nightmare compared to this .NET lib? Basically 2 functions is what I'm looking for.
1) Generate salt (return a string)
2) Hash string using a given salt & pw (return a string)
Your C options for bcrypt seem to be:
In OpenBSD: https://github.com/openbsd/src/blob/master/lib/libc/crypt/bcrypt.c
In OpenWall: http://openwall.com/crypt/
The C implementations seem to be pretty straightforward to use. The OpenBSD version looks like this:
char *bcrypt(const char *key, const char *salt);
char *bcrypt_gensalt(u_int8_t log_rounds);
P.S. Consider scrypt for new code, if you are not restricted to using bcrypt only due to backward compatibility,

Resources