Average C codebase

This is supposed to be a high-performance neural network analysis tool but the authors decided to write it in C and use jagged arrays for everything.

Just look at this shit. I bet it could be twice as fast an infinitely more readable by using C++ with a proper fucking linear algebra library like Armadillo. Yet, there are still boomers who promote C.

github.com/tcwangshiqi-columbia/Neurify

Attached: Screenshot_2019-02-03_19-37-15.png (916x399, 63K)

>(float****)

Attached: 1547496555465.gif (300x300, 1.27M)

>but the authors decided to write it in C and use jagged arrays for everything.
Welcome to the enjoyable world of code written by mathematicians, OP. They can't code for shit.

At least it looks like they've used proper variable names, instead of regular math notation.

>I bet it could be twice as fast
Prove it or STFU.

That's some sexy ass triple indirection, I'm not gonna lie.

Attached: hime check em.jpg (751x1063, 378K)

It's probably written that way to minimize cache misses

>(float ****)
defend this Cniles

Attached: 15.jpg (680x793, 41K)

>4 start programmer

Attached: enlightenment-d352lyf.jpg (737x1083, 256K)

>I bet it could be twice as fast an infinitely more readable by using C++ with a proper fucking linear algebra library like Armadillo.
Prove it.

>Yet, there are still boomers who promote C.
idk none of the people behind that project look like boomers to me

explain to me OpenBLAS
what does it do? what CPU features does it utilize?
how does it functionally differ from OpenCL?

One day I will promote from three star to four star programmer.
One day...

>casting malloc
This code was clearly written by some c++ shitter.

Attached: 1272706855909.jpg (194x300, 12K)

This is straightforward and readable. I don't know why you're complaining, OP.

"Proper variable names" tend to make numerical programs less readable if anything, as it deviates from the literature. I get that it's difficult to grasp for "outsiders", but trust me, when verbose variable names are tacked onto often terrible code, it gets even worse.

I do agree that a lot of people doing numerics suck at programming. Most of the time programming is something that's picked up on the side to solve problems in their main area of study, so it makes sense really.

boomers love casting malloc and typedef'ing their structs and function pointers

he should use lib that handles allocations rather than implementing his own shit.

ftfy
nnet->matrix = xmalloc(sizeof(float *) * nnet->num_layers);
for (layer = 0; layer < nnet->num_layers; layer++) {
nnet->matrix[layer] = xmalloc(sizeof(float *) * 2);
nnet->matrix[layer][0] = xmalloc(sizeof(float *) * nnet->num_layers[layer + 1]);
nnet->matrix[layer][1] = xmalloc(sizeof(float *) * nnet->num_layers[layer + 1]);
for (row = 0; row < nnet->num_layers[layer + 1]; row++) {
nnet->matrix[layer][0][row] = xmalloc(sizeof(float) * nnet->num_layers[layer]);
nnet->matrix[layer][1][row] = xmalloc(sizeof(float));
}
}

also isn't there some requirements for memory alignment for most SIMD instructions? Does just asking for malloc fulfills this?

it's very good for C++ compiler compatibility.

so is extern "C" {}

ok, but what if you wanted to branch your code to be C++ then? rewrite all of your mallocs or just cast them from the get go?

yes, rewrite them to proper C++

>I bet it could be twice as fast an infinitely more readable by using C++
Or a better language for numerical computing, like Fortran or Julia.

While mathematicians often write terrible code, this doesn't look like code written by mathematicians, and the developer is a CS PhD.

If they cared about that they wouldn't be using a (float ****) they would have 1 flat array and use math to convert a 4D index to a 1D index for lookups / insertions.

And there are still better ways to do this then that.

that code is terrible for cache locality. it's just pointer chasing all the time.

>It's probably written that way to minimize -(cache misses)
Sorry, forgot the parens.

Why is he calling malloc like 100 times for the same object?
Every single data point in the entire net is going to be in a different place on the heap.
What the fuck is wrong with making a struct neuron? Having a layer be an array of neurons? With pointers between layers? At least allocate each LAYER in one malloc, Jesus.

Attached: unnamed.jpg (200x200, 9K)

Flat, singly malloc'd multdimensional arrays with array offsets calculated manually are the only way to write dynamically allocated arrays without destroying cache locality.

Attached: K&R c.png (1000x1400, 1.31M)

So I looked at it and it's a bit confusing. I realize this is in part due to not understanding how neural networks work. I think if I know how they should work, I would make a layer struct like this, store everything inside the member bytes, and use pointer arithmetic to get the other members. What do you think?
struct layer {
struct layer *prev, *next;
int size;
char bytes[];
};

float *get_weights(struct layer *ptr)
{
...
}