11
11
from pathlib import Path
12
12
from typing import Iterator
13
13
14
- from arrayfire_wrapper .defines import AFArray
15
-
16
14
from .version import ARRAYFIRE_VER_MAJOR
17
15
18
16
VERBOSE_LOADS = os .environ .get ("AF_VERBOSE_LOADS" , "" ) == "1"
@@ -37,7 +35,7 @@ def is_cygwin(cls, name: str) -> bool:
37
35
class _BackendPathConfig :
38
36
lib_prefix : str
39
37
lib_postfix : str
40
- af_path : Path
38
+ af_path : Path | None
41
39
af_is_user_path : bool
42
40
cuda_found : bool
43
41
@@ -175,7 +173,7 @@ def __iter__(self) -> Iterator:
175
173
176
174
177
175
class Backend :
178
- _backend_type : BackendType
176
+ _backend_type : BackendType | None
179
177
_clibs : dict [BackendType , ctypes .CDLL ]
180
178
181
179
def __init__ (self ) -> None :
@@ -297,51 +295,15 @@ def _find_nvrtc_builtins_lib_name(self, search_path: Path) -> str | None:
297
295
return f .name
298
296
return None
299
297
300
- # unified backend functions
301
- def get_active_backend (self ) -> str :
302
- if self ._backend_type == BackendType .unified :
303
- from arrayfire_wrapper .lib .unified_api_functions import get_active_backend as unified_get_active_backend
304
-
305
- return unified_get_active_backend ()
306
- raise RuntimeError ("Using unified function on non-unified backend" )
307
-
308
- def get_available_backends (self ) -> list [int ]:
309
- if self ._backend_type == BackendType .unified :
310
- from arrayfire_wrapper .lib .unified_api_functions import (
311
- get_available_backends as unified_get_available_backends ,
312
- )
313
-
314
- return unified_get_available_backends ()
315
- raise RuntimeError ("Using unified function on non-unified backend" )
316
-
317
- def get_backend_count (self ) -> int :
318
- if self ._backend_type == BackendType .unified :
319
- from arrayfire_wrapper .lib .unified_api_functions import get_backend_count as unified_get_backend_count
320
-
321
- return unified_get_backend_count ()
322
- raise RuntimeError ("Using unified function on non-unified backend" )
323
-
324
- def get_backend_id (self , arr : AFArray , / ) -> int :
325
- if self ._backend_type == BackendType .unified :
326
- from arrayfire_wrapper .lib .unified_api_functions import get_backend_id as unified_get_backend_id
327
-
328
- return unified_get_backend_id (arr )
329
- raise RuntimeError ("Using unified function on non-unified backend" )
330
-
331
- def get_device_id (self , arr : AFArray , / ) -> int :
332
- if self ._backend_type == BackendType .unified :
333
- from arrayfire_wrapper .lib .unified_api_functions import get_device_id as unified_get_device_id
334
-
335
- return unified_get_device_id (arr )
336
- raise RuntimeError ("Using unified function on non-unified backend" )
337
-
338
298
@property
339
- def backend_type (self ) -> BackendType :
299
+ def backend_type (self ) -> BackendType | None :
340
300
return self ._backend_type
341
301
342
302
@property
343
303
def clib (self ) -> ctypes .CDLL :
344
- return self ._clibs [self ._backend_type ]
304
+ if self ._backend_type :
305
+ return self ._clibs [self ._backend_type ]
306
+ raise RuntimeError ("No valid _backend_type" )
345
307
346
308
347
309
# Initialize the backend
0 commit comments