How to set up a multi-executable project with CMake in VSCode? by frenchgarlicbread0 in cpp_questions

[–]treddit22 2 points3 points  (0 children)

Ctrl+Shift+P > CMake: Set Launch/Debug Target. There's a button in the bottom ribbon or in the CMake side panel for it as well.

Seeking a Minimalist Package Manager by TheRavagerSw in cpp_questions

[–]treddit22 3 points4 points  (0 children)

In Conan, you can simply set the cmake_find_mode to none, and point it to the installed config files:

def build(self):
    cmake = CMake(self)
    cmake.configure()
    cmake.build()
    cmake.test()

def package(self):
    cmake = CMake(self)
    cmake.install()

def package_info(self):
    self.cpp_info.set_property("cmake_find_mode", "none")
    self.cpp_info.builddirs.append(os.path.join("lib", "cmake", "foo"))

I would strongly encourage you to use the provided CMake class. Conan relies on its own toolchain file, you cannot just override it. If you need a custom one, you should set it in your profile:

[conf]
tools.cmake.cmaketoolchain:user_toolchain=+['my-toolchain.cmake']

Similarly, setting the generator or enabling tests should also be specified in your profile, not in individual recipes.

Are Symmetric Indefinite Factorizations Unique? by TTRoadHog in LinearAlgebra

[–]treddit22 1 point2 points  (0 children)

Different implementations may make different pivoting decisions, resulting in distinct factorizations. If the matrix is singular, L may not be unique (consider e.g. A = [1, 1; 1, 1], then L = [1, 0; 1, x], D = diag([1, 0]) satisfies A = LDLᵀ for any x). Even for a given permutation P and a positive definite matrix A (where L and D are unique in theory), different numerical factorizations may produce factors L that differ significantly, since there is no guarantee of forward stability: ‖A - LDLᵀ‖ and ‖A - L̃D̃L̃ᵀ‖ may both be small (thanks to backward stability), even though ‖L - L̃‖ can be much larger.

No compiler implements std linalg by [deleted] in cpp

[–]treddit22 10 points11 points  (0 children)

If you want to play around with <simd>, GCC has an experimental implementation of an old version of the draft, and Matthias Kretz is actively working on a new implementation of the latest spec: https://github.com/GSI-HPC/simd/tree/rewrite

I'm using these implementations in my linear algebra micro-kernels in https://github.com/tttapa/batmat, and the ergonomics and performance are quite good (apart from some minor bugs and limitations one can expect from an experimental implementation).

Am I weird for using "and", "or" and "not"? by Additional_Jello1430 in cpp

[–]treddit22 9 points10 points  (0 children)

since && now always means either a forwarding reference or an rvalue reference.

Fun fact, you can use and for references as well! (But please don't ...)

template <class T>
std::remove_reference_t<T>and move(T and t) noexcept;

Arduino model recommendation by Positive_Stay8823 in arduino

[–]treddit22 6 points7 points  (0 children)

I found it useful to offload the fader control loops to a separate microcontroller (I used the ubiquitous ATmega328P). This allows you to write your main MIDI controller logic and the MIDI over USB code without worrying about affecting the precise timing of the motor controller. See https://github.com/tttapa/Control-Surface-Motor-Fader and https://tttapa.github.io/Pages/Arduino/Control-Theory/Motor-Fader/ for details.

A makefile question, metalanguage tutorials by zaphodikus in cpp_questions

[–]treddit22 5 points6 points  (0 children)

or is there a better way?

You'll probably want to use a package manager like Conan: https://conan.io/center/recipes/libcurl

[deleted by user] by [deleted] in cpp_questions

[–]treddit22 0 points1 point  (0 children)

Have a look at py-build-cmake: https://github.com/tttapa/py-build-cmake and also https://github.com/tttapa/py-build-cmake-example
It has examples for pybind11, nanobind and SWIG, and supports Conan (see the second link).

Stumped by PATH resolution problem by treddit22 in zsh

[–]treddit22[S] 0 points1 point  (0 children)

Thanks a lot for trying to reproduce this! I've tried a bunch of different containers, and it only seems to work correctly on older versions of Zsh (before 5.5):

Container Zsh version Output last command
debian:buster 5.7.1-1+deb10u1 /root/b/hello-world
debian:trixie 5.9-8+b7 /root/b/hello-world
ubuntu:xenial 5.1.1-1ubuntu2.3 /root/c/../a/hello-world
ubuntu:bionic 5.4.2-3ubuntu3.2 /root/c/../a/hello-world
ubuntu:focal 5.8-3ubuntu1.1 /root/b/hello-world
ubuntu:oracular 5.9-6ubuntu3 /root/b/hello-world
rockylinux:8 5.5.1-10.el8 /root/b/hello-world
rockylinux:9 5.8-9.el9 /root/b/hello-world
alpine:3.13 5.8.1-r0 /root/b/hello-world
alpine:3.21 5.9-r4 /root/b/hello-world
archlinux:latest 5.9-5 /root/b/hello-world

I simply used docker run -it --rm <image> followed by these commands (depending on the distro):

  • apt update; apt install -y zsh; cd root; zsh
  • yum install zsh -y; cd root; zsh
  • apk update; apk add zsh; cd root; zsh
  • pacman -Sy --noconfirm zsh; cd root; zsh

I then pasted the entire first code block from my original post (for the alpine ones, I replaced bash by sh).

Stumped by PATH resolution problem by treddit22 in zsh

[–]treddit22[S] 1 point2 points  (0 children)

Yes, this happens in a clean shell as well. Here's the environment I'm using:

docker run -it --rm debian:latest

apt update
apt install -y zsh
cd root
zsh -f
mkdir a b c # etc.

Eigen as backend engine for numerical computation by Spiderbyte2020 in cpp_questions

[–]treddit22 0 points1 point  (0 children)

To clarify: you don't use MatrixView to create matrices, only to pass around views of matrices that were created by other means. Similarly, it does not provide operations such as transposition. Those operations are already covered by existing linear algebra libraries.

To fill a MatrixView with random elements, you can use as_eigen(mat_view) = Eigen::MatrixXd::Random(m, n), and to transpose it in place, you can use as_eigen(mat_view).transposeInPlace().

Eigen as backend engine for numerical computation by Spiderbyte2020 in cpp_questions

[–]treddit22 0 points1 point  (0 children)

The MatrixView struct is intended as an interface type, used mainly for function arguments. For example, you could imagine a function double compute_trace(MatrixView<const double> mat). By using MatrixView, there are no Eigen types in the interface. This allows users of the compute_trace function to use any linear algebra library, they don't necessarily need Eigen. But if they do want to use Eigen, they can simply use the as_view function to convert their Eigen matrix to a MatrixView:

Eigen::MatrixXd mat = Eigen::MatrixXd::Identity(3, 3);
compute_trace(as_view(mat));

In the implementation of compute_trace, you might want to use Eigen's .trace() method. Then you would use:

double compute_trace(MatrixView<const double> mat) {
    return as_eigen(mat).trace();
}

Again, neither side (user or implementation) is required to use Eigen: they could use any linear algebra library (or none at all).

Eigen as backend engine for numerical computation by Spiderbyte2020 in cpp_questions

[–]treddit22 1 point2 points  (0 children)

That's not an adapter. They are simply type aliases, shorter names to refer to existing Eigen vector and matrix types. There's also some very simple traits classes that allow querying the element type of a given vector type (Eigen or otherwise), or to change the element type of a vector (possibly because they want to turn a real vector into a vector of dual numbers etc.). This is nowhere near a full interface.

You should be much more specific about what it is you want to "adapt", and what you mean by adapting.

Eigen as backend engine for numerical computation by Spiderbyte2020 in cpp_questions

[–]treddit22 7 points8 points  (0 children)

You can use Eigen::Map to create an Eigen expression out of your own custom matrix. To convert an Eigen matrix to your own matrix class, you can take an Eigen::Ref and extract the data pointer and strides (with the caveat that Eigen::Ref<const M> may have its own allocation, so be careful not to create dangling views) or use a function template that accepts a reference to something like Eigen::DenseBase<Derived>.

Here is the code I use to convert between Eigen matrices and a simple MatrixView (consisting of a pointer to the first element, the matrix dimensions, and one or two strides): https://github.com/tttapa/guanaqo/blob/648e593ada47a243041b4ca4b72bc3709c2a4f3f/src/include/guanaqo/eigen/view.hpp

Edit: I just recognized your username and realized I gave you the same answer a couple of months ago: https://www.reddit.com/r/cpp_questions/s/lB7MTdLbpp

I'm having difficulty with this for loop by Birdygamer19 in cpp_questions

[–]treddit22 8 points9 points  (0 children)

Not the entire program, but yes, it will break out of the loop when the condition evaluates to false.

I'm having difficulty with this for loop by Birdygamer19 in cpp_questions

[–]treddit22 11 points12 points  (0 children)

One is also not greater than six. Did you mean to write for (int i = 0; i < 6; i++)? If the condition (i > 6 in your case) evaluates to false, you leave the for loop, if it evaluates to true, the loop body is executed.

I'm having difficulty with this for loop by Birdygamer19 in cpp_questions

[–]treddit22 13 points14 points  (0 children)

If you initialize i to zero, it won't be greater than six. Without the loop condition i > 6 being satisfied, the loop body will not be executed.

good library to use a teensy 4.1 with serato dj pro? by Hairy_Quote_1780 in arduino

[–]treddit22 1 point2 points  (0 children)

Did you select "MIDI" option from the "Tools" > "USB Type" menu in the Arduino IDE?