99 | def astensor(self, tensor_in, dtype='float'): |
100 | """ |
101 | Convert to a PyTorch Tensor. |
102 | |
103 | Args: |
104 | tensor_in (Number or Tensor): Tensor object |
105 | |
106 | Returns: |
107 | torch.Tensor: A multi-dimensional matrix containing elements of a single data type. |
108 | """ |
109 | try: |
110 | dtype = self.dtypemap[dtype] |
111 | except KeyError: |
112 | log.error('Invalid dtype: dtype must be float, int, or bool.') |
113 | raise |
114 | |
115 | tensor = torch.as_tensor(tensor_in, dtype=dtype) |
116 | |
117 | try: |
118 | tensor.shape[0] |
119 | except IndexError: |
120 | tensor = tensor.expand(1) |
121 | return tensor |