r/Cplusplus • • 22d ago

Question Designing a C++ ML library from scratch — would you prefer A.transpose() or transpose(A) or A.T()?

/r/cpp_questions/comments/1xvde4p/designing_a_c_ml_library_from_scratch_would_you/
2 Upvotes

5 comments sorted by

•

u/AutoModerator 22d ago

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.

  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.

  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/cfeck_kde 22d ago

B = A.transposed(), if A is not modified, otherwise, A.transpose().

Ideally, offer both inplace transpose and transposed assignment.

1

u/Reifendruckventil 22d ago

In python i prefer np.transpose(A), the language doesnt matter 

1

u/JazzlikeDamage6351 22d ago

A.T() in no case. Logic is explicit therefore all code needs to be explicit.

Other than that, I personally do not see that much of a difference. You can think of it in terms of semantics: is the object performing an operation or is an operation performed on an object?

Since we're talking about matrices then the answer would be transpose(A).

1

u/JazzlikeDamage6351 22d ago

On second thought I would add both.

transpose(A) returns a new matrix B, this is used if you still need A after the operation.

A.transposed() modifies A in place, this is used when you do no need the old state, avoiding the construction of a new matrix