Example #1
0
 def __getattr__(self, name):
     torch_all = torchvision.transforms.transforms.__all__
     if name in torch_all:
         return torchvision.transforms.__getattribute__(name)
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(
                 f"module {name} not implemented in Torch or Heat")
Example #2
0
 def __getattr__(name):
     torch_all = torch.nn.modules.__all__
     if name in torch_all:
         return torch.nn.__getattribute__(name)
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(
                 f"module {name} not implemented in Torch or Heat")
Example #3
0
 def __getattr__(name):
     """
     When a function is called for the heat.nn module it will attempt to run the heat nn module with that
     name, then, if there is no such heat nn module, it will attempt to get the torch nn module of that name.
     """
     torch_all = torch.nn.modules.__all__
     if name in torch_all:
         return torch.nn.__getattribute__(name)
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(
                 f"module {name} not implemented in Torch or Heat")
Example #4
0
 def __getattr__(self, name):
     """
     When a function is called for the heat.vision_transforms module it will attempt to run the
     heat function/class with that name, then, if there is no such object, it will attempt to
     get the torchvision.transforms object of that name.
     """
     torch_all = torchvision.transforms.transforms.__all__
     if name in torch_all:
         return torchvision.transforms.__getattribute__(name)
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(f"module {name} not implemented in Torch or Heat")
Example #5
0
    def __getattr__(name):
        # this will call the Heat optimizers if available,
        # otherwise, it falls back to call a torch optimizer
        if name in dp_optimizer.__all__:
            return dp_optimizer.__getattribute__(name)

        try:
            return torch.optim.__getattribute__(name)
        except AttributeError:
            try:
                unittest.__getattribute__(name)
            except AttributeError:
                if name is not None:
                    raise AttributeError(
                        f"module {name} not implemented in torch.optim")
Example #6
0
 def __getattr__(self, name):
     if name in self.torch_all:
         return torch.nn.__getattribute__(name)
     elif name == "functional":
         return functional
     elif name in self.data_parallel_all:
         return data_parallel.__getattribute__(name)
     elif name == "tests":
         return tests
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(
                 f"module '{name}' not implemented in Torch or Heat")
Example #7
0
    def __getattr__(name):
        """
        When a function is called for the heat.optim module it will attempt to run the heat optimizer with that
        name, then, if there is no such heat optimizer, it will attempt to get the torch optimizer of that name.
        """
        # this will call the Heat optimizers if available,
        # otherwise, it falls back to call a torch optimizer
        if name in dp_optimizer.__all__:
            return dp_optimizer.__getattribute__(name)

        try:
            return torch.optim.__getattribute__(name)
        except AttributeError:
            try:
                unittest.__getattribute__(name)
            except AttributeError:
                if name is not None:
                    raise AttributeError(
                        f"module {name} not implemented in torch.optim")
Example #8
0
 def __getattr__(self, name):
     """
     When a function is called for the heat.nn module it will attempt to run the heat nn module with that
     name, then, if there is no such heat nn module, it will attempt to get the torch nn module of that name.
     """
     if name in self.torch_all:
         return torch.nn.__getattribute__(name)
     elif name == "functional":
         return functional
     elif name in self.data_parallel_all:
         return data_parallel.__getattribute__(name)
     elif name == "tests":
         return tests
     else:
         try:
             unittest.__getattribute__(name)
         except AttributeError:
             raise AttributeError(
                 f"module '{name}' not implemented in Torch or Heat")
Example #9
0
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
A set of tests for the Gengo API. They all require an internet connection.
"""

# @unittest.skip doesn't exist in Python < 2.7 so you will need unittest2
# from pip in this case
# pip install unittest2
import unittest
try:
    unittest.__getattribute__('skip')
except AttributeError:
    try:
        import unittest2 as unittest
    except ImportError:
        raise Exception("The unittest module is missing the " +
                        "required skip attribute. Either use " +
                        " Python 2.7, or `pip install unittest2`")

import os
import random
import time

from gengo import Gengo, GengoError, GengoAuthError

API_PUBKEY = os.getenv('GENGO_PUBKEY')
Example #10
0
	A set of tests for Gengo. They all require internet connections.
	In fact, this entire library and API requires an internet connection.
	Don't complain.

	Also keep in mind that all the test cases test against the Sandbox API,
	since... well, it makes more sense to do that. If you, for some odd reason,
	want/need to test against the regular API, modify the SANDBOX flag at the top
	of this file.

"""

# @unittest.skip doesn't exist in Python < 2.7 so you will need unittest2 from pip in this case
# pip install unittest2
import unittest
try:
    unittest.__getattribute__('skip')
except AttributeError:
    try:
        import unittest2 as unittest
    except ImportError:
        raise Exception(
            "The unittest module is missing the required skip attribute. Either use Python 2.7, or `pip install unittest2`"
        )

import random
import os
import time

from pprint import pprint
from mygengo import MyGengo, MyGengoError, MyGengoAuthError