Unexpected optimization of strlen when aliasing 2-d array

I checked this and it reproduced with -O1 on gcc 8.3, so I just opened list of gcc optimization flags here and started experimenting with them one by one. It turned out that disabling only sparse conditional constant propagation with -fno-tree-ccp made the problem disappear (oh luck, I planned to test couples of flags if … Read more

Compare blitz++, armadillo, boost::MultiArray

Short answer: ./configure CXX=icpc, found by reading the Blitz++ User’s Guide. Long answer: To compile blitz++ with intel c++ compiler, a file called bzconfig.h is required in blitz/intel/ folder. But there isn’t. Yes and yes. Blitz++ is supposed to generate the file itself. According to the Blitz++ User’s Guide blitz.pdf included in blitz-0.10.tar.gz, section “Installation”, … Read more

Swap rows with columns (transposition) of a matrix in javascript [duplicate]

DuckDucking turned up this by Ken. Surprisingly, it’s even more concise and complete than Nikita’s answer. It retrieves column and row lengths implicitly within the guts of map(). function transpose(a) { return Object.keys(a[0]).map(function(c) { return a.map(function(r) { return r[c]; }); }); } console.log(transpose([ [1,2,3], [4,5,6], [7,8,9] ]));

GCC: Array type has incomplete element type

It’s the array that’s causing trouble in: void print_graph(g_node graph_node[], double weight[][], int nodes); The second and subsequent dimensions must be given: void print_graph(g_node graph_node[], double weight[][32], int nodes); Or you can just give a pointer to pointer: void print_graph(g_node graph_node[], double **weight, int nodes); However, although they look similar, those are very different internally. … Read more

May I treat a 2D array as a contiguous 1D array?

Both lines do result in undefined behavior. Subscripting is interpreted as pointer addition followed by an indirection, that is, a[0][1234]/p[1234] is equivalent to *(a[0] + 1234)/*(p + 1234). According to [expr.add]/4 (here I quote the newest draft, while for the time OP is proposed, you can refer to this comment, and the conclusion is the … Read more