<commit_before>#### Types and constructors ####

# Plain arrays can be treated as images. Other types will have
# metadata associated, make yours a child of one of the following:
abstract AbstractImage{T} <: AbstractArray{T}         # image with metadata
abstract AbstractImageDirect{T} <: AbstractImage{T}   # each pixel has own value/color
abstract AbstractImageIndexed{T} <: AbstractImage{T}  # indexed images (i.e., lookup table)

# Direct image (e.g., grayscale, RGB)
type Image{T,A<:StridedArray} <: AbstractImageDirect{T}
    data::A
    properties::Dict
end
Image{A<:StridedArray}(data::A, props::Dict) = Image{eltype(data),A}(data,props)
Image{A<:StridedArray}(data::A) = Image(data,Dict{String,Any}())

# Indexed image (colormap)
type ImageCmap{T,A<:StridedArray,C<:AbstractArray} <: AbstractImageIndexed{T}
    data::A
    cmap::C
    properties::Dict
end
ImageCmap{A<:StridedArray,C<:AbstractArray}(data::A, cmap::C, props::Dict) = ImageCmap{eltype(data),A,C}(data, cmap, props)
ImageCmap{A<:StridedArray,C<:AbstractArray}(data::A, cmap::C) = ImageCmap(data, cmap, Dict{String,Any}())

#### Core operations ####

eltype{T}(img::AbstractImage{T}) = T

size(img::AbstractImage) = size(img.data)
size(img::AbstractImage, i::Integer) = size(img.data, i)

ndims(img::AbstractImage) = ndims(img.data)

strides(img::AbstractImage) = strides(img.data)

copy(img::AbstractImage) = deepcopy(img)

# copy, replacing the data
copy(img::StridedArray, data::StridedArray) = data

copy(img::Image, data::StridedArray) = Image(data, copy(img.properties))

copy(img::ImageCmap, data::StridedArray) = ImageCmap(data, copy(img.cmap), copy(img.properties))

# Provide new data but reuse the properties & cmap
share(img::StridedArray, data::StridedArray) = data

share(img::Image, data::StridedArray) = Image(data, img.properties)

share(img::ImageCmap, data::StridedArray) = ImageCmap(data, img.cmap, img.properties)

# similar
similar{T}(img::Image, ::Type{T}, dims::Dims) = Image(similar(img.data, T, dims), copy(img.properties))

similar{T}(img::Image, ::Type{T}) = Image(similar(img.data, T), copy(img.properties))

similar(img::Image) = Image(similar(img.data), copy(img.properties))

similar{T}(img::ImageCmap, ::Type{T}, dims::Dims) = ImageCmap(similar(img.data, T, dims), copy(img.cmap), copy(img.properties))

similar{T}(img::ImageCmap, ::Type{T}) = ImageCmap(similar(img.data, T), copy(img.cmap), copy(img.properties))

similar(img::ImageCmap) = ImageCmap(similar(img.data), copy(img.cmap), copy(img.properties))

# convert
convert{I<:AbstractImageDirect}(::Type{I}, img::I) = img
convert{I<:AbstractImageIndexed}(::Type{I}, img::I) = img
# Convert an indexed image (cmap) to a direct image
function convert{ID<:AbstractImageDirect,II<:AbstractImageIndexed}(::Type{ID}, img::II)
    local data
    local prop
    if size(img.cmap, 2) == 1<commit_msg>Fix type problem from transition to StridedArray<commit_after>#### Types and constructors ####

# Plain arrays can be treated as images. Other types will have
# metadata associated, make yours a child of one of the following:
abstract AbstractImage{T} <: AbstractArray{T}         # image with metadata
abstract AbstractImageDirect{T} <: AbstractImage{T}   # each pixel has own value/color
abstract AbstractImageIndexed{T} <: AbstractImage{T}  # indexed images (i.e., lookup table)

# Direct image (e.g., grayscale, RGB)
type Image{T,A<:StridedArray} <: AbstractImageDirect{T}
    data::A
    properties::Dict
end
Image{A<:StridedArray}(data::A, props::Dict) = Image{eltype(data),A}(data,props)
Image{A<:StridedArray}(data::A) = Image(data,Dict{String,Any}())

# Indexed image (colormap)
type ImageCmap{T,A<:StridedArray,C<:AbstractArray} <: AbstractImageIndexed{T}
    data::A
    cmap::C
    properties::Dict
end
ImageCmap{A<:StridedArray,C<:AbstractArray}(data::A, cmap::C, props::Dict) = ImageCmap{eltype(data),A,C}(data, cmap, props)
ImageCmap{A<:StridedArray,C<:AbstractArray}(data::A, cmap::C) = ImageCmap(data, cmap, Dict{String,Any}())

#### Core operations ####

eltype{T}(img::AbstractImage{T}) = T

size(img::AbstractImage) = size(img.data)
size(img::AbstractImage, i::Integer) = size(img.data, i)

ndims(img::AbstractImage) = ndims(img.data)

strides(img::AbstractImage) = strides(img.data)

copy(img::AbstractImage) = deepcopy(img)

# copy, replacing the data
copy(img::StridedArray, data::StridedArray) = data

copy(img::Image, data::StridedArray) = Image(data, copy(img.properties))

copy(img::ImageCmap, data::StridedArray) = ImageCmap(data, copy(img.cmap), copy(img.properties))

# Provide new data but reuse the properties & cmap
share(img::StridedArray, data::StridedArray) = data

share(img::Image, data::StridedArray) = Image(data, img.properties)

share(img::ImageCmap, data::StridedArray) = ImageCmap(data, img.cmap, img.properties)

# similar
similar{T}(img::Image, ::Type{T}, dims::Dims) = Image(similar(img.data, T, dims), copy(img.properties))

similar{T}(img::Image, ::Type{T}) = Image(similar(img.data, T), copy(img.properties))

similar(img::Image) = Image(similar(img.data), copy(img.properties))

similar{T}(img::ImageCmap, ::Type{T}, dims::Dims) = ImageCmap(similar(img.data, T, dims), copy(img.cmap), copy(img.properties))

similar{T}(img::ImageCmap, ::Type{T}) = ImageCmap(similar(img.data, T), copy(img.cmap), copy(img.properties))

similar(img::ImageCmap) = ImageCmap(similar(img.data), copy(img.cmap), copy(img.properties))

# convert
convert{I<:AbstractImageDirect}(::Type{I}, img::I) = img
convert{I<:AbstractImageIndexed}(::Type{I}, img::I) = img
# Convert an indexed image (cmap) to a direct image
function convert{ID<:AbstractImageDirect,II<:AbstractImageIndexed}(::Type{ID}, img::II)
    local data::StridedArray
    local prop
    if size(img.cmap, 2) == 1
{'fraction_non_alphanumeric': 0.17486528767599513, 'fraction_numerical': 0.0006952894142186686, 'mean_word_length': 7.3755458515283845, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5577432', 'n_tokens_mistral': 2051, 'n_tokens_neox': 2014, 'n_words': 401}