Splits a tensor into a specific number of chunks. Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by chunks.

tch_chunk(x, chunks, dim)

Arguments

x

tensor object

chunks

number of chunks to return

dim

dimension along which to split the tensor

Examples

x <- tensor(array(runif(100), dim = c(4, 5, 5))) tch_chunk(x, 2, 0)
#> [[1]] #> tensor #> (1,.,.) = #> 0.0704 0.8476 0.9479 0.1381 0.8091 #> 0.1366 0.7954 0.3542 0.6777 0.1300 #> 0.2251 0.9203 0.3692 0.2445 0.1187 #> 0.7776 0.7690 0.6687 0.4388 0.0335 #> 0.1487 0.5110 0.6287 0.2972 0.0688 #> #> (2,.,.) = #> 0.7423 0.8536 0.4074 0.2813 0.3655 #> 0.9302 0.8866 0.4558 0.7007 0.7919 #> 0.9833 0.6160 0.1267 0.9263 0.4582 #> 0.6583 0.1281 0.4681 0.3505 0.0433 #> 0.6407 0.5438 0.4526 0.2906 0.8644 #> [ Variable[CPUFloatType]{2,5,5} ] #> #> [[2]] #> tensor #> (1,.,.) = #> 0.5492 0.8034 0.5147 0.7069 0.2527 #> 0.6511 0.6000 0.2200 0.0684 0.3559 #> 0.1090 0.4357 0.7399 0.5027 0.5237 #> 0.2592 0.5386 0.5382 0.4765 0.7921 #> 0.2012 0.2418 0.8880 0.8597 0.0771 #> #> (2,.,.) = #> 0.6345 0.0239 0.9815 0.4422 0.8561 #> 0.5287 0.4328 0.0818 0.9585 0.9643 #> 0.0699 0.8973 0.9559 0.9355 0.8371 #> 0.9183 0.1290 0.3310 0.9662 0.2027 #> 0.7436 0.8031 0.7842 0.1933 0.4310 #> [ Variable[CPUFloatType]{2,5,5} ] #>