                                  ;; in the adjacency-matrix: Decides with which
                                  ;; of the `attributes' the object has an edge with.
                                  ;; Starts the row with `i' zeros.
-                                 (vec (concat (take i (repeat 0))
-                                              (map
-                                                (fn [attribute]
-                                                  (if (incident? context object attribute)
-                                                    1
-                                                    0))
-                                                attributes))))]
-    (vec (concat
-           ;; Concat the rows corresponding to an object...
-           (map #(compute-row-for-object (objects %)
-                                         attributes
-                                         (- m %))
-                (range 0 m))
-           ;; ... with the rows correpsonding to attributes.
-           (map #(vec (take (- n %) (repeat 0)))
-                (range 0 n))))))
+                                 (concat (take i (repeat 0))
+                                         (map
+                                           (fn [attribute]
+                                             (if (incident? context object attribute)
+                                               1
+                                               0))
+                                           attributes)))]
+    (into-array (map int-array (concat
+                                 ;; Concat the rows corresponding to an object...
+                                 (map #(compute-row-for-object (objects %)
+                                                               attributes
+                                                               (- m %))
+                                      (range 0 m))
+                                 ;; ... with the rows correpsonding to attributes.
+                                 (map #(take (- n %) (repeat 0))
+                                      (range 0 n)))))))
 
 (defn- compute-row-for-object-or-attribute-matrix
   "Tis is a helper-function to initialize the adjacency-matrix

  attributes as vertices and the edges defined via the incidence-relation.
  The edges of the graph have no direction, therefore just the upper entrys
  a_ij with i<=j have to be stored."
  [context]
  (assert (context? context) "Argument must be a formal context!")
  (let [objects (vec (objects context))
        attributes (vec (attributes context))


;;; Average-shortest-path

;;The following two marcros are adapted from
;;http://clojure-goes-fast.com/blog/java-arrays-and-unchecked-math/.
(defmacro two-dimensional-aget [a i j]
  `(aget ^"[I" (aget ~a ~i) ~j))

(defmacro two-dimensional-aset [a i j v]
  `(aset ^"[I" (aget ~a ~i) ~j ~v))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn- floyd-step
  "This is a helper-function for average-shortest-path:
  Do one overwriting in the floyd-algorithm, see
  https://de.wikipedia.org/wiki/Algorithmus_von_Floyd_und_Warshall or
  https://en.wikipedia.org/wiki/Floyd-Warshall_algorithm for Details."
  [^"[[I" matrix ^Integer k ^Integer i ^Integer j]
  (assert (<= i j) "No computation under the diagonalelements possible!")
  (let [A_ij (two-dimensional-aget matrix i (- j i))
        A_ik (if (<= i k)
               (two-dimensional-aget matrix i (- k i))
               (two-dimensional-aget matrix k (- i k)))
        A_kj (if (<= k j)
               (two-dimensional-aget matrix k (- j k))
               (two-dimensional-aget matrix j (- k j)))
        ^Integer newvalue (cond
                            (and (= A_ij 0) (or (= A_ik 0) (=  A_kj 0))) 0
                            (= A_ij 0) (+ A_ik A_kj)
                            (or (= A_ik 0) (=  A_kj 0)) A_ij
                            :else (min A_ij (+ A_ik A_kj)))]
    (two-dimensional-aset matrix i (- j i) newvalue)))

(defn average-shortest-path
  "Computes the average-shortest path for a given `context' and a `projection'.
