Skip to content

Instantly share code, notes, and snippets.

@karlnapf
Last active July 23, 2016 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlnapf/28e1ea447d3d625f2205d303599fa4ff to your computer and use it in GitHub Desktop.
Save karlnapf/28e1ea447d3d625f2205d303599fa4ff to your computer and use it in GitHub Desktop.
// actual implementation
void scale(const Vector& a, float scale, Vector& output)
{
for (auto i=0; i<a.vlen; i++)
output[i]=a[i]*scale;
}
// wrapper, for syntatic ease, should be auto-generated
Vector& scale(const Vector& a, float scale)
{
output = allocate(a.vlen);
scale(a, scale, output);
retun output;
}
int size=2;
Vector a(size);
float scale=2;
// auto allocation
Vector b=scale(a, scale);
// manual buffer
Vector buffer(size);
scale(a, scale, output);
// inplace
scale(a, scale, a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment