TensorNetwork icon indicating copy to clipboard operation
TensorNetwork copied to clipboard

repr for Tensor

Open mganahl opened this issue 5 years ago • 8 comments

We need to add a useful __repr__ to Tensor

mganahl avatar Sep 06 '20 08:09 mganahl

Shape and type seems like a useful information. Should we have a string representation of an array as part of Tensor repr?

It seems to me that Tensor class is used with linalg functions, in this case it might be annoying to call Tensor.array to examine array's content. What do you think?

gaxler avatar Sep 08 '20 20:09 gaxler

I think the repr of the underlying array is fine.

gaxler [email protected] schrieb am Di. 8. Sep. 2020 um 22:18:

Shape and type seems like a useful information.

Should we have a string representation of an array as part of Tensor repr?

It seems to me that Tensor class is used with linalg functions, in this case it might be annoying to call Tensor.array to examine array's content. What do you think?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/TensorNetwork/issues/814#issuecomment-689113201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7RWE3FY7LQ2VBUD7EI3UTSE2GS3ANCNFSM4Q4DQXYA .

mganahl avatar Sep 08 '20 20:09 mganahl

Agreed. I think we'd be ok to to fall back on however the underlying array does it's __repr__ + some extra info?

chaserileyroberts avatar Sep 08 '20 20:09 chaserileyroberts

If we gonna use underlying repr we might get a lot of duplicate info in the repr or inconsistent repr depending on the backend.

e.g. TensorFlow has shape and dtype, pytorch and numpy might have dtype

<tf.Tensor: shape=(10, 10, 10), dtype=float32, numpy=...> array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int16)

So maybe just shape + type and leave the rest for Tensor.array?

EDIT:

We can also generate consistent reprs in the backend, but that's probably too much for this

gaxler avatar Sep 08 '20 20:09 gaxler

Hey, does this still need to be done? I'm interested in working on it but this would be my first open-source contribution which is a little daunting.

wkostuch avatar Sep 28 '20 00:09 wkostuch

Hi! This is addressed in PR #823. You can add @alewis' comments to #823 if you want!

mganahl avatar Sep 28 '20 07:09 mganahl

Hey, does this still need to be done? I'm interested in working on it but this would be my first open-source contribution which is a little daunting.

I think we're good for this one (although indeed you could make the small change suggested in #823 as a first step). However, we have many things that would be a great way to dip your toes into contributing. #840 in particular would have you moving around through most of the code, making small changes, and writing tests - having done it you should be pretty much equipped to do anything. I'd be thrilled to walk you through it if you're interested.

alewis avatar Sep 28 '20 12:09 alewis

@alewis I'll go pop over to #840, thanks for the suggestion!

wkostuch avatar Sep 28 '20 21:09 wkostuch