/robowaifu/ - DIY Robot Wives

Advancing robotics to a point where anime catgrill meidos in tiny miniskirts are a reality!

alogs.space e-mail has been restored. You may now reach me using "admin" at this domain. -r

We are back. - TOR has been restored.

Canary update coming soon.

Max message length: 6144

Drag files to upload or
click here to select them

Maximum 5 files / Maximum size: 20.00 MB

More

(used to delete files and postings)


“At the timberline where the storms strike with the most fury, the sturdiest trees are found.” -t. Hudson Newsletter


Open file (81.61 KB 601x203 python_logo.png)
Open file (15.21 KB 1600x1600 c++_logo.png)
Robowaifu Programming & Learning Thread Greentext anon 04/22/2025 (Tue) 13:37:49 No.37647
A thread for links, examples, & discussion for software development & instruction; primarily intended to focus on Python & C++ & C . Additionally, other systems-oriented (eg, Forth, Ada); and other scripting-oriented (eg, Lua), &tc., programming language discussions are welcome. * Try to keep it practical! (ie, realworld-oriented) (eg, not Scratch language, or similar) Obviously the endgoal here ITT being discussing/providing the crafting of quality code & systems for our robowaifus. --- > threads-related: ( >>19777 ) ( >>12 ) ( >>159 ) ( >>14409 ) ( >>18749 ) ( >>4969 ) ( >>86 ) ( >>128 ) --- * Corpo-tr*on languages (+ other corpo & 'coffee du juor' languages) will be yeet'd ITT! (They have no place in serious opensource robowaifu systems discussions.) >tl;dr Take it to /meta . :^) >=== -add'l crosslink -add'l languages
Edited last time by Chobitsu on 05/26/2025 (Mon) 19:11:55.
I'll just leave this here for now. <---> C++26 Senders/Receivers [1] Async : Partition Sorting, & OpenCV -based [2] Image Processing Examples https://accu.org/journals/overload/33/185/teodorescu/ --- 1. https://en.cppreference.com/w/cpp/execution 2. https://docs.opencv.org/4.11.0/
>image-processing related cv::Mat tr_apply_mask(const cv::Mat& img_main, const cv::Mat& img_mask); cv::Mat tr_blur(const cv::Mat& src, int size); cv::Mat tr_to_grayscale(const cv::Mat& src); cv::Mat tr_adaptthresh(const cv::Mat& img, int block_size, int diff); cv::Mat tr_reducecolors(const cv::Mat& img, int num_colors) cv::Mat tr_oilpainting(const cv::Mat& img, int size, int dyn_ratio); auto tr_cartoonify(const cv::Mat& src, int blur_size, int num_colors, int block_size, int diff); auto error_to_exception(); std::vector<std::byte> read_file(const fs::directory_entry& file); void write_file(const char* filename, const std::vector<unsigned char>& data); exec::task<int> process_files(const char* in_folder_name, const char* out_folder_name, int blur_size, int num_colors, int block_size, int diff); int main() { auto everything = process_files("data", "out", blur_size, num_colors, block_size, diff); auto [processed] = stdexec::sync_wait(std::move(everything)).value(); printf("Processed images: %d\n", processed); return 0; } auto tr_cartoonify(const cv::Mat& src, int blur_size, int num_colors, int block_size, int diff) { auto sched = exec::get_system_scheduler(); stdexec::sender auto snd = stdexec::when_all( stdexec::transfer_just(sched, src) | error_to_exception() | stdexec::then([=](const cv::Mat& src) { auto blurred = tr_blur(src, blur_size); auto gray = tr_to_grayscale(blurred); return tr_adaptthresh(gray, block_size, diff); }), stdexec::transfer_just(sched, src) | error_to_exception() | stdexec::then([=](const cv::Mat& src) { return tr_reducecolors(src, num_colors); })) | stdexec::then([](const cv::Mat& edges, const cv::Mat& reduced_colors) { return tr_apply_mask(reduced_colors, edges); }); return snd; } auto error_to_exception() { return stdexec::let_error([](auto e) { if constexpr (std::same_as<decltype((e)), std::exception_ptr>) return stdexec::just_error(e); else return stdexec::just_error( std::make_exception_ptr(std::runtime_error("other error"))); }); } exec::task<int> process_files(const char* in_folder_name, const char* out_folder_name, int blur_size, int num_colors, int block_size, int diff) { exec::async_scope scope; exec::static_thread_pool io_pool(1); auto io_sched = io_pool.get_scheduler(); auto cpu_sched = exec::get_system_scheduler(); int processed = 0; for (const auto& entry : fs::directory_iterator(in_folder_name)) { auto extension = entry.path().extension(); if (! entry.is_regular_file() || (extension != ".jpg") && (extension != ".jpeg")) continue; auto in_filename = entry.path().string(); auto out_filename = (fs::path(out_folder_name) / entry.path().filename()).string(); printf(“Processing % s\n”, in_filename.c_str()); auto file_content = co_await (stdexec::schedule(io_sched) | stdexec::then([=] { return read_file(entry); })); stdexec::sender auto work = ... scope.spawn(std::move(work)); } co_await scope.on_empty(); co_return processed; } stdexec::sender auto work = stdexec::transfer_just(cpu_sched, cv::_InputArray::rawIn(file_content)) | error_to_exception() | stdexec::then([=](cv::InputArray file_content) -> cv::Mat { return cv::imdecode(file_content, cv::IMREAD_COLOR); }) | stdexec::let_value([=](const cv::Mat& img) { return tr_cartoonify(img, blur_size, num_colors, block_size, diff); }) | stdexec::then([=](const cv::Mat& img) { std::vector<unsigned char> out_image_content; if (! cv::imencode(extension, img, out_image_content)) { throw std::runtime_error("cannot encode image"); } return out_image_content; }) | stdexec::continues_on(io_sched) | stdexec::then([=](const std::vector<unsigned char>& bytes) { write_file(out_filename.c_str(), bytes); }) | stdexec::then([=] { printf("Written %s\n", out_filename.c_str()); }) | stdexec::then([&] { processed++; });
Edited last time by Chobitsu on 04/22/2025 (Tue) 14:20:24.
>via learncpp.com Here's a straightforward example of testing what C++ standard your compiler is currently using, directly inside your code: > read_cpp_standard.cpp : /* minimal build & run: g++ read_cpp_standard.cpp -std=c++14 -o read_std && ./read_std */ #include <algorithm> #include <iostream> #include <map> #include <string> using std::cerr; using std::cout; using std::find_if; using std::map; using std::string; //------------------------------------------------------------------------------ /** read the compiler's C++ standard version code number * * @return code number */ long get_cpp_standard() { // Visual Studio is non-conforming in support for __cplusplus (unless you set // a specific compiler flag, which you probably haven't). in Visual Studio // 2015 or newer we can use _MSVC_LANG instead. see // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ #if defined(_MSVC_LANG) return _MSVC_LANG; #elif defined(_MSC_VER) // if we're using an older version of Visual Studio, bail out return -1; #else // __cplusplus is the intended way to query the language standard code (as // defined by the language standards) return __cplusplus; #endif } //------------------------------------------------------------------------------ /** the program's entry point * * outputs the compiler's C++ language colloquial version number to console * * @return exit status code - 0/'success' implicitly; any other value is failure */ int main() { auto const this_std = get_cpp_standard(); if (this_std == -1) { cerr << "ERROR: Unable to determine your compiler's C++ language " "standard\n"; return -1; } //--- // note: the C++26 std_code is a placeholder since the exact code won't be // determined until the standard is finalized map<long, string> const std_codes{{199711L, "Pre-C++11"}, {201103L, "C++11"}, {201402L, "C++14"}, {201703L, "C++17"}, {202002L, "C++20"}, {202302L, "C++23"}, {202604L, "C++26"}}; auto const it = find_if(std_codes.cbegin(), std_codes.cend(), // note: replace the below C++ lambda with this version for C++11: /* [this_std](decltype(*std_codes.cbegin())& e) { return e.first == this_std; }); */ [this_std](auto const& e) { return e.first == this_std; }); if (it != std_codes.cend()) // code found cout << "Compiler's C++ standard: " << it->second << '\n'; else // code not found cout << "Compiler is not using one of the " << std_codes.size() << " C++ standards: (" << this_std << "L)\n"; } // see: // https://www.learncpp.com/cpp-tutorial/what-language-standard-is-my-compiler-using/ // https://en.cppreference.com/w/cpp/container/map // https://en.cppreference.com/w/cpp/algorithm/find // https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros // https://en.cppreference.com/w/cpp/feature_test possible output: Compiler's C++ standard: C++20
Edited last time by Chobitsu on 04/23/2025 (Wed) 14:07:30.
Open file (799.11 KB 2354x1608 read_std_main.png)
Open file (640.57 KB 2354x1608 read_std_meson.png)
I admit I don't really know much about AI or programming, so what I'm about to say is probably redundant. Recently I was thinking about themed characters making puns and wordplay based on their theme. Six degrees of separation (which I guess would be a semantic network) was the first thing that came to mind on making the AI pick words more closely related to their theme. This could be extended to include similarities in syllable structure for some puns, like a dog-girl being more likely to use the word "rough" or "roughly" because it sounds like "ruff" which is closely related to "dog". But I don't know how a system would work that allows the AI to come up with new words. By that I mean anything from a terrible catgirl pun "pawful" as a conjunction of "paw" and "awful", but also the way humans reuse or combine words to make new ones when they can't or don't think to look-up if it exists already. The first example of this I think of is was a little girl who didn't know the word "died", but seemed to know what death and ghosts were said "his ghost fell out" when someone died. Although it might be a better example to say when people put "-ish" when approximating something.
Open file (371.18 KB 2048x2048 1732894383289072.jpg)
>>37652 Yes, these are all interesting questions, Anon. IMO (while ultimately programming solutions will be needed for the 'rubber to meet the road') for the moment at least, this is more of a Cognitive (or even a Philosophy) robowaifu topic (cf. >>24783 ) I'd think. Cheers, Anon. :^)
Lol, you're awesome, Greentext anon! My apologies & thanks!! I only meant to trouble you for the OP itself -- not to migrate the whole thing over! Thanks very kindly, Anon. Cheers. :^)
>>37653 >(or even a Philosophy) robowaifu topic I figured some of the former part of the post could be done with a semantic network, but no idea how to do the latter part. It's really not a philosophical question.
>>37706 >I figured some of the former part of the post could be done with a semantic network, but no idea how to do the latter part. Yeah, I can totally see that. Surely some software or other will be needed to accomplish all this in the end! :D >It's really not a philosophical question. I can understand that position. However my take on all this is that the entire domains of both sapience & cognition are only but vaguely-understood; to the degree such that they fall fairly into the realm of Philosophies; unlike say, Chemistry, Geology, Mechanics, Astrophysics, Optics & EM, &tc. -- the studies of which are all clearly within the so-called 'hard' Sciences of today. Thanks, Anon. Cheers. :^)
Edited last time by Chobitsu on 04/23/2025 (Wed) 11:27:02.
>C++ Modules have been greatly improved. https://gcc.gnu.org/gcc-15/changes.html My body is ready
> (unitree robo programming -related : >>37869, >>37873 )
Edited last time by Chobitsu on 04/27/2025 (Sun) 01:50:40.
Online tutorial-style learning for Python. https://pythonprogramming.net/python-fundamental-tutorials/
>>37878 >related: Video Python learning playlist (sentdex 's): https://www.youtube.com/playlist?list=PLQVvvaa0QuDeAams7fkdcwOGBpGdHpXln
Contrived (toy) program to demonstrate why you should use std::unique_ptrs instead of raw pointers in your C++ code. >tl;dr Don't use pointers outside of C++ handles (ie, RAII resource-management classes) in the first place; but if you do, ensure they are unique_ptr (for the simple ownership case). >muh_pointer_leaks.cpp #include <memory> #include <vector> using std::make_unique; using std::vector; /** leaks an int * * @param leak : function leaks whether true or false */ void use(bool const leak) { auto p1 = make_unique<int>(7); // OK int* p2 = new int{7}; // bad: might leak // ... no assignment to p2 ... if (leak) return; // ... no assignment to p2 ... vector<int> v(7); v.at(7) = 0; // exception thrown here (std::out_of_range: vector) delete p2; // too late to prevent leaks // ... } int main() { // this function call leaks either way (either true or false argument) : // use(true); // use(false); // this throws an exception as well } // https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es24-use-a-unique_ptrt-to-hold-pointers
Edited last time by Chobitsu on 05/05/2025 (Mon) 11:36:14.
>>38228 If any'non's trying to work through such an issue, I'll post another example showing how this should be done instead (of this intentionally-wrong, learning example).
Contrived (toy) program to demo that a function should perform a single logical operation. While it may require more coding text initially, the benefits of functions being easier to reason about individually; easier to combine/rewrite together in flexible ways (and generally more-reliably so at that); and the improved ease-of-maintenance 'down the road' thereby more than pay off that upfront cost -- many fold. >muh_simple_funcs.cpp #include <iostream> using std::cin; using std::cout; using std::istream; using std::ostream; int read_int(istream& is) { int x; is >> x; // check for errors return x; } void print_int(ostream& os, int x) { os << x << '\n'; } void read_and_print_int() { auto x = read_int(cin); print_int(cout, x); } int main() { read_and_print_int(); } // https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f2-a-function-should-perform-a-single-logical-operation
Edited last time by Chobitsu on 05/05/2025 (Mon) 22:55:56.
Contrived (toy) program to demo that you should specify noexcept if a C++ function can't/shouldn't throw an exception. The first func's reason is that the local (interior) function calls can't throw (b/c they're both C library functions). The second func's reason is that we want the program to simply crash (in this contrived, learning example case) instead of throwing an exception if the computer's memory becomes exhausted. >muh_noexcepts.cpp #include <cmath> #include <cstdio> #include <vector> using std::puts; using std::vector; double compute(double d) noexcept { return log(sqrt(d <= 0 ? 1 : d)); } /** will crash rather than throw * * @param v : (too large a) vector expected * @return : munged copy of v (mayn't get here -- could crash first) */ vector<double> munge(vector<double> const& v) noexcept { puts("entered munge()..."); vector<double> v2(v.size()); // throws if memory becomes exhausted (ignored) // ... do something munge'y ... return v2; } int main() { [[maybe_unused]] auto foo = compute(4.); puts("init'g vecs..."); vector<double> muh_big_vec(10'000'000'000); // program may fail here, auto bar = munge(muh_big_vec); // or here puts("vec init'g done."); // shouldn't reach here on many machines (crashes) } // https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Re-noexcept
Edited last time by Chobitsu on 05/06/2025 (Tue) 23:13:19.
Contrived demo to show why functions shouldn't throw exceptions while enclosing the direct owner of a freestore object (this also applies to other low-level, C-style resources like filehandles, ports, locks, etc.) The first example function will leak upon it's exception throw, b/c that function's int-pointer p directly 'owns' (ie, is solely responsible for the lifetime management of) the int located on the freestore memory it points to... and -- being a C-style pointer -- it.is. braindead! :DD The other two functions will not leak, b/c they instead use well-behaved, robustly-managed C++ RAII resource handles to their underlying data (similarly-located on the freestore memory). The second example uses a std::unique_ptr (an RAII resource handle), which always cleans up after itself regardless of the function's exit scenario (ie, throwing or not-throwing, in that case). Same for the third example which uses a std::vector (again, an RAII resource handle); it will also do proper cleanup by destroying that object at the end of it's enclosing function's scope (or, more-technically: at the end of the vector's lifetime [so... copy-elision, etc., may 'move' it out into another scope in some other example's context]). >tl;dr Just say no to using old C-style pointers outside of creating your own RAII-compliant resource handle classes (from within your own custom C++ library code, ofc) in the first place. But if you still want/need to, use std::unique_ptr (or possibly, std::shared_ptr in some cases) instead for reliable, automatic, resource lifetime management (cf. >>38228 ). >muh_resource_handles_do_proper_cleanups.cpp #include <cstdio> #include <exception> #include <iostream> #include <memory> #include <string> #include <vector> using std::cerr; using std::make_unique; using std::puts; using std::string; using std::vector; // silly custom exception class for demo purposes; inherits from std::exception class Get_me_out_of_here : public std::exception { public: // constructor accepts a const char* that is used to set the exception message Get_me_out_of_here(const char* message) : msg{message} {} // overrides the baseclass' what() method to return our message instead const char* what() const noexcept { return msg.c_str(); } private: string msg; }; void leak(int x) // don't: might leak { // C-style pointer auto p = new int{7}; // wont cleanup itself; requires explicit delete'g if (x < 0) throw Get_me_out_of_here{"lol, b/c why not leak?"}; // might leak *p // ... delete p; // we might never get here } void no_leak(int x) { // C++ unique_ptr auto p = make_unique<int>(7); // C++ RAII-compliant; always cleans itself up if (x < 0) throw Get_me_out_of_here{"lol, b/c why not _NOT_ leak?"}; // ... // no need for delete'g p } // <== std::unique_ptr cleanup occurs here; end of enclosing function's scope void no_leak_simplified() { vector<int> v(7); // vector, a C++ RAII resource-handle, cleans itself up // ... puts("look ma, no leaks! :D"); } // <== std::vector cleanup occurs here; end of enclosing function's scope int main() { // example function call #1 : try { leak(-1); // leaks } catch (Get_me_out_of_here const& e) { // catch, then // handle our custom exception cerr << "caught exception: " << e.what() << '\n'; } // example function call #2 : try { no_leak(-1); // doesn't leak } catch (Get_me_out_of_here const& e) { // catch, then // handle our custom exception cerr << "caught exception: " << e.what() << '\n'; } // example function call #3 : no_leak_simplified(); // doesn't leak } // https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#e13-never-throw-while-being-the-direct-owner-of-an-object // https://en.cppreference.com/w/cpp/language/raii >outputs: caught exception: lol, b/c why not leak? caught exception: lol, b/c why not _NOT_ leak? look ma, no leaks! :D
Edited last time by Chobitsu on 05/10/2025 (Sat) 00:22:22.
Here's a neat little C language teaching tool. Be a leet haxxor in just minutes! :^) https://sundee.neocities.org/c/
>>38295 >and -- being a C-style pointer -- it.is. braindead! :DD Its true. But this project aims to actually give C-pointers some smarts (at a fair cost, to be sure), to help improve the memory safety of the systems: https://github.com/pizlonator/llvm-project-deluge I certainly don't have any intentions of using it upfront, but once we have a working RW Foundations (cf. >>14409 ) system up and reasonably stable, then exploring some of the concepts here (double registers, 'capabilities', etc.) might be a really good idea as a part of a dedicated effort to further harden the overall system against (((attack$$$))). I suppose we'll see. I'd think that non-realtime sections of our code could bear the costs in time & space well-enough, and the benefits should be apparent to all -- particularly for any external-facing, data-validating code. [1] Cheers. :^) https://www.youtube.com/watch?v=JTxIWXWTAXM https://www.youtube.com/watch?v=yyFI7NgyySE --- 1. For example, recompiling cURL using Fil-C would be a no-brainer; its the primary external data-communications vehicle for the robowaifu's Dollnet/Dolldrop comms-physical-lockout component, of the Dollhouse subsection of RW Foundations.
Edited last time by Chobitsu on 05/11/2025 (Sun) 02:46:28.
If someone ever comes to /robowaifu/ demanding that our software be rewritten in r*st, you'll know that they aren't to be trusted even for a moment. Simple as. https://trashchan.xyz/robowaifu/manage/thread/26.html#1001
Bare Metal C: Embedded Programming for the Real World 1FDD4243365E3E5404C6478E531A5FD8 >related: http://oualline.com/ https://www.st.com/en/evaluation-tools/nucleo-f030r8.html >=== -consolidate hotlinks together
Edited last time by Chobitsu on 05/19/2025 (Mon) 10:34:05.
>>38595 Great resources. While C++ is my goto for most every higher-level type functionality (executive, cognition, object-detection, world-modelling, route-planning, etc.), C is literally unbeatable for many embedded programming situations -- especially where realtime is involved! * Cheers, Anon. :^) --- * Say you need to write some rock-solid, stable & reliable, super-fast code for the little $0.08 dumb-as-a-rock MCU that sits managing/watching-over your robowaifu's elbow (or knee, &tc.) joint rotations...and communicating back up to the robowaifu's SBC 'brain cluster' on how that elbow is currently performing (angle, derivative rotation-rate, response-latency, power-consumption, w/e). And thats all this chip does -- just the one thing; all day erry day. You don't want to have to drag C++ runtime dependencies into that tiny chip's memory (and it mayn't even fit, in many cases). For such a task, C is the only right answer! :D
Edited last time by Chobitsu on 05/19/2025 (Mon) 22:28:37.
>>38595 >>38620 > (related : >>367 )
I mentioned zeptoforth and found a doc page and if you scroll down it has several book links telling you how to program with forth. https://github-wiki-see.page/m/tabemann/zeptoforth/wiki/Getting-Started-with-zeptoforth Here's the software. https://github.com/tabemann/zeptoforth It's set up for Raspberry Pi Pico W which is now my pick for the best, cheap, but no tariff micro-controller. Many will disagree but as far as ease of programming, speed and speed of actually creating programs I think forth run rings around C however contrary this may sound. I used HP calculators a lot so this sort of stack based RPN calculating comes natural to me. In fact once you use a HP RPN calculators all others are vile contraptions that cause nothing but trouble to use. RPN notation is smooth and follows logically all the steps of computation. I would say that programming in the large is not forth's strength as it can get hard to follow but for small stuff, which is what happens with MC, I don't think there's much that is any better. So anyways if you don't like it fine but I provided links for those that have interest.
>>38704 Thanks, Grommet! I'll think about an edit I can make to the OP ITT to better welcome other languages. Thanks for your recommendations. Cheers, Anon. :^) <---> Done.
Edited last time by Chobitsu on 05/26/2025 (Mon) 17:45:19.
Smol walkthrough on getting simple inferencing up & running using llamacpp. Focuses on aspects of the C++ code itself as well. https://medium.com/data-science/llama-cpp-writing-a-simple-c-inference-program-for-gguf-llm-models-12bc5f58505f
Now that I've graduated college, what code editor and compiler should I use? When I was in college It was a requirement for me to use Visual Studios. What does /robowaifu/ recommend I use?
>>38991 Congrats, Anon!! Big event in your life, savor it. :^) >what code editor and compiler should I use? I use juCi++ & g++ [1] as my own daily-driver when I have the choice (if you don't know already, just like in Uni, your workplace will likely require you to use a specific toolchain). So, what's the big plan now, Anon? Have any personal side projects already going? Anything in mind that you want to pursue learning much-deeper in? Regardless, again congratulations. Cheers. :^) --- 1. A tutorial of sorts was created for Anons on /robowaifu/ to follow along, if they wanted to. (cf. >>4969 )

Report/Delete/Moderation Forms
Delete
Report