Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations #307

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ if !libmxnet_detected

blas_path = Libdl.dlpath(Libdl.dlopen(Base.libblas_name))

if VERSION >= v"0.5.0-dev+4338"
blas_vendor = Base.BLAS.vendor()
else
blas_vendor = Base.blas_vendor()
end
blas_vendor = Base.BLAS.vendor()

ilp64 = ""
if blas_vendor == :openblas64
Expand Down
6 changes: 3 additions & 3 deletions examples/char-lstm/lstm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using MXNet

#--LSTMState
immutable LSTMState
struct LSTMState
c :: mx.SymbolicNode
h :: mx.SymbolicNode
end
#--/LSTMState

#--LSTMParam
immutable LSTMParam
struct LSTMParam
i2h_W :: mx.SymbolicNode
h2h_W :: mx.SymbolicNode
i2h_b :: mx.SymbolicNode
Expand Down Expand Up @@ -116,7 +116,7 @@ end


# Negative Log-likelihood
type NLL <: mx.AbstractEvalMetric
mutable struct NLL <: mx.AbstractEvalMetric
nll_sum :: Float64
n_sample :: Int

Expand Down
2 changes: 1 addition & 1 deletion examples/char-lstm/seq-data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function build_vocabulary(corpus_fn::AbstractString, vocab_fn::AbstractString; m
end

#--CharSeqProvider
type CharSeqProvider <: mx.AbstractDataProvider
mutable struct CharSeqProvider <: mx.AbstractDataProvider
text :: AbstractString
batch_size :: Int
seq_len :: Int
Expand Down
2 changes: 1 addition & 1 deletion plugins/io/svmlight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ datasets in this format could be found at http://www.csie.ntu.edu.tw/~cjlin/libs
using MXNet
using SVMLightLoader

type SVMLightProvider <: mx.AbstractDataProvider
mutable struct SVMLightProvider <: mx.AbstractDataProvider
filename :: AbstractString
batch_size :: Int
fea_dim :: Int
Expand Down
4 changes: 1 addition & 3 deletions src/MXNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ using Compat
import Compat.String
import Compat.view

if VERSION >= v"0.6.0-dev.1024"
import Base.Iterators: filter
end
import Base.Iterators: filter

using Formatting
using MacroTools
Expand Down
12 changes: 6 additions & 6 deletions src/base.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Exception thrown when an error occurred calling MXNet API."
immutable MXError <: Exception
struct MXError <: Exception
msg :: AbstractString
end

Expand Down Expand Up @@ -91,7 +91,7 @@ end
macro mx_define_handle_t(name, destructor)
name = esc(name)
quote
type $name
mutable struct $name
value :: MX_handle

function $name(value = C_NULL)
Expand Down Expand Up @@ -161,7 +161,7 @@ dump_mx_param(val::Any) = string(val)
dump_mx_param(val::Float64) = @sprintf("%.16e", val)
dump_mx_param(val::Float32) = @sprintf("%.8e", val)
dump_mx_param(val::Float16) = @sprintf("%.4e", val)
dump_mx_param{N, T<:Integer}(shape::NTuple{N, T}) =
dump_mx_param(shape::NTuple{N, T}) where {N, T<:Integer} =
string(tuple(flipdim([shape...], 1)...))


Expand Down Expand Up @@ -203,7 +203,7 @@ end
"""Internal use only, this value is used to indicate a required value
is not specified.
"""
immutable __Undefined
struct __Undefined
end

function _defstruct_impl(is_immutable, name, fields)
Expand Down Expand Up @@ -285,15 +285,15 @@ function _defstruct_impl(is_immutable, name, fields)

if is_immutable
quote
immutable $(name) <: $(super_name)
struct $(name) <: $(super_name)
$type_body
end

$ctor
end
else
quote
type $(name) <: $(super_name)
mutable struct $(name) <: $(super_name)
$type_body
end

Expand Down
12 changes: 6 additions & 6 deletions src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

Abstract type of callback functions used in training.
"""
@compat abstract type AbstractCallback end
abstract type AbstractCallback end

"""
AbstractBatchCallback

Abstract type of callbacks to be called every mini-batch.
"""
@compat abstract type AbstractBatchCallback <: AbstractCallback end
abstract type AbstractBatchCallback <: AbstractCallback end

"""
AbstractEpochCallback

Abstract type of callbacks to be called every epoch.
"""
@compat abstract type AbstractEpochCallback <: AbstractCallback end
abstract type AbstractEpochCallback <: AbstractCallback end

type BatchCallback <: AbstractBatchCallback
mutable struct BatchCallback <: AbstractBatchCallback
frequency :: Int
call_on_0 :: Bool
callback :: Function
Expand Down Expand Up @@ -86,7 +86,7 @@ function speedometer(;frequency::Int=50)
end


type EpochCallback <: AbstractEpochCallback
mutable struct EpochCallback <: AbstractEpochCallback
frequency :: Int
call_on_0 :: Bool
callback :: Function
Expand All @@ -107,7 +107,7 @@ See also [`every_n_batch`](@ref).
function every_n_epoch(callback :: Function, n :: Int; call_on_0 :: Bool = false)
EpochCallback(n, call_on_0, callback)
end
function (cb :: EpochCallback){T<:Real}(model :: Any, state :: OptimizationState, metric :: Vector{Tuple{Base.Symbol, T}})
function (cb :: EpochCallback)(model :: Any, state :: OptimizationState, metric :: Vector{Tuple{Base.Symbol, T}}) where T<:Real
if state.curr_epoch == 0
if cb.call_on_0
cb.callback(model, state, metric)
Expand Down
13 changes: 2 additions & 11 deletions src/compat.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# this file contains code used for enabling backward compatibility with 0.5

# have to import base dotted operators if in 0.5
if VERSION < v"0.6.0-dev"
import Base: .+, .-, .*, ./, .^
end


# this is for declaring broadcasted functions in 0.5
# TODO this macro should be removed when 0.5 support is dropped
macro compatdot(fblock)
if VERSION ≥ v"0.6.0-dev"
return esc(fblock)
end
return esc(fblock)
@capture(fblock, function Base.broadcast(::typeof(op_), args__)
body_
end)
Expand All @@ -24,9 +19,5 @@ macro compatdot(fblock)
end

macro compatmul(expr1, expr2)
if VERSION ≥ v"0.6.0-dev"
esc(:(broadcast(*, $expr1, $expr2)))
else
esc(:($expr1 .* $expr2))
end
esc(:(broadcast(*, $expr1, $expr2)))
end
2 changes: 1 addition & 1 deletion src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A context describes the device type and id on which computation should be carried on.
"""
immutable Context
struct Context
device_type :: CONTEXT_TYPE
device_id :: Int
end
Expand Down
2 changes: 1 addition & 1 deletion src/executor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An executor is a realization of a symbolic architecture defined by a `SymbolicNo
The actual forward and backward computation specified by the network architecture can
be carried out with an executor.
"""
type Executor
mutable struct Executor
handle :: MX_ExecutorHandle
symbol :: SymbolicNode
arg_arrays :: Vector{NDArray}
Expand Down
10 changes: 5 additions & 5 deletions src/initializer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Or, if full behavior customization is needed, override the following function

init(self :: AbstractInitializer, name :: Base.Symbol, array :: NDArray)
"""
@compat abstract type AbstractInitializer end
abstract type AbstractInitializer end

function init{T<:AbstractInitializer}(self :: T, name :: Base.Symbol, array :: NDArray)
function init(self :: T, name :: Base.Symbol, array :: NDArray) where T<:AbstractInitializer
strname = string(name)
if startswith(strname,"upsampling")
_init_bilinear(self,name, array)
Expand Down Expand Up @@ -94,7 +94,7 @@ end

Initialize weights according to a uniform distribution within the provided scale.
"""
immutable UniformInitializer <: AbstractInitializer
struct UniformInitializer <: AbstractInitializer
scale :: AbstractFloat
end
"""
Expand All @@ -113,7 +113,7 @@ end

Initialize weights according to a univariate Gaussian distribution.
"""
immutable NormalInitializer <: AbstractInitializer
struct NormalInitializer <: AbstractInitializer
μ :: AbstractFloat
σ :: AbstractFloat
end
Expand Down Expand Up @@ -150,7 +150,7 @@ used by various libraries.
@enum XavierDistribution xv_uniform xv_normal
@enum XavierRegularization xv_avg xv_in xv_out

immutable XavierInitializer <: AbstractInitializer
struct XavierInitializer <: AbstractInitializer
distribution :: XavierDistribution
regularization :: XavierRegularization
magnitude :: Float64
Expand Down
26 changes: 13 additions & 13 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Normally this involves defining:
* `Base.done(provider, state) -> Bool`
* `Base.next(provider, state) -> (AbstractDataBatch, AbstractDataProvider)`
"""
@compat abstract type AbstractDataProvider end
abstract type AbstractDataProvider end

"""
get_batch_size(provider) -> Int
Expand Down Expand Up @@ -53,7 +53,7 @@ function provide_label end

Base type for data provider states.
"""
@compat abstract type AbstractDataProviderState end
abstract type AbstractDataProviderState end

"""
AbstractDataBatch
Expand All @@ -70,7 +70,7 @@ The following utility functions will be automatically defined:
* [`load_data!`](@ref)
* [`load_label!`](@ref)
"""
@compat abstract type AbstractDataBatch end
abstract type AbstractDataBatch end

"""
count_samples(provider, batch) -> Int
Expand Down Expand Up @@ -113,14 +113,14 @@ function get_label end
A basic subclass of `AbstractDataBatch`, that implement the interface by
accessing member fields.
"""
type DataBatch <: AbstractDataBatch
mutable struct DataBatch <: AbstractDataBatch
data :: Vector{NDArray}
label :: Vector{NDArray}
count :: Int
end
count_samples(batch :: DataBatch) = batch.count
get_data{Provider<:AbstractDataProvider}(::Provider, batch :: DataBatch) = batch.data
get_label{Provider<:AbstractDataProvider}(::Provider, batch :: DataBatch) = batch.label
get_data(::Provider, batch :: DataBatch) where {Provider<:AbstractDataProvider} = batch.data
get_label(::Provider, batch :: DataBatch) where {Provider<:AbstractDataProvider} = batch.label

"""
SlicedNDArray
Expand Down Expand Up @@ -252,7 +252,7 @@ Construct a data provider from `NDArray` or Julia Arrays.
TODO: remove `data_padding` and `label_padding`, and implement rollover that copies
the last or first several training samples to feed the padding.
"""
type ArrayDataProvider <: AbstractDataProvider
mutable struct ArrayDataProvider <: AbstractDataProvider
data_arrays :: Vector{Array}
data_names :: Vector{Base.Symbol}
label_arrays :: Vector{Array}
Expand All @@ -277,7 +277,7 @@ function ArrayDataProvider(data::Any; batch_size::Int=0, shuffle::Bool=false, da
ArrayDataProvider(data, [], batch_size=batch_size, shuffle=shuffle, data_padding=data_padding, label_padding=label_padding)
end
function ArrayDataProvider(data::Any, label::Any; batch_size::Int=0, shuffle::Bool=false, data_padding::Real=0, label_padding::Real=0)
asarr{T}(arr :: Array{T}) = convert(Array{MX_float}, arr)
asarr(arr :: Array{T}) where {T} = convert(Array{MX_float}, arr)
asarr(arr :: NDArray) = copy(arr)

if isa(data, Union{NDArray, Array}) && eltype(data) <: Real
Expand Down Expand Up @@ -362,7 +362,7 @@ end

get_batch_size(provider::ArrayDataProvider) = provider.batch_size

immutable ArrayDataProviderState <: AbstractDataProviderState
struct ArrayDataProviderState <: AbstractDataProviderState
curr_idx :: Int
end

Expand All @@ -385,7 +385,7 @@ function Base.done(provider::ArrayDataProvider, state :: ArrayDataProviderState)
return state.curr_idx > provider.sample_count
end

immutable ArrayDataBatch <: AbstractDataBatch
struct ArrayDataBatch <: AbstractDataBatch
idx :: UnitRange{Int}
end
function Base.next(provider :: ArrayDataProvider, state :: ArrayDataProviderState)
Expand Down Expand Up @@ -423,7 +423,7 @@ end
A data provider that wrap built-in data iterators from libmxnet. See below for
a list of built-in data iterators.
"""
type MXDataProvider <: AbstractDataProvider
mutable struct MXDataProvider <: AbstractDataProvider
handle :: MX_DataIterHandle
data_shape :: Vector{Tuple{Base.Symbol, Tuple}}
label_shape:: Vector{Tuple{Base.Symbol, Tuple}}
Expand Down Expand Up @@ -474,10 +474,10 @@ provide_data(provider::MXDataProvider) = provider.data_shape
provide_label(provider::MXDataProvider) = provider.label_shape
get_batch_size(provider::MXDataProvider) = provider.batch_size

type MXDataProviderState <: AbstractDataProviderState
mutable struct MXDataProviderState <: AbstractDataProviderState
has_next :: Bool
end
immutable MXDataBatch <: AbstractDataBatch
struct MXDataBatch <: AbstractDataBatch
end

function Base.eltype(provider :: MXDataProvider)
Expand Down
2 changes: 1 addition & 1 deletion src/kvstore.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type KVStore
mutable struct KVStore
handle :: MX_KVStoreHandle
updater_c :: Ptr{Void}
updater :: Function
Expand Down