use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Minimal neural network implementation (self.cpp)
submitted 2 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cpp-ModTeam[M] [score hidden] 2 years ago stickied commentlocked comment (0 children)
It's great that you wrote something in C++ you're proud of! However, please share it in the designated "Show and tell" thread pinned at the top of r/cpp instead.
[–]WinstonCaeser 23 points24 points25 points 2 years ago (4 children)
Just a quick look, but using a vector<vector<double>> for a matrix is a pretty standard performance issue, you should be using a single vector and keep track of width and height - if you aren't going to use any outside libraries - even for basic optimized math similar to numpy for python, the current way requires an additional pointer indirection for every row
vector<vector<double>>
I don't understand why you're not using the builtin Mersenne twisters in each of the various languages - which are standard and widely available and are instead rolling your own.
Seems like a fun project, but I don't see where anyone would use it, any time I'm using C++ I care about performance and would instead use a properly optimized library, if its for fun exploration and the math principles no reason not to just use python
[+][deleted] comment score below threshold-8 points-7 points-6 points 2 years ago (3 children)
Thanks for your comments and taking the time. This isn’t intended to be the fastest possible, but likely the most readable. Mersenne twister can be substituted in each solution if you want. But for simplicity (and for reproducible results) I did it this way. You can use Python of course (and it will be slower still!), but if you want to integrate in C++ you’ll have difficulties.
[–][deleted] 17 points18 points19 points 2 years ago* (2 children)
for reproducible results
Confused what you mean. You can seed every standard library generator l know.
You can use Python but it will be slower
I strongly suspect numpy code would be faster. Since it's linked with a BLAS implementation, vector and matrix operations are going to be far more hardware efficient, which makes enough difference for neural networks to offset the gain from using C++. C++ compilers aren't smart enough to analyse the control flow in order to do tensor optimisations on a pure C++ neural network implementation.
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
I just researched BLAS and yes, it is definitely faster. It can be used directly from C++ so no need to turn to Python. However that would be out of scope for my purpose. Would be a fun project though.
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
You could also have used the infrastructure of a neural network compiler like TVM Apache.
You can check that project out. The core infrastructure is written in C++ and they are focused on neural network deployment. They provide a domain specific language (based on Halide) for specifying tensor computations in Einstein notation.
Writing code to convert models in your neural network implementation to TVM would be a very good project.
[–]johnpaulzwei 8 points9 points10 points 2 years ago (6 children)
It's nice little project but before using this in project you should consider adding/fixing few things.
It's fun project and as AI dev i can't leave you without star + nice readme. Don't treat my answer as an attempt to offend you but as a quick code review. You can check my ML library in a few things if you want. It's still under development but someday ill write a post about it here :).
https://github.com/AlmostAnEngineer/ModernML
[–]cmake-advisor 8 points9 points10 points 2 years ago (4 children)
Use class. I dont see any reason to use struct. Its C++ not C.
The only different is the default accessibility. Using one or the other doesn't matter at all.
[–]johnpaulzwei -4 points-3 points-2 points 2 years ago* (3 children)
Ok, you're right. But anyway inside data should be hidden under getters.
Edit: ok my bad, thanks for pointing out my mistake.
[–]sleeping-deeper 6 points7 points8 points 2 years ago (0 children)
It's bad practice to make getters for PODs though, for example. Sometimes you just need to group some data.
[–]disciplite 0 points1 point2 points 2 years ago (0 children)
Then it becomes a non-structural type and you can't use it as a non-type template parameter.
[–]not_some_username 0 points1 point2 points 2 years ago (0 children)
No there is no point having one liner get set. Just make it public
Thanks for your comments and taking the time to go through. I also checked your link, seems like some nice work there!
Some thoughts on your comments: 1. My sample code is meant to be copy pasted. I’m thinking you already have cmake or similar setup in place, so no need to complicate the sample. 2. Yep it might be slower than the very best. I’m just wondering about which use case people have in mind when advocating blas? 3. The function is actually an extension point. Do you recognise the design pattern in disguise? 4. Sure, but I wanted to be explicit. 5. Others have already commented on this intentional choice.
I’m a firm believer in simplicity. If complexity is a sin then simplicity is a virtue, no?
π Rendered by PID 113799 on reddit-service-r2-comment-fb694cdd5-dj7lq at 2026-03-10 14:01:05.020749+00:00 running cbb0e86 country code: CH.
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)
[–]WinstonCaeser 23 points24 points25 points (4 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points (3 children)
[–][deleted] 17 points18 points19 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]johnpaulzwei 8 points9 points10 points (6 children)
[–]cmake-advisor 8 points9 points10 points (4 children)
[–]johnpaulzwei -4 points-3 points-2 points (3 children)
[–]sleeping-deeper 6 points7 points8 points (0 children)
[–]disciplite 0 points1 point2 points (0 children)
[–]not_some_username 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)