syft.lib package

Subpackages

Submodules

syft.lib.util module

syft.lib.util.generic_update_ast(lib_name, create_ast, ast_or_client)[source]
syft.lib.util.is_static_method(klass, attr)[source]

Test if a value of a class is static method.

Example:

class MyClass(object):
    @staticmethod
    def method():
        ...
Parameters
  • klass (type) – the class on which we want to check whether the method is statically implemented

  • attr (str) – the name of the method we want to check.

Returns

whether or not a method named <attr> is a static method of class <klass>

Return type

bool

syft.lib.util.copy_static_methods(from_class, to_class)[source]

Copies all static methods from one class to another class

This utility was initialized during the creation of the Constructor for PyTorch’s “th.Tensor” class. Since we replace each original constructor (th.Tensor) with on we implement (torch.UppercaseTensorConstructor), we also need to make sure that our new constructor has any static methods which were previously stored on th.Tensor. Otherwise, the library might look for them there, not find them, and then trigger an error.

Parameters
  • from_class (Type) – the class on which we look for static methods co copy

  • to_class (Type) – the class onto which we copy all static methods found in <from_class>

syft.lib.util.get_original_constructor_name(object_name)[source]

Generate name for original constructor

For each custom constructor, we move the original constructor to a consistent location relative to the original constructor so that each custom constructor automatically knows where to find the original method it is overloading. Namely, we move the original constructor to a different attr within the same module as the original constructor. This method specifies the naming convention that we use to name the original constructor when it is moved.

Args:

object_name (str): the original constructor’s original name

syft.lib.util.replace_classes_in_module(module, from_class, to_class, ignore_prefix=None)[source]

Recursively replace occurrence of from_class to to_class inside module.

For example, when syft replaces torch.nn.parameter.Parameter constructor, there’s also need to replace the same constructor in other modules that has already imported it.

Parameters
  • module (ModuleType) – top-level module to traverse

  • from_class – Original constructor

  • to_class – syft’s ObjectConstructor

syft.lib.util.full_name_with_qualname(klass)[source]
syft.lib.util.full_name_with_name(klass)[source]