449049 (15) [Avatar] Offline
Although the dataset isn't yet in the book's repo. I was able to download it without much hassle since you provided the source. I made sure I was using the right one by checking it's dimensions. Everything worked fine until the following line:
daily_bikes = bikes.view(-1, 24, bikes.shape[1])

This line attempts to break the dataset into batches of daily (24 hours) segments. However this produces the following error:
RuntimeError: invalid argument 2: size '[-1 x 24 x 17]' is invalid for input with 295443 elements

My guess: The storage is holding 295443 elements. If we try to divide that by the other two dimensions (24*17) the result is a decimal number. So inferring the first dimension via -1 won't work?

Solution: If we remove the last 3 rows from the dataset, the total number of elements in storage is reduced to 295392, which is divisible by the other two dimensions (24*17).
total_elements = 295443
for i in range(295443):
    total_elements -= 17
    if total % (24*17) == 0:

Now the line works as intended. I imagine you had prepped the raw data from the source so it would just work, but you forgot to add it to the repo. ;-)
bikes = bikes[sorted_row_idxs]
bikes_test = bikes[:-3, :]
bikes_test = bikes_test.view(-1, 24, bikes.shape[1])
Luca Antiga (4) [Avatar] Offline
Thank you for your assistance on Ch4 (again). And apologies for the glitches with Ch4.

You're correct, we had slightly edited the bike sharing dataset and didn't post it back on the repository. I'm going to fix this by this weekend.

Thanks again
321640 (1) [Avatar] Offline
The underlying problem is that view may only fold an array into evenly sized chunks, thus B x C x L must be == to the number of elements in the backing storage array.

IMHO the following is the correct way to resolve this:

batch = 24
rows = bikes.shape[0] - bikes.shape[0] % batch
bikes[:rows, :].view(-1, batch, bikes.shape[1]).size()

torch.Size([724, 24, 17])