@@ -36,7 +36,7 @@ class TestCSPRNG(unittest.TestCase):
3636
3737 size = 1000
3838
39- all_devices = ['cpu' , 'cuda' ] if csprng .supports_cuda () else ['cpu' ]
39+ all_devices = ['cpu' , 'cuda' ] if ( torch . cuda . is_available () and csprng .supports_cuda () ) else ['cpu' ]
4040
4141 def test_random_kstest (self ):
4242 for device in self .all_devices :
@@ -53,7 +53,7 @@ def test_random_kstest(self):
5353 res = stats .kstest (t .cpu (), stats .randint .cdf , args = (0 , to_inc ))
5454 self .assertTrue (res .statistic < 0.1 )
5555
56- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
56+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
5757 def test_random_cpu_vs_cuda (self ):
5858 for dtype in self .num_dtypes :
5959 gen = csprng .create_mt19937_generator (42 )
@@ -71,7 +71,7 @@ def test_random_to_kstest(self):
7171 res = stats .kstest (t .cpu (), stats .randint .cdf , args = (0 , to_ ))
7272 self .assertTrue (res .statistic < 0.1 )
7373
74- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
74+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
7575 def test_random_to_cpu_vs_cuda (self ):
7676 to_ = 42
7777 for dtype in self .num_dtypes :
@@ -92,7 +92,7 @@ def test_random_from_to_kstest(self):
9292 res = stats .kstest (t .cpu (), stats .randint .cdf , args = (from_ , to_ ))
9393 self .assertTrue (res .statistic < 0.2 )
9494
95- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
95+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
9696 def test_random_from_to_cpu_vs_cuda (self ):
9797 for dtype in self .num_dtypes :
9898 for from_ in [0 , 24 , 42 ]:
@@ -121,7 +121,7 @@ def test_random_bool(self):
121121 self .assertEqual (t .max (), True )
122122 self .assertTrue (0.4 < (t .eq (True )).to (torch .int ).sum ().item () / self .size < 0.6 )
123123
124- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
124+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
125125 def test_random_bool_cpu_vs_cuda (self ):
126126 gen = csprng .create_mt19937_generator (42 )
127127 cpu_t = torch .empty (self .size , dtype = torch .bool , device = 'cpu' ).random_ (generator = gen )
@@ -140,7 +140,7 @@ def test_uniform_kstest(self):
140140 res = stats .kstest (t .cpu ().to (torch .double ), 'uniform' , args = (from_ , (to_ - from_ )))
141141 self .assertTrue (res .statistic < 0.1 )
142142
143- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
143+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
144144 def test_uniform_cpu_vs_cuda (self ):
145145 for dtype in self .fp_ftypes :
146146 for from_ in [- 42 , 0 , 4.2 ]:
@@ -162,7 +162,7 @@ def test_normal_kstest(self):
162162 res = stats .kstest (t .cpu ().to (torch .double ), 'norm' , args = (mean , std ))
163163 self .assertTrue (res .statistic < 0.1 )
164164
165- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
165+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
166166 def test_normal_cpu_vs_cuda (self ):
167167 for dtype in self .fp_ftypes :
168168 for mean in [- 3 , 0 , 7 ]:
@@ -183,7 +183,7 @@ def test_log_normal_kstest(self):
183183 res = stats .kstest (t .cpu ().to (torch .double ), 'lognorm' , args = (std , 0 , math .exp (mean )))
184184 self .assertTrue (res .statistic < 0.1 )
185185
186- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
186+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
187187 def test_log_normal_cpu_vs_cuda (self ):
188188 for dtype in self .fp_ftypes :
189189 for mean in [- 3 , 0 , 7 ]:
@@ -203,7 +203,7 @@ def test_exponential_kstest(self):
203203 res = stats .kstest (t .cpu ().to (torch .double ), 'expon' , args = (0 , 1 / lambd ,))
204204 self .assertTrue (res .statistic < 0.1 )
205205
206- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
206+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
207207 def test_exponential_cpu_vs_cuda (self ):
208208 for dtype in self .fp_ftypes :
209209 for lambd in [0.5 , 1.0 , 5.0 ]:
@@ -223,7 +223,7 @@ def test_cauchy_kstest(self):
223223 res = stats .kstest (t .cpu ().to (torch .double ), 'cauchy' , args = (median , sigma ))
224224 self .assertTrue (res .statistic < 0.1 )
225225
226- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
226+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
227227 def test_cauchy_cpu_vs_cuda (self ):
228228 for dtype in self .fp_ftypes :
229229 for median in [- 10 , 0 , 50 ]:
@@ -245,7 +245,7 @@ def test_geometric(self):
245245 # res = stats.chisquare(actual, expected)
246246 # self.assertAlmostEqual(res.pvalue, 1.0, delta=0.5) TODO https://github.com/pytorch/csprng/issues/7
247247
248- @unittest .skipIf (not csprng .supports_cuda (), "csprng was not compiled with CUDA support" )
248+ @unittest .skipIf (not torch . cuda . is_available () or not csprng .supports_cuda (), "CUDA is not available or csprng was not compiled with CUDA support" )
249249 def test_geometric_cpu_vs_cuda (self ):
250250 for dtype in self .fp_ftypes :
251251 for p in [0.2 , 0.5 , 0.8 ]:
@@ -307,6 +307,7 @@ def measure(size):
307307 # Pessimistic check that parallel execution gives >= 1.5 performance boost
308308 self .assertTrue (time_for_1M / time_for_1K < 1000 / min (1.5 , torch .get_num_threads ()))
309309
310+ @unittest .skip ("Temporary disable because doesn't work on Sandcastle" )
310311 def test_version (self ):
311312 import torchcsprng .version as version
312313 self .assertTrue (version .__version__ )
0 commit comments