终端输出信息:
```bash
UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
time_vector = time_vector // time_win_aggr
代码位置:
```python
def aggregate_by_time(time_vector,time_win_aggr):
time_vector = time_vector - time_vector.min()
time_vector = time_vector // time_win_aggr
return time_vector
解决办法:
把上述代码修改为下述代码即可:
def aggregate_by_time(time_vector,time_win_aggr):
time_vector = time_vector - time_vector.min()
time_vector = torch.div(time_vector, time_win_aggr, rounding_mode='trunc')
return time_vector
【以下回答由 GPT 生成】
根据给出的信息,问题是出现在PyTorch中的警告信息,即"UserWarning: floordiv is deprecated"。
警告信息指出,在未来版本的PyTorch中,__floordiv__
方法的行为将发生变化。目前的行为是向0('trunc'函数)舍入,而不是向下('floor')舍入。对于负值,会导致舍入错误。
为了解决这个问题,可以按照警告信息所提供的建议修改代码。具体来说是将 //
运算符替换为 torch.div
方法,并指定 rounding_mode='trunc'
参数。
以下是修改后的代码:
def aggregate_by_time(time_vector, time_win_aggr):
time_vector = time_vector - time_vector.min()
time_vector = torch.div(time_vector, time_win_aggr, rounding_mode='trunc')
return time_vector
通过使用 torch.div
方法并设置 rounding_mode='trunc'
参数,可以避免警告信息并解决问题。
希望对您有所帮助,如果还有其他问题,请随时提问!