Skip to content

Commit

Permalink
Support conversion between different clad::array instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Nov 19, 2024
1 parent 0bf8e21 commit 09f7d97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/clad/Differentiator/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ template <typename T> class array {

CUDA_HOST_DEVICE array(const array<T>& arr) : array(arr.m_arr, arr.m_size) {}

template <typename U>
CUDA_HOST_DEVICE array(const array<U>& arr)
: m_arr(new T[arr.size()]), m_size(arr.size()) {
(*this) = arr;
}

CUDA_HOST_DEVICE array(std::size_t size, const clad::array<T>& arr)
: m_arr(new T[size]), m_size(size) {
for (std::size_t i = 0; i < size; ++i)
Expand Down
10 changes: 10 additions & 0 deletions test/Misc/CladArray.C
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ int main() {
//CHECK-EXEC: 1 : 4
//CHECK-EXEC: 2 : 5

// clad::array<int> --> clad::array<long double>
clad::array<long double> type_conv_arr = clad_arr;

for (int i = 0; i < 3; i++) {
printf("%d : %.2Lf\n", i, type_conv_arr[i]);
}
//CHECK-EXEC: 0 : 1.00
//CHECK-EXEC: 1 : 2.00
//CHECK-EXEC: 2 : 3.00

test_arr -= arr_ref;
for (int i = 0; i < 3; i++) {
printf("%d : %d\n", i, test_arr[i]);
Expand Down

0 comments on commit 09f7d97

Please sign in to comment.