Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sketch out conj method #46

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
16 changes: 12 additions & 4 deletions scratchpad/tn_api/tn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import math
from dataclasses import dataclass
from typing import TypeVar, Generic, Iterable
from qtree import np_framework

class Array(np.ndarray):
shape: tuple[int]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all instances of tuple[... because was getting error that types can't have [

shape: tuple

D = TypeVar('D') # tensor data type (numpy, torch, etc.)

Expand Down Expand Up @@ -52,16 +53,21 @@ class Port:
class TensorNetwork(TensorNetworkIFC[np.ndarray]):
tensors: Iterable[np.ndarray]
shape: tuple
edges: tuple[tuple[Port]]
edges: tuple

def __init__(self, *args, **kwargs):
self._tensors = []
self._edges = tuple()
self.shape = tuple()
self.buckets = []
self.data_dict = {}

# slice not inplace
def slice(self, slice_dict: dict) -> 'TensorNetwork':
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danlkv thanks for the previous comment, i believed i've addressed that in this update

...
tn = self.copy()
sliced_buckets = np_framework.get_sliced_np_buckets(self.buckets, self.data_dict, slice_dict)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i imagine data_dict needs to be populated for this to be meaningful logic. is that something the callers should pass in? @danlkv

tn.buckets = sliced_buckets
return tn

def copy(self):
new = TensorNetwork()
Expand Down Expand Up @@ -153,4 +159,6 @@ def __repr__(self):




if __name__ == "__main__":
tn = TensorNetwork.new_random_cpu(2, 3, 4)
import pdb; pdb.set_trace()
Loading