w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Armadillo C++ LU decomposition
Since A = P.t()*L*U (where equality is only approximate due to rounding errors), solving for x in P.t()*L*U*x = b requires to permute rows of B and performing forward and back substitution: x = solve(trimatu(U), solve(trimatl(L), P*b) ); Due to the lack of a true triangular solver in armadillo, and a fast way to perform row permutation, this procedure will not be very efficient, with respect to a direct call to the relevant computational LAPACK subroutines. General advice is to avoid explicit LU decomposition in higher level libraries, like armadillo. if all different b's are known at the same time, store them as columns in a rectangular matrix B and X = solve(A,B); if the different b's are known one at a time, then precomputing AINV = A.i(); and x = AINV*b; will be more efficient i

Categories : C++

use the same memory to do LU decomposition in armadillo
You're going to have to use LAPACK directly, instead of going through Armadillo. I suggest you have a look at how Armadillo prepares data and calls the underlying LAPACK functions to implement solve(). This is in the file include/armadillo_bits/auxlib_meat.hpp EDIT: Armadillo developers are usually receptive to patches. If you come up with a solution, send them a patch or the modified files.

Categories : C++

Does Armadillo run well with Embarcadero C++ Builder XE*?
C++Builder's 32-bit compiler has several issues with more complicated C++ constructs, so it's not unusual for me to have to do some porting work to get C++ libraries to build in it. All other things being equal, I'd recommend another compiler. I have no experience with Armadillo in particular, but Embarcadero has a free trial available, so you should be able to try it yourself.

Categories : C++

cannot compile rinside with armadillo examples
The error you get is because Rcpp.h is included before RcppArmadillo.h, Rcpp.h is included by RInside.h. For the magic that RcppArmadillo gives you, the file RcppArmadillo.h needs to be loaded before Rcpp.h. So I suggest you do this: #include <RcppArmadillo.h> #include <RInside.h>

Categories : C++

Vectorized power function in armadillo
There is no predefined function of that kind in Armadillo. Here is a quick self-made version, that however will not benefit from any delayed expression evaluation template features of Armadillo: #include <cassert> #include <cmath> #include <armadillo> #include <iostream> template<class Object> Object elementwise_pow(const Object& base, const Object& p) { assert(base.n_elem == p.n_elem); Object result; result.copy_size(base); for (std::size_t i = 0; i < result.n_elem; ++i) { result[i] = std::pow(base[i], p[i]); } return result; } int main() { arma::mat m(3,3); m.fill(2.); arma::mat p(3,3); p << 1 << 2 << 3 << arma::endr << 4 << 5 << 6 << arma::en

Categories : C++

Armadillo join_cols() compile error
Are you sure you can call the join on vectors? At least looking at the documentation and given a fast look at the function definition it seems that it works on mat objects, since this code compiles fine: mat m1, m2; mat m3 = join_cols<mat>(m1, m2); also vec v1, v2; vec v3 = join_cols<mat>(v1, v2); works. I'd suggest you try the second example to see if the results are correct, maybe the library is not sure how to interpret a vector in a column join operation. But since vec is just a subclass of mat (logically a matrix with one row) i'd guess it works.

Categories : C++

Undefined Reference to LAPACK wrapper of Armadillo
Looks like you have two copies of Armadillo installed, which have different configurations. If in doubt, link your programs with: g++ prog.cpp -o prog -O2 -larmadillo -llapack -lblas You may also want to have a look at Armadillo's FAQ and a previous Stackoverflow question.

Categories : C++

How to perform element-wise Boolean operation in a matrix in Armadillo
This is accomplished via Armadillo's relational operators: mat A = randu<mat>(5,5) - 0.5; umat B = (A > 0); Note that B has the type "umat" instead of "mat". The former contains unsigned integer elements.

Categories : C++

Armadillo error: no matching function for call to ‘inv(arma::SpMat&)’
In contrast to the previous question about vec and mat in this case, at least from looking at armadillo headers, it seems that sp_mat and mat have unrelated base types, so you can't push the sp_mat type as a parameter to inv and join_cols, I guess do to the underlying data structures. Also, since both functions needed by you are not mentioned here http://arma.sourceforge.net/docs.html#SpMat I guess the support is not there. Since i at least partially understand the need for such a bix matrix to be kept as a sparse matrix, maybe it makes sense to use alternatives like http://math.nist.gov/sparselib++/ and http://math.nist.gov/mv++/ ?

Categories : C++

What happens after segfault?
The default handling for SIGSEGV is to terminate and generate a core dump. The process is killed and its associated resources are freed. Unless the program handles the signal, none of the following code will be executed. See the signal(7) man page for more information.

Categories : C++

C++ Segfault output
When building, use ndk-build NDK_DEBUG=1 that might give you more information on backtrace. If that doesn't magically help, you can use addr2line (which you'll still need to build with symbols). addr2line <addr> -e <filename> In your case you should get you something like $addr2line 0x6e64 -e libxxx.so XXX.c:406 One possible problem here if your libxxx.so isn't mapped at 0x0, then all the addresses would be offset to some other base value. However your addresses look small enough so it might work or may be even kernel prints the right values directly (subtracting the mapped addresses from pointer values and correctly printing addresses on log).

Categories : Android

What does ?? () in segfault error mean?
There are no debug information available in your glibc (since it's usually compiled without debug information). So the only thing you can see is the address of the function - but not its name, because it's not known. However, you can compile your program with debug information (gcc option: -ggdb). Then you can use a debugger like gdb or valgrind to see which line in your code caused the segfault.

Categories : C

Segfault at srandom_r
You might like ot add a test whether calloc() succeeded, as passing NULL most propably provokes the segmentation violation. #include <stdlib.h> ... struct random_data * qq = calloc(50, sizeof(*qq)); if (NULL == qq) perror("malloc() failed"); else srandom_r(time(NULL), qq);

Categories : C

Why does this pointer-fu segfault?
I think it looks broken. This: char *IPv4Address; /* optional element of type tt:IPv4Address */ says IPv4Address is a single pointer to character data, i.e. a string. But then it's used like this: DNSInformation->DNSManual->IPv4Address = (char **)soap_malloc(soap, sizeof(char *)); This is just wrong. Assuming a sane return value for soap_malloc() (i.e. void * to comply with malloc()), no cast should be necessary, but the fact that the cast differs from the actual type signal some kind of error. It treats the IPv4Address struct field as a pointer to pointer, which it clearly is not.

Categories : C

C++ segfault at the end of a for loop
You were passing the grounds parameter by value. That means a copy of the list was made. Apparently your Ground class have a broken copy constructor, which makes the getGlobalBounds() method referring to some invalid pointer, which caused the crash. You should almost never pass a big object by value unless you want to immediately copy it. Always train yourself to type const & all the time :).

Categories : C++

Sparse matrix conversion from Matrix to armadillo with RcppArmadilloExtensions/sp_mat.h
I have made a few changes to RcppArmadillo to clean this. Now as and wrap are correctly templated for sparse matrix types from armadillo (arma::SpMat<T>). Can you try again using the RcppArmadillo from svn ? Also, now, you should only need #include <RcppArmadillo.h> With the updated code, I'm able to compile your package as well as something like this : #include <RcppArmadillo.h> // [[Rcpp::depends("RcppArmadillo")]] using namespace Rcpp ; // [[Rcpp::export]] arma::sp_mat sparse( arma::sp_mat A ){ A(0,0) = 1; A(1,0) = 2; return A ; } /*** R require(Matrix) m <- Matrix(c(0,0,2:0), 3,5) sparse(m) */

Categories : C++

Segfault in Assembly Code
addl $8,%esp removes thing from the stack. It removes the two arguments pushed just above it. This instruction should be after the call to printf, not before it. There could be other errors; I have not checked thoroughly. Also, you have not specified in your question which tools or platform you are using. Different platforms may use different interfaces for calls, interrupts, and system routines.

Categories : Assembly

Segfault in my csv_loader() function
So, you've allocated space on the line right before: loaded_csv=malloc(sizeof(char **) *l); That is fine and dandy, but loaded_csv[0] isn't yet initialized to somewhere you own. So, when you do the following line loaded_csv[0][0]=malloc(getfirstcolumn(filename)*sizeof(char)+2); you are trying to set a variable located in some random location (wherever loaded_csv[0] happens to be right then). If you want to touch loaded_csv[0][0], you'll have to make sure that loaded_csv[0] is pointing to valid memory first (probably by allocating memory for it via malloc before you allocate something for loaded_csv[0][0].)

Categories : C

c segfault straight from the textbook
if(c>='0'&&c>='9') Well you meant: if(c>='0'&&c<='9') Also please check that c is correctly declared with type int and not char.

Categories : C

c++ shared flag segfault
From g++ manual: --shared Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.[1] When you put the --shared option, it means that you don't want an executable, but a shared object. In your case, you create a shared library and not an executable. This is why you segfault when your launch it.

Categories : C++

grep -f on OS X produces segfault
I've got OSX 10.8.4 on MacBook Air and your example doesn't crash by default, but only when adding --color parameter. Explanation This crash usually happens when you're mixing wilcard (asterisk sign) with the terminal colours and this is the software bug. Also check another simpler example: echo 'abc*' | grep --color=auto -e ".*" -e a Here it seems that --color=auto makes the difference (without it or setting to never, then it doesn't crash). So I assume that your grep is using colors in terminal by default. Solution Make sure that your grep is not an alias to the grep with colors enabled, or the colors are not enabled by default. You can always try to run grep with --color=never. For permanent solution, I've reported the bug report: http://www.freebsd.org/cgi/query-pr.cgi?pr=18

Categories : Osx

Understanding GDB and Segfault Messages
But the library the kernel identifies is different, No, it isn't. Do ls -l /lib64/libc.so.6, and you'll see that it's a symlink to libc-2.12.so. the address of the instruction is different The kernel message is for a different execution from the one you've observed in GDB, and address randomization caused libc-2.12.so to be loaded at a different base address. and the function and instruction within that library is different. That is, the instruction within libc-2-12.so is 0x13259f <__memset_sse2+911>: movdqa %xmm0,-0x43(%edx) It is likely that you looked at a different libc-2.12.so from the one that is actually used.

Categories : Linux

Gtk MessageDialog causes segfault (PYGObject)
I figured it out. The problem was calling "window.failDialog" directly instead of with GLib.idle_add. I added some other slight changes. Here is the new code: import time, threading from sys import exit from gi.repository import Gtk, GObject, GLib def run_core_engine(): time.sleep(2) window.switchToMainFrame() time.sleep(2.5) GLib.idle_add(window.failDialog, "The window said hello") class CoreThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.daemon = True super(CoreThread, self).start() def run(self): run_core_engine() class GettingInfoFrame(Gtk.Frame): def __init__(self): Gtk.Frame.__init__(self) self.connect("delete-event", Gtk.main_quit) self.set_shadow_type(Gtk.S

Categories : Python

What's your method for finding the cause of a segfault?
Use a debugger such as gdb and upon seg fault, print back trace. It would show the line number and file on which it crashed. Use this as a starting point. To take this further, you can repeat the process to make sure it is not a random fault occuring due to something wrong else where earlier and rather a specific problem at that line number. For static code analysis you can use tools such as klockworks or lint which would show possible issues in your code. For dynamic analysis, use tools such as memwatch which would monitor your memory allocations at run time. i didn't point out valgrind as it is already mentioned by others and no doubt is a great tool.

Categories : C++

Segfault logic with two threads
You can wait() for a process and pthread_wait() for a thread to finish (you didn't specify clearly which one you use). Remember that if you are in segfault handler, your memory is messed up (avoid malloc() and free()) and your FILE * could also be borked.

Categories : C++

c++11 nested lambda compile segfault
If you want to use C++11 features in a production environment, make sure to install the latest stable g++ or Clang compiler. Currently, that would be g++ 4.8.1 and Clang 3.3. They can be installed either from source (somewhat tricky, but if you have ever compiled a Linux kernel e.g., you should manage), or from a binary package from your own Linux distro or from a 3rd party package server. Very roughly -and unofficially- speaking, you can view g++ 4.7 as a late beta-version with a high-quality of implementation (although even g++ 4.7.2 as subtle lambda bugs), whereas g++ 4.6 is more of alpha / early beta quality for many C++11 features. You happen to have run into a g++ 4.6 bug. There is not much sense in tracking this particular bug down, you may or may not find a similar fault in the b

Categories : C++

segfault during write to the realloc'd area
Here is the cause of my problem. The point is that at some loop step stack->trcSize + size exceeds UINT32_MAX. That means Realloc in fact shrinks stc->trcData. Next, I define buffer which now is far behind the allocated area. Hence, when I write to buffer I get segfault. I've checked it and it was indeed the cause.

Categories : C

Why do I mysteriously segfault when writing to file?
You are declaring the identifier inputfile several times, but it won't be the same object at each time. See the behavior of this program for instance (from Wikipedia): #include <stdio.h> int main(void) { char x = 'm'; printf("%c ", x); { printf("%c ", x); char x = 'b'; printf("%c ", x); } printf("%c ", x); } You have to declare inputfile just once, and then assign it in if statements. FILE *inputfile; if (/* ... */) inputfile = /* ... */ else if (/* ... */) inputfile = /* ... */ else inputfile = /* ... */

Categories : C

SegFault in v8 on Windows in HandleScope constructor
If someone has the same problem, here is the answer: For some reason, it seems that V8 engine doesn't call its own initialize function. So if you put the line V8::initialize(); as the first line of your program it's gonna be ok. To create, a new Isolate that is not NULL, you have to call Isolate *isolate=Isolate::New()

Categories : Javascript

SAS Segfault with plot= option in GENMOD
An example from the SAS example library runs OK on my installation (9.3 TS1M1). I do get a warning 1476 proc genmod data=nor plots=(Reschi(xbeta) leverageplot); ------------ 1 WARNING 1-322: Assuming the symbol LEVERAGE was misspelled as leverageplot. Try changing your code to leverage instead of leverageplot. Also try rearranging the order in which you specify the plots. Older, experimental, versions of ODS GRAPHICS could be temperamental.

Categories : Sas

Bizarre segfault on memcpy in getline
The problem is that both buffer and nbytes are unitialized. From man getline(): Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary. getline() will be writing to a random location memory (whatever value buffer holds) that it has been told is nbytes (some unknown value) in size. This is undefined behaviour. To correct, initialize the variables to valid values and check the result of fopen() before using.

Categories : C

dalvik segfault on embedded linux
It is hard to tell from your trace where it actually failed. Are you using Android or trying to use dalvik in a non-android configuration? It might be easier to use an embedded configuration of Android than to try to port Dalvik to a non-bionic-based Linux distribution. Android system components such as Dalvik use quite a few additional kernel components, so it may be that you are still missing some of them. I enable the following in the kernel configuration and I'm able to run dalvik: # # Android # CONFIG_ANDROID=y CONFIG_ANDROID_BINDER_IPC=y CONFIG_ASHMEM=y CONFIG_ANDROID_LOGGER=y CONFIG_ANDROID_TIMED_OUTPUT=y # CONFIG_ANDROID_TIMED_GPIO is not set CONFIG_ANDROID_LOW_MEMORY_KILLER=y CONFIG_ANDROID_INTF_ALARM_DEV=y

Categories : Android

Manipulating array results in segfault?
Here are reasons this code might segfault: node is NULL, uninitialized, pointing to freed memory, or node->children is NULL, uninitialized, pointing to freed memory, or node->numchildren is greater than the allocated size of node->children Make sure the calling code: Allocates node allocates node->children sets node->numchildren passed in the right value for node Looking at the calling code pasted... The calling code does not allocate node; it's an uninitialized pointer, which means it points to a random location in memory. Misread that code due to the naming. The child passed down is an uninitialized pointer, but that won't case a segfault in the demonstrated code because it's never dereferenced. The first time { is entered, it should work fine. The second time it should s

Categories : C

Custom QDialog causes segfault upon exec()
Should be NodeEditBox::NodeEditBox(QWidget* _parent, GLWidget* _scene) : QDialog(parent) { /* nothing! */ } instead of NodeEditBox::NodeEditBox(QWidget* _parent, GLWidget* _scene){ /* nothing! */ } you need to pass through input arguments, otehrwise default ctor is called for unbderlying widget, with 0 parent. Not 100% sure if this causes segfault, but it is definitely error prone.

Categories : C++

Python: help(numpy) causes segfault on exit
From the Python side, I managed to track it down to this function in pydoc.py... def pipepager(text, cmd): """Page through text by feeding it to another program.""" pipe = os.popen(cmd, 'w') try: pipe.write(text) pipe.close() except IOError: pass # Ignore broken pipes caused by quitting the pager program. ...specifically the line pipe.write(text). The problem goes away if you change that function to... def pipepager(text, cmd): """Page through text by feeding it to another program.""" import subprocess pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True).stdin try: pipe.write(text) pipe.close() except IOError: pass # Ignore broken pipes caused by quitting the pager program. ...which might

Categories : Python

Numpy C++: How to iterate over PyArrayObject without a segfault
In the past I have done the following to iterate over a PyArrayObject: static PyObject *func1(PyObject *self, PyObject *args) { PyArrayObject *X; int ndX; npy_intp *shapeX; PyArray_Descr *dtype; NpyIter *iter; NpyIter_IterNextFunc *iternext; PyArg_ParseTuple(args, "O!", &PyArray_Type, &X); ndX = PyArray_NDIM(X); shapeX = PyArray_SHAPE(X); dtype = PyArray_DescrFromType(NPY_DOUBLE); iter = NpyIter_New(X, NPY_ITER_READONLY, NPY_KEEPORDER, NPY_NO_CASTING, dtype); if (iter==NULL) { return NULL; } iternext = NpyIter_GetIterNext(iter, NULL); dataptr = (double **) NpyIter_GetDataPtrArray(iter); do { cout << **dataptr << endl; } while (iternext(iter)); NpyIter_Deallocate(iter); retur

Categories : C++

segfault using SWIG converted code for tcl
I found the problem. Please see my other post: C++: linked library disappears and gives segfault during execution There was an undefined symbol of my library. I defined it and problem solved! The confusion was, my program crashed in the middle of tcl wrapper functions (where my undefined symbol was not involved at all). I don't really know why but that's it.. Hope it will help others!

Categories : C++

Boost.Asio segfault, no idea why
I think I found out the issue. Note the declaration order of the members of Server: boost::shared_ptr<Connection> connection; boost::asio::io_service io_service; boost::asio::signal_set signal_monitor; Destruction order is done in the opposite order of declaration. This means that first signal_monitor, then io_service and finally connection get destroyed. But connection contains a boost::asio::ip::tcp::socket containing a reference to io_service, which got destroyed. And indeed, this is pretty much what happening, and causes a segfault too: int main(int argc, char **argv) { auto io_service = new boost::asio::io_service(); auto socket = new boost::asio::ip::tcp::socket(*io_service); delete io_service; delete socket; return 0; } Declaring connection after i

Categories : C++

What is the best way to use the OpenCV library in conjunction with the Armadillo library?
To avoid or reduce copying, you can access the memory used by Armadillo matrices via the .memptr() member function. For example: mat X(5,6); double* mem = X.memptr(); Be careful when using the above, as you're not allowed to free the memory yourself (Armadillo will still manage the memory). Alternatively, you can construct an Armadillo matrix directly from existing memory. For example: double* data = new double[4*5]; // ... fill data ... mat X(data, 4, 5, false); // 'false' indicates that no copying is to be done; see docs In this case you will be responsible for manually managing the memory. Also bear in mind that Armadillo stores and accesses matrices in column-major order, ie. column 0 is first stored, then column 1, column 2, etc. This is the same as used by MATLAB, LAPACK an

Categories : Opencv

C: Passing one dimension of a 2D array results in segfault
You are allocating the array of pointers, but you aren't setting them to anything: float** signals = malloc(NUM_FILES * sizeof(float*)); Which means that you are passing an uninitialized pointer (signals[i]) here: read_signal_from_file(INPUT_FILES[i], signals[i], &tmp_info) Because signals[i] is passed by value, it isn't going to be changed in the function call, so it is still going to be uninitialized after read_signal_from_file returns. A simple change would be to pass by reference: int read_signal_from_file(const char* path, float* &signal, SF_INFO * info) { ... }

Categories : C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.