Pysyft: Implement Default numel Functionality for Base Tensor Type

Created on 10 Aug 2017  路  9Comments  路  Source: OpenMined/PySyft

User Story A: As a Data Scientist using Syft's Base Tensor type, I want to leverage a default method for computing operations on a Tensor of arbitrary type. For this ticket to be complete, numel() should return a new tensor. For a reference on the operation this performs check out PyTorch's documentation.

Acceptance Criteria:

  • If the Base Tensor type's attribute "encrypted" is set to True, it should return a NotImplemented error.
  • a unit test demonstrating the correct operation on the Base Tensor type implemented over int and float Tensors.
  • inline documentation in the python code. For inspiration on inline documentation, please check out PyTorch's documentation for this operator.
Help Wanted Type

All 9 comments

Shouldn't it be possible to compute the number of elements in a tensor even if it is encrypted?
For instance, in this notebook one can easily count the number of [e]s in the encrypted tensors.

Also: torch.numel() returns an integer, while the user story says numel() should return a tensor. Which one should PySyft implementation follow?

@baldassarreFe all your points are correct :)

I would like to work on that, cause it seems to be pretty simple. Anyway, I'm not very confident yet, so I'll try but if anyone wants to work on that too, please, feel free to do it :)

Now I have some doubts for @iamtrask, @baldassarreFe or anyone that could help.

If, as @baldassarreFe has suggested, numel() will return an integer, and the post is Returns the total number of elements in the Tensor. What's the point of implementing numel if we already have nelements and size?

size: Size of tensor
nelements: Returns the total number of elements in the tensor.

If it's just for having the operation named numel, as PyTorch, shouldn't we implement the count for encrypted tensors in size and nelement too as @baldassarreFe has also suggested?

nelement is just an alias for numel in PyTorch, so I suppose we have both to conform with PyTorch's methods.

Looking at PyTorch's documentation, it seems that their implementation of size returns a torch.Size subclass of tuple, as in:

>>> torch.Tensor(3, 4, 5).size()
torch.Size([3, 4, 5])

If we're seeking to mirror PyTorch, it looks like we'll probably need to change our current implementation of size.

As my personal opinion, I agree that size() should give us a tuple of dimensions, just like pytorch size(), while numel() and its alias nelement() should simply count the elements in the tensor, again like pytorch implementation

Waiting for @iamtrask to give us a last word ;)

I agree with @baldassarreFe & @joewie, these functions need to be modified.

Totally agree with you two, too!

Agreed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tblazina picture tblazina  路  3Comments

wentaiwu92 picture wentaiwu92  路  4Comments

swaroopch picture swaroopch  路  4Comments

akirahirohito picture akirahirohito  路  3Comments

iamtrask picture iamtrask  路  4Comments