|
|
|
#define CUDATOOLS_IMPLEMENTATION
|
|
|
|
#include <Array.h>
|
|
|
|
#include <Core.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
CudaTools::Array<int> arr = CudaTools::Array<int>::constant({100}, 0);
|
|
|
|
arr.reshape({4, 5, 5}); // Creates a three dimensional array.
|
|
|
|
|
|
|
|
arr[0][0][0] = 1; // Axis by axis indexing.
|
|
|
|
arr[{1, 0, 0}] = 100; // Specific 'coordinate' indexing.
|
|
|
|
std::cout << arr << "\n";
|
|
|
|
|
|
|
|
CudaTools::Array<int> arrRange = CudaTools::Array<int>::range(0, 18);
|
|
|
|
auto arrSlice = arr.slice({{1, 3}, {1, 4}, {1, 4}}); // Takes a slice of the center.
|
|
|
|
std::cout << "Before Copy:\n" << arrSlice << "\n";
|
|
|
|
arrSlice = arrRange; // Copies arrRange into arrSlice. (Does NOT replace!)
|
|
|
|
std::cout << "After Copy:\n" << arrSlice << "\n";
|
|
|
|
|
|
|
|
std::cout << "Modified: \n"
|
|
|
|
<< arr << "\n"; // The original array is modified, since a slice does not copy.
|
|
|
|
|
|
|
|
CudaTools::Array<int> newArr = arr.copy(); // Copies the original Array.
|
|
|
|
for (auto it = newArr.begin(); it != newArr.end(); ++it) { // Iterate through the array.
|
|
|
|
*it = 1;
|
|
|
|
}
|
|
|
|
std::cout << "Modified New Array:\n" << newArr << "\n";
|
|
|
|
std::cout << "Old Array:\n" << arr << "\n"; // The original array was not modified after a copy.
|
|
|
|
return 0;
|
|
|
|
}
|