func debug()

in Sources/TensorUtils/MLMultiArray+Utils.swift [162:197]


    func debug(_ indices: [Int]) -> String {
        func indent(_ x: Int) -> String {
            String(repeating: " ", count: x)
        }

        // This function is called recursively for every dimension.
        // Add an entry for this dimension to the end of the array.
        var indices = indices + [0]

        let d = indices.count - 1 // the current dimension
        let N = shape[d].intValue // how many elements in this dimension
        var s = "["
        if indices.count < shape.count { // not last dimension yet?
            for i in 0..<N {
                indices[d] = i
                s += debug(indices) // then call recursively again
                if i != N - 1 {
                    s += ",\n" + indent(d + 1)
                }
            }
        } else { // the last dimension has actual data
            s += " "
            for i in 0..<N {
                indices[d] = i
                s += "\(self[indices as [NSNumber]])"
                if i != N - 1 { // not last element?
                    s += ", "
                    if i % 11 == 10 { // wrap long lines
                        s += "\n " + indent(d + 1)
                    }
                }
            }
            s += " "
        }
        return s + "]"
    }