Live data from Hacker News

Tinn: A tiny neural network library written in C99

github.com

51–60 of 62 posts

Re: Tinn: A tiny neural network library written in C99

#51
post #40

Earlier quoted context omitted.

It might be easier to answer if you explained why you think it would be better. There may be cases where by-reference (yes, that's an absolutely acceptable thing to say, even in C) is more efficient: If the struct is a kind of "this pointer" (as in object-oriented programming) that is passed to a bunch of functions but relatively rarely used , then passing it by reference causes much less register pressure. Passing i…

> There may be cases where by-reference (yes, that's an absolutely acceptable thing to say, even in C) I don't want to be nit-picking. But I would like to know why "by-reference" is an acceptable thing to say. When I learnt C, C++, Java, etc. I was repeatedly told that pass by reference exists only in C++. In C, a pointer is passed by value. In Java, a reference is passed by value. Doesn't calling "pass pointer by va…

C implements the concept 'pass by reference' using the mechanism of 'pointer passed by value'.

You have no problem using the terms 'loop' or 'recurse' to describe C code, right? But these high-level ideas are implemented without using those terms in the code. Same with 'pass by reference'.

Re: Tinn: A tiny neural network library written in C99

#52
post #14

Earlier quoted context omitted.

This does nor preclude the use of threads or SIMD. Essentially this library is a demo toy that will need a lot to work to make useful in real conditions.

> Essentially this library is a demo toy It's 200 lines of C, what were you expecting?

Expected about 100 lines more for actual performance. ;)

Re: Tinn: A tiny neural network library written in C99

#53
post #3

Single core? No AVX? What's the point of writing it in C?

A thing of beauty happens when you write simple code in C and C++: the compiler has a field-day optimizing ad-nauseum. look at all those zmm(AVX-512) registers being used if your architecture supports it (on top of all the inlining and unrolling)!

godbolt link of the source + assembly -- all I did was combine the header, source and test files:

https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaP...

Re: Tinn: A tiny neural network library written in C99

#54

kann [0] is a similarly small neural network library written in pure C. It's quite fast for CPU-only, but only applicable for rather small problems. [0] https://github.com/attractivechaos/kann

It is fair to say KANN "only applicable for rather small problems". However, KANN is not so "similar" to Tinn. Tinn only implements MLP with a single hidden layer. KANN supports a lot more features such as 1D/2D convolution, RNN/LSTM, weight sharing and mini-batching. It is also more optimized.

Re: Tinn: A tiny neural network library written in C99

#55

kann [0] is a similarly small neural network library written in pure C. It's quite fast for CPU-only, but only applicable for rather small problems. [0] https://github.com/attractivechaos/kann

It is fair to say KANN "only applicable for rather small problems". However, KANN is not so "similar" to Tinn. Tinn only implements MLP with a single hidden layer. KANN supports a lot more features such as 1D/2D convolution, RNN/LSTM, weight sharing and mini-batching. It is also more optimized.

You're absolutely right that kann is more optimized and full-featured. I thought to mention your library because it is also a very portable neural network library written in C.

kann is a stunning piece of engineering, and your code is magnificent, and that is precisely why I mentioned it. I apologize, I did not clearly express my intent.

Re: Tinn: A tiny neural network library written in C99

#56

Earlier quoted context omitted.

It is fair to say KANN "only applicable for rather small problems". However, KANN is not so "similar" to Tinn. Tinn only implements MLP with a single hidden layer. KANN supports a lot more features such as 1D/2D convolution, RNN/LSTM, weight sharing and mini-batching. It is also more optimized.

You're absolutely right that kann is more optimized and full-featured. I thought to mention your library because it is also a very portable neural network library written in C. kann is a stunning piece of engineering, and your code is magnificent, and that is precisely why I mentioned it. I apologize, I did not clearly express my intent.

I just meant to add some clarification. I actually do appreciate that you mentioned it. Thank you!

Re: Tinn: A tiny neural network library written in C99

#58
post #19

Just curious, is there a reason for passing around the Tinn struct by-value? Will it get optimized?

Hi, I'm glouw.

Structs on the stack I pass by value. Structs on the heap I pass by pointer. It's a mental thing that I find helps with large codebases.

Re: Tinn: A tiny neural network library written in C99

#59
post #30

Earlier quoted context omitted.

I just pointed out that this is a very basic code. It's definitely not something I would use in any real life scenario(see other posts itt). And if you want to learn about NN you'd be better off googling something like 'backpropagation example' as this project does is virtually not documented. I personally don't find it useful and it takes up the space that can be filled with more interesting content. How is that 'sh…

It's a refreshingly clean, tiny library without dependencies that can do some cool stuff. Let people like things. Stop shitposting.

Thankyou for the kind words.

Re: Tinn: A tiny neural network library written in C99

#60
post #19

Just curious, is there a reason for passing around the Tinn struct by-value? Will it get optimized?

Hi, I'm glouw. Structs on the stack I pass by value. Structs on the heap I pass by pointer. It's a mental thing that I find helps with large codebases.

Unrelated but thanks for making this! The code is clean and easy to follow.

- a student trying to get a better grasp on neural networks

Post reply on HN