anchor.diff:     different representations of the same data. See @MAT-BASICS for a
      tuturialish treatment."))
   
  +;;; Faster version of CFFI:FOREIGN-TYPE-SIZE.
  +(declaim (inline ctype-size))
  +(defun ctype-size (ctype)
  +  (if (eq ctype :float)
  +      4
  +      8))
  +
   (defmethod initialize-instance :after ((mat mat) &key initial-contents
                                          &allow-other-keys)
     (unless (listp (mat-dimensions mat))
       (setf (slot-value mat 'dimensions)
             (list (mat-dimensions mat))))
  -  (setf (slot-value mat 'size) (reduce #'* (mat-dimensions mat)))
  +  (setf (slot-value mat 'size) (mat-size-from-dimensions (mat-dimensions mat)))
     (unless (slot-boundp mat 'max-size)
       (setf (slot-value mat 'max-size)
             (+ (mat-displacement mat) (mat-size mat))))
     (assert (<= (+ (mat-displacement mat) (mat-size mat)) (mat-max-size mat)))
     (setf (slot-value mat 'n-bytes)
  -        (* (mat-max-size mat) (cffi:foreign-type-size (mat-ctype mat))))
  +        (* (mat-max-size mat) (ctype-size (mat-ctype mat))))
     (when (mat-initial-element mat)
       (setf (slot-value mat 'initial-element)
             (coerce-to-ctype (mat-initial-element mat)
                              :ctype (mat-ctype mat))))
     (when initial-contents
       (replace! mat initial-contents)))
  +
  +;;; Optimized version of (REDUCE #'* DIMENSIONS).
  +(defun mat-size-from-dimensions (dimensions)
  +  (let ((product 1))
  +    (declare (type index product)
  +             (optimize speed))
  +    (dolist (dimension dimensions)
  +      (declare (type index dimension))
  +      (setq product (the! index (* product dimension))))
  +    product))
   
   (defun mat-dimension (mat axis-number)
     "Return the dimension along AXIS-NUMBER. Similar to
  
positive.code: 
  (defmethod make-facet* ((mat mat) (facet-name (eql 'foreign-array)))
    (assert (or (eq *foreign-array-strategy* :dynamic)
                ;; It may be that this backing array was allocating when
                ;; *FOREIGN-ARRAY-STRATEGY* was :PIN-BACKING-ARRAY so it
                ;; is not static.
                (and (eq *foreign-array-strategy* :static-backing-array)
  
negative.code:   copied over and the old matrix is destroyed with DESTROY-CUBE if
    DESTROY-OLD-P."
    (let* ((dimensions (alexandria:ensure-list dimensions))
           (size (mat-size-from-dimensions dimensions)))
      (if (<= (+ displacement size) (mat-max-size mat))
          (reshape-and-displace! mat dimensions displacement)
          (prog1
  