This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> //memcpy implemented here | |
// Copy pointer y from x | |
void copy_pointer(double *y, const double *x, size_t n){ | |
// The size in memcpy is byte length! | |
std::memcpy(y, x, n * sizeof(double)); | |
} | |
int main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// Return vector y = x * x | |
void manipulate(double *y, double *x, size_t n){ | |
/* x and y must be initialized! */ | |
std::cout << "Inside the function" << std::endl; | |
std::cout << "Size of x?: " << | |
sizeof(x) << " " | |
<< "Size of y?: " | |
<<sizeof(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <random> | |
int main() { | |
std::mt19937_64 gen(42); | |
std::uniform_real_distribution<double> uni(-10.0, 10.0); | |
double *numbers = new double[20]; | |
/*use std::generate to fill the array pointer with lambda function*/ | |
std::generate(numbers, &numbers[20], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
#include <iostream> | |
int main() | |
{ | |
std::random_device device; | |
/* Or use any number replace the device() */ | |
std::mt19937 generator(device()); | |
std::uniform_int_distribution<int> distribution(1,6); | |
NewerOlder