HPL_dswap(3)

πŸ“¦ version 2.2, in fedora 43, fedora 44

πŸ’– HPL_dswap β€” bestie edition πŸ’–

okay so you're in the HPL Library Functions section of the manual, page HPL_dswap(3), and honestly? this one is a whole vibe. it's the glow-up where two vectors just... trade places. no cap. πŸ¦‹


✨ NAME ✨

HPL_dswap β€” y <-> x. that's it. that's the tweet. πŸ’…


🌸 SYNOPSIS 🌸

#include "hpl.h"

void HPL_dswap( const int N, double * X, const int INCX, double * Y,
const int INCY );

look at that signature. chef's kiss. πŸŽ€


πŸ’« DESCRIPTION πŸ’«

so HPL_dswap swaps the vectors x and y. like, fully swaps them. x becomes what y was, y becomes what x was, and they both walk away changed. it's giving identity crisis but make it math. πŸ”₯


πŸ‘‘ ARGUMENTS πŸ‘‘

  • N β€” (local input) const int β€” on entry, N specifies the length of the vectors x and y. N must be at least zero. yes bestie, zero is allowed. negative is not. don't try it. πŸ’€
  • X β€” (local input/output) double * β€” on entry, X is an incremented array of dimension at least ( 1 + ( n - 1 ) * abs( INCX ) ) that contains the vector x. on exit, the entries of the incremented array X are updated with the entries of the incremented array Y. so it's not just reading, it's receiving. main character energy. ✨
  • INCX β€” (local input) const int β€” on entry, INCX specifies the increment for the elements of X. INCX must not be zero. fr fr, zero is not the move here. 🚫
  • Y β€” (local input/output) double * β€” on entry, Y is an incremented array of dimension at least ( 1 + ( n - 1 ) * abs( INCY ) ) that contains the vector y. on exit, the entries of the incremented array Y are updated with the entries of the incremented array X. mutual exchange. mutual slay. 🫢
  • INCY β€” (local input) const int β€” on entry, INCY specifies the increment for the elements of Y. INCY must not be zero. same rule, same energy. πŸ’…

🌈 EXAMPLE 🌈

here's a lil demo, copy-paste ready, no thoughts head empty just swaps:

#include "hpl.h"

int main(int argc, char *argv[])
{
   double x[3], y[3];
   x[0] = 1.0; x[1] = 2.0; x[2] = 3.0;
   y[0] = 4.0; y[1] = 5.0; y[2] = 6.0;
   HPL_dswap( 3, x, 1, y, 1 );
   printf("x=[%f,%f,%f]\n", x[0], x[1], x[2]);
   printf("y=[%f,%f,%f]\n", y[0], y[1], y[2]);
   exit(0); return(0);
}

x comes in as 1.0, 2.0, 3.0, y comes in as 4.0, 5.0, 6.0, and after one call to HPL_dswap( 3, x, 1, y, 1 ) they've fully swapped. iconic behaviour, honestly. 😭


πŸ” SEE ALSO πŸ”

the girlies in the same friend group:

  • HPL_daxpy (3)
  • HPL_dcopy (3)
  • HPL_dscal (3)

πŸ’€ heads up: INCX and INCY must not be zero. and N must be at least zero. these aren't suggestions bestie, that's just the rules.

okay that's the whole page!! this was HPL 2.2, dated February 24, 2016 β€” yes she's an older queen but she still ate, and she's still serving swaps to this very day. go forth and swap responsibly. mwah. πŸ’–πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from