     ! Compute the final shape
     [
         ! Compute the first dimension
-        [ 0 [ shape>> first + ] reduce 1array ]
+        [ [ shape>> first ] map-sum 1array ]
         ! Compute the other dimensions
         [ first shape>> rest ] bi  append
     ]


! Sum together all elements in the tensor
syntax:M: tensor sum vec>> 0 <simd-slice>
    [ simd-slice>> 0 [ sum + ] reduce ]
    [ end-slice>> sum ] bi + ;

<PRIVATE


! Flatten the tensor so that it is only one-dimensional
: flatten ( tensor -- tensor )
    dup shape>> product { } 1sequence >>shape ;

! outputs the number of dimensions of a tensor
: dims ( tensor -- n )
