-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from mtsokol/lazy-api
API: Lazy API
- Loading branch information
Showing
5 changed files
with
343 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from functools import wraps | ||
|
||
from .julia import jl | ||
from .tensor import Tensor | ||
|
||
|
||
def compiled(func): | ||
@wraps(func) | ||
def wrapper_func(*args, **kwargs): | ||
new_args = [] | ||
for arg in args: | ||
if isinstance(arg, Tensor) and not jl.isa(arg._obj, jl.Finch.LazyTensor): | ||
new_args.append(Tensor(jl.Finch.LazyTensor(arg._obj))) | ||
else: | ||
new_args.append(arg) | ||
|
||
result = func(*new_args, **kwargs) | ||
result_tensor = Tensor(jl.Finch.compute(result._obj)) | ||
|
||
return result_tensor | ||
|
||
return wrapper_func | ||
|
||
|
||
def lazy(tensor: Tensor): | ||
if tensor.is_computed(): | ||
return Tensor(jl.Finch.LazyTensor(tensor._obj)) | ||
return tensor | ||
|
||
|
||
def compute(tensor: Tensor): | ||
if not tensor.is_computed(): | ||
return Tensor(jl.Finch.compute(tensor._obj)) | ||
return tensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.