File: Mat.jl

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (49 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Adapted from IndirectArray

struct Mat{T <: dtypes} <: AbstractArray{T,3}
    mat
    data_raw
    data

    @inline function Mat{T}(mat, data_raw::AbstractArray{T,3}) where {T <: dtypes}
        data = reinterpret(T, data_raw)
        new{T}(mat, data_raw, data)
    end

    @inline function Mat(data_raw::AbstractArray{T, 3}) where {T <: dtypes}
        data = reinterpret(T, data_raw)
        mat = nothing
        new{T}(mat, data_raw, data)
    end
end

function Base.deepcopy_internal(x::Mat{T}, y::IdDict) where {T}
    if haskey(y, x)
        return y[x]
    end
    ret = Base.copy(x)
    y[x] = ret
    return ret
end

Base.size(A::Mat) = size(A.data)
Base.axes(A::Mat) = axes(A.data)
Base.IndexStyle(::Type{Mat{T}}) where {T} = IndexCartesian()

Base.strides(A::Mat{T}) where {T} = strides(A.data)
Base.copy(A::Mat{T}) where {T} = Mat(copy(A.data_raw))
Base.pointer(A::Mat) = Base.pointer(A.data)

Base.unsafe_convert(::Type{Ptr{T}}, A::Mat{S}) where {T, S} = Base.unsafe_convert(Ptr{T}, A.data)

@inline function Base.getindex(A::Mat{T}, I::Vararg{Int,3}) where {T}
    @boundscheck checkbounds(A.data, I...)
    @inbounds ret = A.data[I...]
    ret
end

@inline function Base.setindex!(A::Mat, x, I::Vararg{Int,3})
    @boundscheck checkbounds(A.data, I...)
    A.data[I...] = x
    return A
end