Skip to content

Commit

Permalink
Add CUDA support for arange
Browse files Browse the repository at this point in the history
Also enables CUDA for range
  • Loading branch information
fmassa authored and soumith committed Jul 19, 2017
1 parent cfcf2af commit bd6263c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions generic/THCTensorMath.cu
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,15 @@ void THCTensor_(range)(THCState *state, THCTensor *r_, accreal xmin, accreal xma
THCudaCheck(cudaGetLastError());
}

void THCTensor_(arange)(THCState* state, THCTensor *r_, accreal xmin, accreal xmax, accreal step) {
#if defined(THC_REAL_IS_FLOAT) || defined(THC_REAL_IS_DOUBLE) || defined(THC_REAL_IS_HALF)
int m = fmod(xmax - xmin, step) == 0;
#else
int m = (xmax - xmin) % step == 0;
#endif
if (m)
xmax -= step;
THCTensor_(range)(state, r_, xmin, xmax, step);
}

#endif
1 change: 1 addition & 0 deletions generic/THCTensorMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ THC_API void THCTensor_(logspace)(THCState *state, THCTensor *r_, real a, real b
#endif

THC_API void THCTensor_(range)(THCState *state, THCTensor *r_, accreal xmin, accreal xmax, accreal step);
THC_API void THCTensor_(arange)(THCState *state, THCTensor *r_, accreal xmin, accreal xmax, accreal step);

#endif

0 comments on commit bd6263c

Please sign in to comment.