| 103 | return ndarray |
| 104 | |
| 105 | def to_int_tensor(self, ndarray, requires_grad=False, is_deep_copy=True): |
| 106 | if ndarray is None: |
| 107 | return ndarray |
| 108 | |
| 109 | # this part is meaningless if tensor is in gpu |
| 110 | if is_deep_copy: |
| 111 | ndarray = copy.deepcopy(ndarray) |
| 112 | |
| 113 | if isinstance(ndarray, list) and len(ndarray) > 0: |
| 114 | var_ = [] |
| 115 | for v in ndarray: |
| 116 | temp = torch.from_numpy(v) |
| 117 | temp = temp.to(self.device) |
| 118 | temp.requires_grad = requires_grad |
| 119 | var_.append(temp) |
| 120 | return var_ |
| 121 | if isinstance(ndarray, dict) and len(ndarray) > 0: |
| 122 | var_ = {} |
| 123 | for k, v in ndarray.iteritems(): |
| 124 | temp = torch.from_numpy(v) |
| 125 | temp = temp.to(self.device) |
| 126 | temp.requires_grad = requires_grad |
| 127 | var_[k] = temp |
| 128 | |
| 129 | return var_ |
| 130 | |
| 131 | ndarray = torch.from_numpy(ndarray) |
| 132 | ndarray = ndarray.to(self.device) |
| 133 | ndarray.requires_grad = requires_grad |
| 134 | |
| 135 | return ndarray |
| 136 | |
| 137 | |
| 138 | class OrnsteinUhlenbeckActionNoise: |