text:
# Julia wrapper for header: /Volumes/BOOTCAMP/programs/compa_libs/libim_process_/include/libim_process_.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

@static is_windows()? (const liblibim_process__ = "libim_process_") : (const liblibim_process__ = "liblibim_process_")  # Name of shared lib.

function imProcessUnaryPointOp(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, func::imUnaryPointOpFunc, params::Ptr{Cfloat}, userdata::Ptr{Void}, op_name::Ptr{UInt8})
  ccall( (:imProcessUnaryPointOp, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, imUnaryPointOpFunc, Ptr{Cfloat}, Ptr{Void}, Ptr{UInt8}), src_image, dst_image, func, params, userdata, op_name)
end
function imProcessUnaryPointColorOp(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, func::imUnaryPointColorOpFunc, params::Ptr{Cfloat}, userdata::Ptr{Void}, op_name::Ptr{UInt8})
  ccall( (:imProcessUnaryPointColorOp, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, imUnaryPointColorOpFunc, Ptr{Cfloat}, Ptr{Void}, Ptr{UInt8}), src_image, dst_image, func, params, userdata, op_name)
end
function imProcessMultiPointOp(src_image::Ptr{Ptr{imImage}}, src_count::Cint, dst_image::Ptr{imImage}, func::imMultiPointOpFunc, params::Ptr{Cfloat}, userdata::Ptr{Void}, op_name::Ptr{UInt8})
  ccall( (:imProcessMultiPointOp, libim_process_), Cint, (Ptr{Ptr{imImage}}, Cint, Ptr{imImage}, imMultiPointOpFunc, Ptr{Cfloat}, Ptr{Void}, Ptr{UInt8}), src_image, src_count, dst_image, func, params, userdata, op_name)
end
function imProcessMultiPointColorOp(src_image::Ptr{Ptr{imImage}}, src_count::Cint, dst_image::Ptr{imImage}, func::imMultiPointColorOpFunc, params::Ptr{Cfloat}, userdata::Ptr{Void}, op_name::Ptr{UInt8})
  ccall( (:imProcessMultiPointColorOp, libim_process_), Cint, (Ptr{Ptr{imImage}}, Cint, Ptr{imImage}, imMultiPointColorOpFunc, Ptr{Cfloat}, Ptr{Void}, Ptr{UInt8}), src_image, src_count, dst_image, func, params, userdata, op_name)
end
function imProcessUnArithmeticOp(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, op::Cint)
  ccall( (:imProcessUnArithmeticOp, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, op)
end
function imProcessArithmeticOp(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage}, op::Cint)
  ccall( (:imProcessArithmeticOp, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image1, src_image2, dst_image, op)
end
function imProcessArithmeticConstOp(src_image::Ptr{imImage}, src_const::Cfloat, dst_image::Ptr{imImage}, op::Cint)
  ccall( (:imProcessArithmeticConstOp, libim_process_), Void, (Ptr{imImage}, Cfloat, Ptr{imImage}, Cint), src_image, src_const, dst_image, op)
end
function imProcessBlendConst(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage}, alpha::Cfloat)
  ccall( (:imProcessBlendConst, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cfloat), src_image1, src_image2, dst_image, alpha)
end
function imProcessBlend(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, alpha_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessBlend, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image1, src_image2, alpha_image, dst_image)
end
function imProcessCompose(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessCompose, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image1, src_image2, dst_image)
end
function imProcessSplitComplex(src_image::Ptr{imImage}, dst_image1::Ptr{imImage}, dst_image2::Ptr{imImage}, polar::Cint)
  ccall( (:imProcessSplitComplex, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image1, dst_image2, polar)
end
function imProcessMergeComplex(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage}, polar::Cint)
  ccall( (:imProcessMergeComplex, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image1, src_image2, dst_image, polar)
end
function imProcessMultipleMean(src_image_list::Ptr{Ptr{imImage}}, src_image_count::Cint, dst_image::Ptr{imImage})
  ccall( (:imProcessMultipleMean, libim_process_), Void, (Ptr{Ptr{imImage}}, Cint, Ptr{imImage}), src_image_list, src_image_count, dst_image)
end
function imProcessMultipleStdDev(src_image_list::Ptr{Ptr{imImage}}, src_image_count::Cint, mean_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessMultipleStdDev, libim_process_), Void, (Ptr{Ptr{imImage}}, Cint, Ptr{imImage}, Ptr{imImage}), src_image_list, src_image_count, mean_image, dst_image)
end
function imProcessAutoCovariance(src_image::Ptr{imImage}, mean_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessAutoCovariance, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, mean_image, dst_image)
end
function imProcessMultiplyConj(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessMultiplyConj, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image1, src_image2, dst_image)
end
function imProcessQuantizeRGBUniform(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, do_dither::Cint)
  ccall( (:imProcessQuantizeRGBUniform, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, do_dither)
end
function imProcessQuantizeGrayUniform(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, grays::Cint)
  ccall( (:imProcessQuantizeGrayUniform, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, grays)
end
function imProcessExpandHistogram(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, percent::Cfloat)
  ccall( (:imProcessExpandHistogram, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, percent)
end
function imProcessEqualizeHistogram(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessEqualizeHistogram, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessSplitYChroma(src_image::Ptr{imImage}, y_image::Ptr{imImage}, chroma_image::Ptr{imImage})
  ccall( (:imProcessSplitYChroma, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, y_image, chroma_image)
end
function imProcessSplitHSI(src_image::Ptr{imImage}, h_image::Ptr{imImage}, s_image::Ptr{imImage}, i_image::Ptr{imImage})
  ccall( (:imProcessSplitHSI, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, h_image, s_image, i_image)
end
function imProcessMergeHSI(h_image::Ptr{imImage}, s_image::Ptr{imImage}, i_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessMergeHSI, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), h_image, s_image, i_image, dst_image)
end
function imProcessSplitComponents(src_image::Ptr{imImage}, dst_image_list::Ptr{Ptr{imImage}})
  ccall( (:imProcessSplitComponents, libim_process_), Void, (Ptr{imImage}, Ptr{Ptr{imImage}}), src_image, dst_image_list)
end
function imProcessMergeComponents(src_image_list::Ptr{Ptr{imImage}}, dst_image::Ptr{imImage})
  ccall( (:imProcessMergeComponents, libim_process_), Void, (Ptr{Ptr{imImage}}, Ptr{imImage}), src_image_list, dst_image)
end
function imProcessNormalizeComponents(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessNormalizeComponents, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessReplaceColor(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, src_color::Ptr{Cfloat}, dst_color::Ptr{Cfloat})
  ccall( (:imProcessReplaceColor, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{Cfloat}, Ptr{Cfloat}), src_image, dst_image, src_color, dst_color)
end
function imProcessSetAlphaColor(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, src_color::Ptr{Cfloat}, dst_alpha::Cfloat)
  ccall( (:imProcessSetAlphaColor, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{Cfloat}, Cfloat), src_image, dst_image, src_color, dst_alpha)
end
function imProcessBitwiseOp(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage}, op::Cint)
  ccall( (:imProcessBitwiseOp, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image1, src_image2, dst_image, op)
end
function imProcessBitwiseNot(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessBitwiseNot, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessBitMask(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, mask::Cuchar, op::Cint)
  ccall( (:imProcessBitMask, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cuchar, Cint), src_image, dst_image, mask, op)
end
function imProcessBitPlane(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, plane::Cint, do_reset::Cint)
  ccall( (:imProcessBitPlane, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, plane, do_reset)
end
function imProcessRenderOp(image::Ptr{imImage}, render_func::imRenderFunc, render_name::Ptr{UInt8}, params::Ptr{Cfloat}, plus::Cint)
  ccall( (:imProcessRenderOp, libim_process_), Cint, (Ptr{imImage}, imRenderFunc, Ptr{UInt8}, Ptr{Cfloat}, Cint), image, render_func, render_name, params, plus)
end
function imProcessRenderCondOp(image::Ptr{imImage}, render_cond_func::imRenderCondFunc, render_name::Ptr{UInt8}, params::Ptr{Cfloat})
  ccall( (:imProcessRenderCondOp, libim_process_), Cint, (Ptr{imImage}, imRenderCondFunc, Ptr{UInt8}, Ptr{Cfloat}), image, render_cond_func, render_name, params)
end
function imProcessRenderAddSpeckleNoise(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, percent::Cfloat)
  ccall( (:imProcessRenderAddSpeckleNoise, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, percent)
end
function imProcessRenderAddGaussianNoise(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, mean::Cfloat, stddev::Cfloat)
  ccall( (:imProcessRenderAddGaussianNoise, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, dst_image, mean, stddev)
end
function imProcessRenderAddUniformNoise(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, mean::Cfloat, stddev::Cfloat)
  ccall( (:imProcessRenderAddUniformNoise, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, dst_image, mean, stddev)
end
function imProcessRenderRandomNoise(image::Ptr{imImage})
  ccall( (:imProcessRenderRandomNoise, libim_process_), Cint, (Ptr{imImage},), image)
end
function imProcessRenderConstant(image::Ptr{imImage}, value::Ptr{Cfloat})
  ccall( (:imProcessRenderConstant, libim_process_), Cint, (Ptr{imImage}, Ptr{Cfloat}), image, value)
end
function imProcessRenderWheel(image::Ptr{imImage}, internal_radius::Cint, external_radius::Cint)
  ccall( (:imProcessRenderWheel, libim_process_), Cint, (Ptr{imImage}, Cint, Cint), image, internal_radius, external_radius)
end
function imProcessRenderCone(image::Ptr{imImage}, radius::Cint)
  ccall( (:imProcessRenderCone, libim_process_), Cint, (Ptr{imImage}, Cint), image, radius)
end
function imProcessRenderTent(image::Ptr{imImage}, tent_width::Cint, tent_height::Cint)
  ccall( (:imProcessRenderTent, libim_process_), Cint, (Ptr{imImage}, Cint, Cint), image, tent_width, tent_height)
end
function imProcessRenderRamp(image::Ptr{imImage}, start::Cint, _end::Cint, vert_dir::Cint)
  ccall( (:imProcessRenderRamp, libim_process_), Cint, (Ptr{imImage}, Cint, Cint, Cint), image, start, _end, vert_dir)
end
function imProcessRenderBox(image::Ptr{imImage}, box_width::Cint, box_height::Cint)
  ccall( (:imProcessRenderBox, libim_process_), Cint, (Ptr{imImage}, Cint, Cint), image, box_width, box_height)
end
function imProcessRenderSinc(image::Ptr{imImage}, x_period::Cfloat, y_period::Cfloat)
  ccall( (:imProcessRenderSinc, libim_process_), Cint, (Ptr{imImage}, Cfloat, Cfloat), image, x_period, y_period)
end
function imProcessRenderGaussian(image::Ptr{imImage}, stddev::Cfloat)
  ccall( (:imProcessRenderGaussian, libim_process_), Cint, (Ptr{imImage}, Cfloat), image, stddev)
end
function imProcessRenderLapOfGaussian(image::Ptr{imImage}, stddev::Cfloat)
  ccall( (:imProcessRenderLapOfGaussian, libim_process_), Cint, (Ptr{imImage}, Cfloat), image, stddev)
end
function imProcessRenderCosine(image::Ptr{imImage}, x_period::Cfloat, y_period::Cfloat)
  ccall( (:imProcessRenderCosine, libim_process_), Cint, (Ptr{imImage}, Cfloat, Cfloat), image, x_period, y_period)
end
function imProcessRenderGrid(image::Ptr{imImage}, x_space::Cint, y_space::Cint)
  ccall( (:imProcessRenderGrid, libim_process_), Cint, (Ptr{imImage}, Cint, Cint), image, x_space, y_space)
end
function imProcessRenderChessboard(image::Ptr{imImage}, x_space::Cint, y_space::Cint)
  ccall( (:imProcessRenderChessboard, libim_process_), Cint, (Ptr{imImage}, Cint, Cint), image, x_space, y_space)
end
function imProcessToneGamut(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, op::Cint, params::Ptr{Cfloat})
  ccall( (:imProcessToneGamut, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Ptr{Cfloat}), src_image, dst_image, op, params)
end
function imProcessUnNormalize(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessUnNormalize, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessDirectConv(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessDirectConv, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessNegative(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessNegative, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessCalcAutoGamma(image::Ptr{imImage})
  ccall( (:imProcessCalcAutoGamma, libim_process_), Cfloat, (Ptr{imImage},), image)
end
function imProcessShiftHSI(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, h_shift::Cfloat, s_shift::Cfloat, i_shift::Cfloat)
  ccall( (:imProcessShiftHSI, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat, Cfloat), src_image, dst_image, h_shift, s_shift, i_shift)
end
function imProcessThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, level::Cfloat, value::Cint)
  ccall( (:imProcessThreshold, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cint), src_image, dst_image, level, value)
end
function imProcessThresholdByDiff(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessThresholdByDiff, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image1, src_image2, dst_image)
end
function imProcessHysteresisThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, low_thres::Cint, high_thres::Cint)
  ccall( (:imProcessHysteresisThreshold, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, low_thres, high_thres)
end
function imProcessHysteresisThresEstimate(image::Ptr{imImage}, low_level::Ptr{Cint}, high_level::Ptr{Cint})
  ccall( (:imProcessHysteresisThresEstimate, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}, Ptr{Cint}), image, low_level, high_level)
end
function imProcessUniformErrThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessUniformErrThreshold, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessDifusionErrThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, level::Cint)
  ccall( (:imProcessDifusionErrThreshold, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, level)
end
function imProcessPercentThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, percent::Cfloat)
  ccall( (:imProcessPercentThreshold, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, percent)
end
function imProcessOtsuThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessOtsuThreshold, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessMinMaxThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessMinMaxThreshold, libim_process_), Cfloat, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessLocalMaxThresEstimate(image::Ptr{imImage}, level::Ptr{Cint})
  ccall( (:imProcessLocalMaxThresEstimate, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}), image, level)
end
function imProcessSliceThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, start_level::Cfloat, end_level::Cfloat)
  ccall( (:imProcessSliceThreshold, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, dst_image, start_level, end_level)
end
function imProcessPixelate(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, box_size::Cint)
  ccall( (:imProcessPixelate, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, box_size)
end
function imProcessPosterize(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, level::Cint)
  ccall( (:imProcessPosterize, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, level)
end
function imProcessNormDiffRatio(image1::Ptr{imImage}, image2::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessNormDiffRatio, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), image1, image2, dst_image)
end
function imProcessAbnormalHyperionCorrection(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, threshold_consecutive::Cint, threshold_percent::Cint, image_abnormal::Ptr{imImage})
  ccall( (:imProcessAbnormalHyperionCorrection, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint, Ptr{imImage}), src_image, dst_image, threshold_consecutive, threshold_percent, image_abnormal)
end
function imProcessConvertDataType(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, cpx2real::Cint, gamma::Cfloat, abssolute::Cint, cast_mode::Cint)
  ccall( (:imProcessConvertDataType, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cfloat, Cint, Cint), src_image, dst_image, cpx2real, gamma, abssolute, cast_mode)
end
function imProcessConvertColorSpace(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessConvertColorSpace, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessConvertToBitmap(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, cpx2real::Cint, gamma::Cfloat, abssolute::Cint, cast_mode::Cint)
  ccall( (:imProcessConvertToBitmap, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cfloat, Cint, Cint), src_image, dst_image, cpx2real, gamma, abssolute, cast_mode)
end
function imProcessReduce(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, order::Cint)
  ccall( (:imProcessReduce, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, order)
end
function imProcessResize(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, order::Cint)
  ccall( (:imProcessResize, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, order)
end
function imProcessReduceBy4(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessReduceBy4, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessCrop(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, xmin::Cint, ymin::Cint)
  ccall( (:imProcessCrop, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, xmin, ymin)
end
function imProcessInsert(src_image::Ptr{imImage}, region_image::Ptr{imImage}, dst_image::Ptr{imImage}, xmin::Cint, ymin::Cint)
  ccall( (:imProcessInsert, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, region_image, dst_image, xmin, ymin)
end
function imProcessAddMargins(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, xmin::Cint, ymin::Cint)
  ccall( (:imProcessAddMargins, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, xmin, ymin)
end
function imProcessCalcRotateSize(width::Cint, height::Cint, new_width::Ptr{Cint}, new_height::Ptr{Cint}, cos0::Cdouble, sin0::Cdouble)
  ccall( (:imProcessCalcRotateSize, libim_process_), Void, (Cint, Cint, Ptr{Cint}, Ptr{Cint}, Cdouble, Cdouble), width, height, new_width, new_height, cos0, sin0)
end
function imProcessRotate(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, cos0::Cdouble, sin0::Cdouble, order::Cint)
  ccall( (:imProcessRotate, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cdouble, Cdouble, Cint), src_image, dst_image, cos0, sin0, order)
end
function imProcessRotateRef(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, cos0::Cdouble, sin0::Cdouble, x::Cint, y::Cint, to_origin::Cint, order::Cint)
  ccall( (:imProcessRotateRef, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cdouble, Cdouble, Cint, Cint, Cint, Cint), src_image, dst_image, cos0, sin0, x, y, to_origin, order)
end
function imProcessRotate90(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, dir_clockwise::Cint)
  ccall( (:imProcessRotate90, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, dir_clockwise)
end
function imProcessRotate180(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessRotate180, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessMirror(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessMirror, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessFlip(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessFlip, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessRadial(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, k1::Cfloat, order::Cint)
  ccall( (:imProcessRadial, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cint), src_image, dst_image, k1, order)
end
function imProcessSwirl(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, k1::Cfloat, order::Cint)
  ccall( (:imProcessSwirl, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cint), src_image, dst_image, k1, order)
end
function imProcessInterlaceSplit(src_image::Ptr{imImage}, dst_image1::Ptr{imImage}, dst_image2::Ptr{imImage})
  ccall( (:imProcessInterlaceSplit, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, dst_image1, dst_image2)
end
function imProcessGrayMorphConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage}, ismax::Cint)
  ccall( (:imProcessGrayMorphConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel, ismax)
end
function imProcessGrayMorphErode(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphErode, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphDilate(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphDilate, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphOpen(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphOpen, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphClose(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphClose, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphTopHat(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphTopHat, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphWell(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphWell, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGrayMorphGradient(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessGrayMorphGradient, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessBinMorphConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage}, hit_white::Cint, iter::Cint)
  ccall( (:imProcessBinMorphConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel, hit_white, iter)
end
function imProcessBinMorphErode(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, iter::Cint)
  ccall( (:imProcessBinMorphErode, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, iter)
end
function imProcessBinMorphDilate(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, iter::Cint)
  ccall( (:imProcessBinMorphDilate, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, iter)
end
function imProcessBinMorphOpen(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, iter::Cint)
  ccall( (:imProcessBinMorphOpen, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, iter)
end
function imProcessBinMorphClose(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, iter::Cint)
  ccall( (:imProcessBinMorphClose, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, iter)
end
function imProcessBinMorphOutline(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, iter::Cint)
  ccall( (:imProcessBinMorphOutline, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, iter)
end
function imProcessBinMorphThin(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessBinMorphThin, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessMedianConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessMedianConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessRangeConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessRangeConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessRankClosestConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessRankClosestConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessRankMaxConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessRankMaxConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessRankMinConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessRankMinConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessRangeContrastThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, min_range::Cint)
  ccall( (:imProcessRangeContrastThreshold, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, min_range)
end
function imProcessLocalMaxThreshold(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint, min_level::Cint)
  ccall( (:imProcessLocalMaxThreshold, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, kernel_size, min_level)
end
function imProcessConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage})
  ccall( (:imProcessConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, dst_image, kernel)
end
function imProcessConvolveSep(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage})
  ccall( (:imProcessConvolveSep, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, dst_image, kernel)
end
function imProcessConvolveDual(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel1::Ptr{imImage}, kernel2::Ptr{imImage})
  ccall( (:imProcessConvolveDual, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, dst_image, kernel1, kernel2)
end
function imProcessConvolveRep(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage}, count::Cint)
  ccall( (:imProcessConvolveRep, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel, count)
end
function imProcessCompassConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel::Ptr{imImage})
  ccall( (:imProcessCompassConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, dst_image, kernel)
end
function imProcessRotateKernel(kernel::Ptr{imImage})
  ccall( (:imProcessRotateKernel, libim_process_), Void, (Ptr{imImage},), kernel)
end
function imProcessDiffOfGaussianConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, stddev1::Cfloat, stddev2::Cfloat)
  ccall( (:imProcessDiffOfGaussianConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, dst_image, stddev1, stddev2)
end
function imProcessLapOfGaussianConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, stddev::Cfloat)
  ccall( (:imProcessLapOfGaussianConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, stddev)
end
function imProcessMeanConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessMeanConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessGaussianConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, stddev::Cfloat)
  ccall( (:imProcessGaussianConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, stddev)
end
function imProcessBarlettConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, kernel_size::Cint)
  ccall( (:imProcessBarlettConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, kernel_size)
end
function imProcessSobelConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessSobelConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessPrewittConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessPrewittConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessSplineEdgeConvolve(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessSplineEdgeConvolve, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessZeroCrossing(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessZeroCrossing, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessCanny(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, stddev::Cfloat)
  ccall( (:imProcessCanny, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cfloat), src_image, dst_image, stddev)
end
function imGaussianStdDev2KernelSize(stddev::Cfloat)
  ccall( (:imGaussianStdDev2KernelSize, libim_process_), Cint, (Cfloat,), stddev)
end
function imGaussianKernelSize2StdDev(kernel_size::Cint)
  ccall( (:imGaussianKernelSize2StdDev, libim_process_), Cfloat, (Cint,), kernel_size)
end
function imProcessUnsharp(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, stddev::Cfloat, amount::Cfloat, threshold::Cfloat)
  ccall( (:imProcessUnsharp, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat, Cfloat), src_image, dst_image, stddev, amount, threshold)
end
function imProcessSharp(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, amount::Cfloat, threshold::Cfloat)
  ccall( (:imProcessSharp, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, dst_image, amount, threshold)
end
function imProcessSharpKernel(src_image::Ptr{imImage}, kernel::Ptr{imImage}, dst_image::Ptr{imImage}, amount::Cfloat, threshold::Cfloat)
  ccall( (:imProcessSharpKernel, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Cfloat, Cfloat), src_image, kernel, dst_image, amount, threshold)
end
function imProcessHoughLines(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessHoughLines, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessHoughLinesDraw(src_image::Ptr{imImage}, hough::Ptr{imImage}, hough_points::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessHoughLinesDraw, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image, hough, hough_points, dst_image)
end
function imProcessCrossCorrelation(src_image1::Ptr{imImage}, src_image2::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessCrossCorrelation, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Ptr{imImage}), src_image1, src_image2, dst_image)
end
function imProcessAutoCorrelation(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessAutoCorrelation, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessDistanceTransform(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessDistanceTransform, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessRegionalMaximum(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessRegionalMaximum, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessFFT(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessFFT, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessIFFT(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessIFFT, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessFFTraw(image::Ptr{imImage}, inverse::Cint, center::Cint, normalize::Cint)
  ccall( (:imProcessFFTraw, libim_process_), Void, (Ptr{imImage}, Cint, Cint, Cint), image, inverse, center, normalize)
end
function imProcessSwapQuadrants(image::Ptr{imImage}, center2origin::Cint)
  ccall( (:imProcessSwapQuadrants, libim_process_), Void, (Ptr{imImage}, Cint), image, center2origin)
end
function imProcessOpenMPSetMinCount(min_count::Cint)
  ccall( (:imProcessOpenMPSetMinCount, libim_process_), Cint, (Cint,), min_count)
end
function imProcessOpenMPSetNumThreads(count::Cint)
  ccall( (:imProcessOpenMPSetNumThreads, libim_process_), Cint, (Cint,), count)
end
function imCalcRMSError(image1::Ptr{imImage}, image2::Ptr{imImage})
  ccall( (:imCalcRMSError, libim_process_), Cfloat, (Ptr{imImage}, Ptr{imImage}), image1, image2)
end
function imCalcSNR(src_image::Ptr{imImage}, noise_image::Ptr{imImage})
  ccall( (:imCalcSNR, libim_process_), Cfloat, (Ptr{imImage}, Ptr{imImage}), src_image, noise_image)
end
function imCalcCountColors(image::Ptr{imImage})
  ccall( (:imCalcCountColors, libim_process_), Culong, (Ptr{imImage},), image)
end
function imCalcGrayHistogram(image::Ptr{imImage}, histo::Ptr{Culong}, cumulative::Cint)
  ccall( (:imCalcGrayHistogram, libim_process_), Void, (Ptr{imImage}, Ptr{Culong}, Cint), image, histo, cumulative)
end
function imCalcHistogram(image::Ptr{imImage}, histo::Ptr{Culong}, plane::Cint, cumulative::Cint)
  ccall( (:imCalcHistogram, libim_process_), Void, (Ptr{imImage}, Ptr{Culong}, Cint, Cint), image, histo, plane, cumulative)
end
function imCalcByteHistogram(data::Ptr{Cuchar}, count::Cint, histo::Ptr{Culong}, cumulative::Cint)
  ccall( (:imCalcByteHistogram, libim_process_), Void, (Ptr{Cuchar}, Cint, Ptr{Culong}, Cint), data, count, histo, cumulative)
end
function imCalcUShortHistogram(data::Ptr{Uint16}, count::Cint, histo::Ptr{Culong}, cumulative::Cint)
  ccall( (:imCalcUShortHistogram, libim_process_), Void, (Ptr{Uint16}, Cint, Ptr{Culong}, Cint), data, count, histo, cumulative)
end
function imCalcShortHistogram(data::Ptr{Int16}, count::Cint, histo::Ptr{Culong}, cumulative::Cint)
  ccall( (:imCalcShortHistogram, libim_process_), Void, (Ptr{Int16}, Cint, Ptr{Culong}, Cint), data, count, histo, cumulative)
end
function imHistogramNew(data_type::Cint, hcount::Ptr{Cint})
  ccall( (:imHistogramNew, libim_process_), Ptr{Culong}, (Cint, Ptr{Cint}), data_type, hcount)
end
function imHistogramRelease(histo::Ptr{Culong})
  ccall( (:imHistogramRelease, libim_process_), Void, (Ptr{Culong},), histo)
end
function imHistogramShift(data_type::Cint)
  ccall( (:imHistogramShift, libim_process_), Cint, (Cint,), data_type)
end
function imHistogramCount(data_type::Cint)
  ccall( (:imHistogramCount, libim_process_), Cint, (Cint,), data_type)
end
function imCalcImageStatistics(image::Ptr{imImage}, stats::Ptr{imStats})
  ccall( (:imCalcImageStatistics, libim_process_), Void, (Ptr{imImage}, Ptr{imStats}), image, stats)
end
function imCalcHistogramStatistics(image::Ptr{imImage}, stats::Ptr{imStats})
  ccall( (:imCalcHistogramStatistics, libim_process_), Void, (Ptr{imImage}, Ptr{imStats}), image, stats)
end
function imCalcHistoImageStatistics(image::Ptr{imImage}, median::Ptr{Cint}, mode::Ptr{Cint})
  ccall( (:imCalcHistoImageStatistics, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}, Ptr{Cint}), image, median, mode)
end
function imCalcPercentMinMax(image::Ptr{imImage}, percent::Cfloat, ignore_zero::Cint, min::Ptr{Cint}, max::Ptr{Cint})
  ccall( (:imCalcPercentMinMax, libim_process_), Void, (Ptr{imImage}, Cfloat, Cint, Ptr{Cint}, Ptr{Cint}), image, percent, ignore_zero, min, max)
end
function imAnalyzeFindRegions(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, connect::Cint, touch_border::Cint)
  ccall( (:imAnalyzeFindRegions, libim_process_), Cint, (Ptr{imImage}, Ptr{imImage}, Cint, Cint), src_image, dst_image, connect, touch_border)
end
function imAnalyzeMeasureArea(image::Ptr{imImage}, area::Ptr{Cint}, region_count::Cint)
  ccall( (:imAnalyzeMeasureArea, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}, Cint), image, area, region_count)
end
function imAnalyzeMeasurePerimArea(image::Ptr{imImage}, perimarea::Ptr{Cfloat})
  ccall( (:imAnalyzeMeasurePerimArea, libim_process_), Void, (Ptr{imImage}, Ptr{Cfloat}), image, perimarea)
end
function imAnalyzeMeasureCentroid(image::Ptr{imImage}, area::Ptr{Cint}, region_count::Cint, cx::Ptr{Cfloat}, cy::Ptr{Cfloat})
  ccall( (:imAnalyzeMeasureCentroid, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}, Cint, Ptr{Cfloat}, Ptr{Cfloat}), image, area, region_count, cx, cy)
end
function imAnalyzeMeasurePrincipalAxis(image::Ptr{imImage}, area::Ptr{Cint}, cx::Ptr{Cfloat}, cy::Ptr{Cfloat}, region_count::Cint, major_slope::Ptr{Cfloat}, major_length::Ptr{Cfloat}, minor_slope::Ptr{Cfloat}, minor_length::Ptr{Cfloat})
  ccall( (:imAnalyzeMeasurePrincipalAxis, libim_process_), Void, (Ptr{imImage}, Ptr{Cint}, Ptr{Cfloat}, Ptr{Cfloat}, Cint, Ptr{Cfloat}, Ptr{Cfloat}, Ptr{Cfloat}, Ptr{Cfloat}), image, area, cx, cy, region_count, major_slope, major_length, minor_slope, minor_length)
end
function imAnalyzeMeasureHoles(image::Ptr{imImage}, connect::Cint, holes_count::Ptr{Cint}, area::Ptr{Cint}, perim::Ptr{Cfloat})
  ccall( (:imAnalyzeMeasureHoles, libim_process_), Void, (Ptr{imImage}, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cfloat}), image, connect, holes_count, area, perim)
end
function imAnalyzeMeasurePerimeter(image::Ptr{imImage}, perim::Ptr{Cfloat}, region_count::Cint)
  ccall( (:imAnalyzeMeasurePerimeter, libim_process_), Void, (Ptr{imImage}, Ptr{Cfloat}, Cint), image, perim, region_count)
end
function imProcessPerimeterLine(src_image::Ptr{imImage}, dst_image::Ptr{imImage})
  ccall( (:imProcessPerimeterLine, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}), src_image, dst_image)
end
function imProcessRemoveByArea(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, connect::Cint, start_size::Cint, end_size::Cint, inside::Cint)
  ccall( (:imProcessRemoveByArea, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint, Cint, Cint, Cint), src_image, dst_image, connect, start_size, end_size, inside)
end
function imProcessFillHoles(src_image::Ptr{imImage}, dst_image::Ptr{imImage}, connect::Cint)
  ccall( (:imProcessFillHoles, libim_process_), Void, (Ptr{imImage}, Ptr{imImage}, Cint), src_image, dst_image, connect)
end


text: # No image information

ext: jl


text:
using StanDump
using StanRun

srand(UInt32[0x5b02bb69, 0xf5693c2c, 0xb0101f2a, 0xc44fb3ce]) # consistent runs

sp = StanRun.Program(Pkg.dir("StanSamples", "test", "testmodel", "test"))

M1 = 3
M2 = 5
N = 100
μ = 1.0
σ = 0.5
ν = 1.0
α = randn(M1, M2)*σ + μ
X = randn(M1, M2, N)*ν .+ α

standump(sp, @vardict M1 M2 N X)

StanRun.make(sp, StanRun.EXECUTABLE, force = true)
StanRun.sample(sp, 1)


text:
using transD_GP, Distributed
## make options for the multichannel lengthscale GP
nminlog10λ, nmaxlog10λ = 2, 40
pnorm = 2.
Klog10λ = transD_GP.GP.Mat32()
log10bounds = [0 1.]
λlog10λ = [0.07*abs(diff([extrema(znall)...])[1])]
δlog10λ = 0.1
demean = false
sdev_poslog10λ = [0.05abs(diff([extrema(znall)...])[1])]
sdev_proplog10λ = 0.1*diff(log10bounds, dims=2)[:]
xall = permutedims(collect(znall))
xbounds = permutedims([extrema(znall)...])
## Initialize a lengthscale model using these options
Random.seed!(12)
optlog10λ = transD_GP.OptionsStat(nmin = nminlog10λ,
                        nmax = nmaxlog10λ,
                        xbounds = xbounds,
                        fbounds = log10bounds,
                        xall = xall,
                        λ = λlog10λ,
                        δ = δlog10λ,
                        demean = demean,
                        sdev_prop = sdev_proplog10λ,
                        sdev_pos = sdev_poslog10λ,
                        needλ²fromlog = true,
                        updatenonstat = true,
                        pnorm = pnorm,
                        quasimultid = false,
                        K = Klog10λ,
                        timesλ = 3.7,
                        peskycholesky = true
                        )
## make options for the nonstationary actual properties GP
nmin, nmax = 2, 20
fbounds = [-0.5 2.3]
δ = 0.06
sdev_prop = 0.02*diff(fbounds, dims=2)[:]
sdev_pos = [0.008abs(diff([extrema(znall)...])[1])]
demean_ns = true
K = transD_GP.GP.Mat32()
## Initialize model for the nonstationary properties GP
Random.seed!(13)
opt = transD_GP.OptionsNonstat(optlog10λ,
                        nmin = nmin,
                        nmax = nmax,
                        fbounds = fbounds,
                        δ = δ,
                        demean = demean_ns,
                        sdev_prop = sdev_prop,
                        sdev_pos = sdev_pos,
                        pnorm = pnorm,
                        K = K
                        )

max_stars_repo_name: GeoscienceAustralia/HiQGA

max_issues_repo_name: GeoscienceAustralia/HiQGA


text:
# Masked Arrays are used in systems
struct Mask
    start :: Int
    len   :: Int
end

function Base.sum(v::Vector{Mask})
    t = 0
    for g in v
        t += g.len
    end
    return t
end

struct MaskedArray{T,N} <: AbstractArray{T,N}
    base::DenseArray{T,N}
    masks::Vector{Mask}
end

function masked_index(A::MaskedArray, i::Int)
    t_id = i
    for g in A.masks
        if t_id >= g.start
            t_id += g.len
        end
    end
    return t_id
end

Base.size(A::MaskedArray)                 = size(A.base) .- sum(A.masks)
Base.length(A::MaskedArray)               = length(A.base) .- sum(A.masks)
Base.getindex(A::MaskedArray, i::Int)     = A.base[masked_index(A, i)]
Base.setindex!(A::MaskedArray, v, i::Int) = A.base[masked_index(A, i)] = v
Base.IndexStyle(::Type{<:MaskedArray})    = IndexLinear()


text:
function xpow(x)
return [x x^2 x^3 x^4]
end
function xpow_loop(n)
s = 0
for i = 1:n
s = s + xpow(i)[2]
end
return s
end

max_stars_repo_path: Module 2/Chapter06/allocations.jl

max_issues_repo_path: Module 2/Chapter06/allocations.jl

max_forks_repo_path: Module 2/Chapter06/allocations.jl


text:
abstract IndexFormula{T<:Number}

"""
refindex(formula, λ_μm) computes the refractive index for a given wavelength in μm.
"""
refindex{T}(::IndexFormula{T}, λ_μm::T) = zero(T);

type SellmeierFormula{T<:Number} <: IndexFormula{T}
  n::Int8
  A::T
  B::Array{T,1}
  C::Array{T,1}
  λn::Bool
  function SellmeierFormula(A,B,C,λn=true)
    n = length(B)
    if length(C) != n
      error("Coefficients B and C of different length")
    else
      new(n,A,B,C,λn)
    end
  end
end

function refindex{T}(formula::SellmeierFormula{T}, λ_μm::T)
  nsq=one(T)+formula.A
  λsq = λ_μm^2
  for i = 1:formula.n
    num = i==formula.n && !formula.λn ? formula.B[i] : formula.B[i] * λsq
    nsq += num/(λsq - formula.C[i])
  end
  return sqrt(nsq)
end

bk7 = SellmeierFormula{Float64}(0, [1.03961212, 0.231792344, 1.01046945], [6.00069867e-3, 2.00179144e-2, 1.03560653e2])
refindex(bk7,0.5)

using Gadfly
plot(x->refindex(bk7,x),0.21,1.6)


text:
using Smolyak
import PyPlot

# function to plot a 2d or 3d grid
function plot(sg::SmolyakGrid)
    g = sg.grid
    mu  = sg.mu
    d = sg.d
    mu_str = isa(mu, Array) ? replace(strip(string(mu)),'\n'," \\times ") : mu
    if size(g, 2) == 2
        PyPlot.scatter(g[:, 1], g[:, 2])
        PyPlot.title("Smolyak grid: \$d=$(d), \\; \\mu=$(mu_str)\$")
    elseif size(g, 2) == 3
        PyPlot.scatter3D(g[:, 1], g[:, 2], g[:, 3], "b.")
        PyPlot.title("Smolyak grid: \$d=$(d), \\; \\mu=$(mu_str)\$")
    else
        error("ERROR: can only plot 2d or 3d grids")
    end
end

max_issues_repo_name: EconForge/Smolyak

max_forks_repo_name: EconForge/Smolyak


text:
using IPNets
using Base.Test
using Compat

ip41 = IPv4("1.2.3.4")
ip42 = IPv4("5.6.7.8")

n1 = IPv4Net("1.2.3.0/24")
n2 = IPv4Net("1.2.3.4/24")
n3 = IPv4Net("1.2.3.4/26")
n4 = IPv4Net("5.6.7.0/24")
n5 = IPv4Net("1.2.3.4/30")

ip61 = IPv6("2001:1::4")
ip62 = IPv6("2001:2::8")

o1 = IPv6Net("2001:1::/64")
o2 = IPv6Net("2001:1::4/64")
o3 = IPv6Net("2001:1::4/68")
o4 = IPv6Net("2001:2::8/64")
o5 = IPv6Net("2001:1::4/126")

# ipv4
@test_throws ErrorException IPv4Net(ip41, 33)
@test IPv4Net("1.2.3.4", "255.255.255.0") == n1
@test IPv4Net("1.2.3.4", 24) == n1
@test IPv4Net(16909060,24) == n1
@test IPv4Net((16909060,24)) == n1

@test IPv4Net("1.2.3.4") == IPv4Net("1.2.3.4/32")
@test n1 == n2

@test isless(n1,n3) == false
@test isless(n1,n4) == true

@test n1[5] == ip41
@test isless(ip41, ip42) == true
@test in(ip42, n4) == true
@test_throws ErrorException ip42 in o4
@test contains(n4, ip42) == true
@test issubset(n3, n2) == true
@test issubset(n1, n2) == true

@test IPNets.contiguousbitcount(240,UInt8) == 0x04
@test IPNets.contiguousbitcount(252,UInt8) == 0x06
@test_throws ErrorException IPNets.contiguousbitcount(241,UInt8)

@test endswith(string(n5),"(\"1.2.3.4/30\")") == true
@test endswith(sprint(print,n5),"(\"1.2.3.4/30\")") == true
@test endswith(sprint(show,n5),"(\"1.2.3.4/30\")") == true
@test endswith(string(display,n5),"(\"1.2.3.4/30\")") == true
@test size(n5) == (4,)
@test [x for x in n5] == [ip"1.2.3.4", ip"1.2.3.5", ip"1.2.3.6", ip"1.2.3.7"]
@test endof(n5) == 4
@test minimum(n5) == ip"1.2.3.4"
@test maximum(n5) == ip"1.2.3.7"
@test extrema(n5) == (ip"1.2.3.4",ip"1.2.3.7")
@test getindex(n5,1:2) == [ip"1.2.3.4", ip"1.2.3.5"]
# @test getindex(n5,(1,)) == ip41
@test_throws BoundsError getindex(n5, 10)
@test IPNets.width(IPv4) == 32
@test_throws BoundsError IPNets.mask2bits(IPv4, @compat(UInt64(33)))

# IPv6
@test_throws ErrorException IPv6Net(ip61, 129)
@test IPv6Net("2001:1::", 64) == o1
@test IPv6Net(0x20010001000000000000000000000004,64) == o1
@test IPv6Net((0x20010001000000000000000000000004,64)) == o1
@test o1 == o2

@test IPv6Net("2001:1::1") == IPv6Net("2001:1::1/128")
@test isless(o1,o3) == false
@test isless(o1,o4) == true

@test o1[5] == ip61
@test isless(ip61, ip62) == true
@test in(ip62, o4) == true
@test_throws ErrorException ip62 in n4
@test contains(o4, ip62) == true

@test endswith(string(o5),"(\"2001:1::4/126\")") == true
@test endswith(sprint(print,o5),"(\"2001:1::4/126\")") == true
@test endswith(sprint(show,o5),"(\"2001:1::4/126\")") == true
@test endswith(string(display,o5),"(\"2001:1::4/126\")") == true
@test size(o5) == (4,)
@test [x for x in o5] == [ip"2001:1::4",ip"2001:1::5",ip"2001:1::6",ip"2001:1::7"]
@test endof(o5) == 4
@test minimum(o5) == ip"2001:1::4"
@test maximum(o5) == ip"2001:1::7"
@test extrema(o5) == (ip"2001:1::4",ip"2001:1::7")
@test getindex(o5,1:2) == [ip"2001:1::4", ip"2001:1::5"]
# @test getindex(o5,(1,)) == ip61
@test_throws BoundsError getindex(o5, 10)
@test IPNets.width(IPv6) == 128

@test_throws BoundsError IPNets.mask2bits(IPv6, @compat(UInt64(129)))


text:
using BRKGA, TSP, Base.Test

srand(12345) # For reproducibility
@testset "TSP" begin
    pairs = readTSP("a280.tsp")
    @testset "read instance" begin

        @test sum(pairs) == [39358, 24892]
        @test pairs[1] == [288, 149]
        @test pairs[end] == [280, 133]
        @test sum(pairs) == [39358, 24892]
    end
    para = Parameters(
            0.70, # probability that offspring inherit an allele from elite parent
            256,  # size of population
            1000, # number of generations
            0.1, # fraction of population to be the elite-set
            0.1, # fraction of population to be replaced by mutants
            1   # Crossover type
            )

    tsp = TSPProblem(pairs, para)

    @testset "decoder" begin
        obj = BRKGA.decoder(tsp, [0.62724,0.27957,0.9319,0.154122,0.16129,0.157706,0.623656,0.562724,0.616487,0.55914,0.555556,0.928315,0.0215054,0.924731,0.566308,0.53405,0.724014,0.802867,0.892473,0.899642,0.799283,0.0286738,0.0322581,0.0250896,0.863799,0.612903,0.83871,0.0681004,0.0645161,0.831541,0.415771,0.795699,0.874552,0.867384,0.827957,0.870968,0.97491,0.971326,0.792115,0.11828,0.967742,0.985663,0.78853,0.0860215,0.111111,0.207885,0.0824373,0.114695,0.982079,0.978495,0.0896057,0.078853,0.0716846,0.0752688,0.670251,0.204301,0.218638,0.21147,0.09319,0.0143369,0.222222,0.824373,0.046595,0.0107527,0.197133,0.673835,0.00716846,0.215054,0.964158,0.960573,0.200717,0.107527,0.00358423,0.666667,0.505376,0.0,0.749104,0.598566,1.0,0.523297,0.103943,0.752688,0.426523,0.602151,0.408602,0.677419,0.508961,0.494624,0.0967742,0.74552,0.516129,0.318996,0.498208,0.519713,0.501792,0.591398,0.594982,0.430108,0.512545,0.401434,0.315412,0.491039,0.996416,0.100358,0.437276,0.322581,0.0537634,0.663082,0.193548,0.913978,0.756272,0.992832,0.0501792,0.989247,0.526882,0.910394,0.605735,0.956989,0.0573477,0.903226,0.444444,0.609319,0.121864,0.412186,0.784946,0.878136,0.0179211,0.835125,0.896057,0.88172,0.0358423,0.842294,0.888889,0.845878,0.530466,0.860215,0.551971,0.921147,0.458781,0.688172,0.731183,0.713262,0.777778,0.293907,0.329749,0.810036,0.455197,0.548387,0.480287,0.65233,0.125448,0.781362,0.448029,0.0609319,0.419355,0.953405,0.422939,0.90681,0.301075,0.44086,0.326165,0.917563,0.681004,0.308244,0.487455,0.394265,0.587814,0.397849,0.433692,0.405018,0.659498,0.387097,0.311828,0.225806,0.0430108,0.0394265,0.820789,0.189964,0.304659,0.451613,0.483871,0.297491,0.655914,0.584229,0.379928,0.759857,0.390681,0.383513,0.741935,0.763441,0.817204,0.81362,0.37276,0.767025,0.18638,0.369176,0.738351,0.684588,0.709677,0.376344,0.706093,0.734767,0.365591,0.580645,0.362007,0.774194,0.648746,0.645161,0.243728,0.132616,0.695341,0.175627,0.179211,0.344086,0.182796,0.770609,0.333333,0.25448,0.290323,0.702509,0.698925,0.336918,0.340502,0.261649,0.258065,0.268817,0.247312,0.265233,0.272401,0.34767,0.637993,0.641577,0.283154,0.136201,0.286738,0.139785,0.351254,0.146953,0.150538,0.634409,0.143369,0.354839,0.275986,0.935484,0.939068,0.856631,0.473118,0.358423,0.853047,0.942652,0.250896,0.476703,0.946237,0.577061,0.229391,0.691756,0.541219,0.240143,0.232975,0.168459,0.236559,0.716846,0.172043,0.849462,0.129032,0.544803,0.806452,0.727599,0.949821,0.885305,0.72043,0.569892,0.462366,0.620072,0.573477,0.164875,0.537634,0.469534,0.46595,0.630824])
        @test obj == 10980

    end

    @testset "start GA" begin
        bestcost, gen, totaltime, bestsoltime = BRKGA.start(tsp)
        @test isapprox(bestcost, 10030.)
        @test gen == 1000
        @test isapprox(totaltime, bestsoltime; atol=1e-1)

        para.maxgen = 10000
        bestcost, gen, totaltime, bestsoltime = BRKGA.start(tsp; targetcost=10069.)
        @test isapprox(bestcost, 10047.0)

        bestcost, gen, totaltime, bestsoltime = BRKGA.start(tsp; maxstableit=50)
        @test isapprox(bestcost, 8433.)
        @test gen == 2495
    end
end


text:
#  Copyright 2016, Iain Dunning, Joey Huchette, Miles Lubin, and contributors
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.
#############################################################################
# JuMP
# An algebraic modelling langauge for Julia
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################
# test/quadmodel.jl
# Testing quadratic models (objective and constraints)
# Must be run as part of runtests.jl, as it needs a list of solvers.
#############################################################################
using JuMP, FactCheck

# If solvers not loaded, load them (i.e running just these tests)
!isdefined(:lp_solvers) && include("solvers.jl")

facts("[qcqpmodel] Test quad objective (discrete)") do
for solver in quad_mip_solvers
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    @objective(modQ, Min, 10*x[1]*x[1] + 3*x[1]*x[2] + 5*x[2]*x[2] + 9*x[3]*x[3])
    @constraint(modQ, x[2] <= 1.7*x[3])
    @constraint(modQ, x[2] >= 0.5*x[1])
    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly( 247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)

    # vectorized version
    modV = Model(solver=solver)
    @variable(modV, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    obj = x'*[10 1.5 0; 1.5 5 0; 0 0 9]*x
    @objective(modV, Min, obj[1])
    A = [  0  1 -1.7
         0.5 -1    0]
    @constraint(modV, A*x .<= zeros(2))
    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly( 247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)

    modQ = Model(solver=solver)
    @variable(modQ, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    @objective(modQ, :Max, -10*x[1]*x[1] - 3*x[1]*x[2] - 5*x[2]*x[2] - 9*x[3]*x[3])
    @constraint(modQ, x[2] <= 1.7*x[3])
    @constraint(modQ, x[2] >= 0.5*x[1])
    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(-247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)

    # sparse vectorized version
    modV = Model(solver=solver)
    @variable(modV, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    obj = x'*sparse([10 1.5 0; 1.5 5 0; 0 0 9])*x
    @objective(modV, Min, obj[1])
    A = sparse([  0  1 -1.7
                0.5 -1    0])
    @constraint(modV, A*x .<= zeros(2))
    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly( 247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)

    modQ = Model(solver=solver)
    @variable(modQ, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    @objective(modQ, :Max, -10*x[1]*x[1] - 3*x[1]*x[2] - 5*x[2]*x[2] - 9*x[3]*x[3])
    @constraint(modQ, x[2] <= 1.7*x[3])
    @constraint(modQ, x[2] >= 0.5*x[1])
    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(-247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)

    # vectorized version
    modV = Model(solver=solver)
    @variable(modV, 1.1*i <= x[i=1:3] <= 2.5*i, Int)
    Q = [10 3 0; 0 5 0; 0 0 9]
    obj = x'Q*x
    @objective(modV, Min, obj[1])
    A = [   0 -1 1.7
         -0.5  1   0]
    @constraint(modV, A*x .>= zeros(2))
    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly( 247.0, 1e-5)
    @fact getvalue(x)[:] --> roughly([2.0, 3.0, 4.0], 1e-6)
end; end; end

facts("[qcqpmodel] Test quad objective (continuous)") do
for solver in quad_solvers
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, 0.5 <= x <= 2 )
    @variable(modQ, 0 <= y <= 30 )
    @objective(modQ, :Min, (x+y)*(x+y) )
    @constraint(modQ, x + y >= 1 )
    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(1.0, 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(1.0, 1e-6)

    # Vectorized version
    modV = Model(solver=solver)
    @variable(modV, 0.5 <= x <= 2 )
    @variable(modV, 0 <= y <= 30 )
    obj = [x y]*ones(2,2)*[x,y]
    @objective(modV, Min, obj[1])
    @constraint(modV, ones(1,2)*[x,y] .>= 1)
    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(1.0, 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(1.0, 1e-6)

    # Sparse vectorized version
    modV = Model(solver=solver)
    @variable(modV, 0.5 <= x <= 2 )
    @variable(modV, 0 <= y <= 30 )
    obj = [x y]*sparse(ones(2,2))*[x,y]
    @objective(modV, Min, obj[1])
    @constraint(modV, sparse(ones(1,2))*[x,y] .>= 1)
    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(1.0, 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(1.0, 1e-6)
end; end; end

facts("[qcqpmodel] Test quad constraints (continuous)") do
for solver in quad_solvers
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, -2 <= x <= 2 )
    @variable(modQ, -2 <= y <= 2 )
    @objective(modQ, Min, x - y )
    @constraint(modQ, x + x*x + x*y + y*y <= 1 )
    @fact MathProgBase.numquadconstr(modQ) --> 1
    @fact MathProgBase.numlinconstr(modQ) --> 0
    @fact MathProgBase.numconstr(modQ) --> 1
    @fact JuMP.isquadsoc(modQ) --> false

    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(-1-4/sqrt(3), 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(-1/3, 1e-3)

    # Vectorized version
    modV = Model(solver=solver)
    @variable(modV, -2 <= x <= 2 )
    @variable(modV, -2 <= y <= 2 )
    obj = [1 -1]*[x,y]
    @objective(modV, Min, obj[1])
    A = [1 0.5; 0.5 1]
    @constraint(modV, [x y]*A*[x,y] + [x] .<= [1])
    @fact MathProgBase.numquadconstr(modV) --> 1
    @fact MathProgBase.numlinconstr(modV) --> 0
    @fact MathProgBase.numconstr(modV) --> 1

    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(-1-4/sqrt(3), 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(-1/3, 1e-3)

    # Sparse vectorized version
    modV = Model(solver=solver)
    @variable(modV, -2 <= x <= 2 )
    @variable(modV, -2 <= y <= 2 )
    obj = [1 -1]*[x,y]
    @objective(modV, Min, obj[1])
    A = sparse([1 0.5; 0.5 1])
    @constraint(modV, [x y]*A*[x,y] + [x] .<= [1])
    @fact MathProgBase.numquadconstr(modV) --> 1
    @fact MathProgBase.numlinconstr(modV) --> 0
    @fact MathProgBase.numconstr(modV) --> 1

    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(-1-4/sqrt(3), 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(-1/3, 1e-3)
end; end; end

facts("[qcqpmodel] Test SOC constraints (continuous)") do
for solver in soc_solvers
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, x)
    @variable(modQ, y)
    @variable(modQ, t >= 0)
    @objective(modQ, Min, t)
    @constraint(modQ, x+y >= 1)
    @constraint(modQ, x^2 + y^2 <= t^2)
    @fact JuMP.isquadsoc(modQ) --> true

    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(sqrt(1/2), 1e-6)
    @fact norm([getvalue(x), getvalue(y), getvalue(t)] - [0.5,0.5,sqrt(1/2)]) --> roughly(0.0,1e-3)

    # Vectorized version
    modV = Model(solver=solver)
    @variable(modV, x)
    @variable(modV, y)
    @variable(modV, t >= 0)
    @objective(modV, Min, t)
    @constraint(modV, [1 1 0]*[x,y,t] .>= 1)
    Q = [1 0  0
         0 1  0
         0 0 -1]
    @constraint(modV, [x y t]*Q*[x,y,t] .<= 0)

    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(sqrt(1/2), 1e-6)
    @fact norm([getvalue(x), getvalue(y), getvalue(t)] - [0.5,0.5,sqrt(1/2)]) --> roughly(0.0,1e-3)

    # Sparse vectorized version
    modV = Model(solver=solver)
    @variable(modV, x)
    @variable(modV, y)
    @variable(modV, t >= 0)
    @objective(modV, Min, t)
    @constraint(modV, sparse([1 1 0])*[x,y,t] .>= 1)
    Q = sparse([1 0  0
                0 1  0
                0 0 -1])
    @constraint(modV, [x y t]*Q*[x,y,t] .<= 0)

    @fact solve(modV) --> :Optimal
    @fact modV.objVal --> roughly(sqrt(1/2), 1e-6)
    @fact norm([getvalue(x), getvalue(y), getvalue(t)] - [0.5,0.5,sqrt(1/2)]) --> roughly(0.0,1e-3)

    # SOC version 1
    modN = Model(solver=solver)
    @variable(modN, x)
    @variable(modN, y)
    @variable(modN, t >= 0)
    @objective(modN, Min, t)
    @constraint(modN, x + y >= 1)
    @constraint(modN, norm([x,y]) <= t)

    @fact solve(modN) --> :Optimal
    @fact modN.objVal --> roughly(sqrt(1/2), 1e-6)
    @fact norm([getvalue(x), getvalue(y), getvalue(t)] - [0.5,0.5,sqrt(1/2)]) --> roughly(0.0,1e-3)

    # SOC version 2
    modN = Model(solver=solver)
    @variable(modN, x)
    @variable(modN, y)
    @variable(modN, t >= 0)
    @objective(modN, Min, t)
    @constraint(modN, x + y >= 1)
    tmp = [x,y]
    @constraint(modN, norm2{tmp[i], i=1:2} <= t)

    @fact solve(modN) --> :Optimal
    @fact modN.objVal --> roughly(sqrt(1/2), 1e-6)
    @fact norm([getvalue(x), getvalue(y), getvalue(t)] - [0.5,0.5,sqrt(1/2)]) --> roughly(0.0,1e-3)
end; end; end

facts("[qcqpmodel] Test SOC duals") do
for solver in soc_solvers
contains("$(typeof(solver))", "MosekSolver") && continue # Mosek doesn't support duals with conic-through-quadratic
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, x >= 0)
    @variable(modQ, y)
    @variable(modQ, z)
    @objective(modQ, Min, -y-z)
    @constraint(modQ, eq, x <= 1)
    @constraint(modQ, y^2 + z^2 <= x^2)

    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(-sqrt(2), 1e-6)
    @fact getvalue(y) --> roughly(1/sqrt(2), 1e-6)
    @fact getvalue(z) --> roughly(1/sqrt(2), 1e-6)
    @fact getdual(eq) --> roughly(-sqrt(2), 1e-6)

    @objective(modQ, Max, y+z)
    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(sqrt(2), 1e-6)
    @fact getvalue(y) --> roughly(1/sqrt(2), 1e-6)
    @fact getvalue(z) --> roughly(1/sqrt(2), 1e-6)
    @fact getdual(eq) --> roughly(sqrt(2), 1e-6)

    # # SOC syntax version
    # modN = Model(solver=solver)
    # @variable(modN, x >= 0)
    # @variable(modN, y)
    # @variable(modN, z)
    # @objective(modN, Min, -y-z)
    # @constraint(modN, eq, x <= 1)
    # # @constraint(modN, y^2 + z^2 <= x^2)
    # @constraint(modN, (1/4)*norm([4.0y,4.0z]) <= x)
    #
    # @fact solve(modN) --> :Optimal
    # @fact modN.objVal --> roughly(-sqrt(2), 1e-6)
    # @fact getvalue(y) --> roughly(1/sqrt(2), 1e-6)
    # @fact getvalue(z) --> roughly(1/sqrt(2), 1e-6)
    # @fact getdual(eq) --> roughly(-sqrt(2), 1e-6)
    #
    # @objective(modN, Max, y+z)
    # @fact solve(modN) --> :Optimal
    # @fact modN.objVal --> roughly(sqrt(2), 1e-6)
    # @fact getvalue(y) --> roughly(1/sqrt(2), 1e-6)
    # @fact getvalue(z) --> roughly(1/sqrt(2), 1e-6)
    # @fact getdual(eq) --> roughly(sqrt(2), 1e-6)

end; end; end

facts("[qcqpmodel] Test quad constraints (discrete)") do
for solver in quad_mip_solvers
context("With solver $(typeof(solver))") do
    modQ = Model(solver=solver)
    @variable(modQ, -2 <= x <= 2, Int )
    @variable(modQ, -2 <= y <= 2, Int )
    @objective(modQ, Min, x - y )
    @constraint(modQ, x + x*x + x*y + y*y <= 1 )

    @fact solve(modQ) --> :Optimal
    @fact modQ.objVal --> roughly(-3, 1e-6)
    @fact (getvalue(x) + getvalue(y)) --> roughly(-1, 1e-6)

end; end; end

facts("[qcqpmodel] Test simple normed problem") do
for solver in soc_solvers
context("With solver $(typeof(solver))") do
    m = Model(solver=solver);
    @variable(m, x[1:3]);
    @constraint(m, 2norm2{x[i]-1, i=1:3} <= 2)
    @objective(m, Max, x[1]+x[2])

    @fact solve(m) --> :Optimal
    @fact getobjectivevalue(m) --> roughly(2+sqrt(2), 1e-5)
    @fact norm(getvalue(x)-[1+sqrt(1/2),1+sqrt(1/2),1]) --> roughly(0, 1e-6)
    @fact getvalue(norm(x-1)) --> roughly(1, 1e-5)
    @fact getvalue(norm(x-1)-2) --> roughly(-1, 1e-5)
end; end; end

facts("[qcqpmodel] Test quad problem modification") do
for solver in quad_solvers
context("With solver $(typeof(solver))") do

    modQ = Model(solver=solver)
    @variable(modQ, x >= 0)
    @constraint(modQ, x*x <= 1)
    @objective(modQ, Max, x)
    @fact solve(modQ) --> :Optimal
    @fact getobjectivevalue(modQ) --> roughly(1.0, 1e-6)

    @constraint(modQ, 2x*x <= 1)
    @fact modQ.internalModelLoaded --> true
    @fact solve(modQ) --> :Optimal
    @fact getobjectivevalue(modQ) --> roughly(sqrt(0.5), 1e-6)

    modQ = Model(solver=solver)
    @variable(modQ,   0 <= x <= 1)
    @variable(modQ, 1/2 <= y <= 1)
    @objective(modQ, Min, x*x - y)
    @fact solve(modQ) --> :Optimal
    @fact getobjectivevalue(modQ) --> roughly(-1.0, 1e-6)

    @objective(modQ, Min, y*y - x)
    @fact modQ.internalModelLoaded --> true
    @fact solve(modQ) --> :Optimal
    @fact getobjectivevalue(modQ) --> roughly(-0.75, 1e-6)
end; end; end

facts("[qcqpmodel] Rotated second-order cones") do
for solver in rsoc_solvers
context("With solver $(typeof(solver))") do
    mod = Model(solver=solver)

    @variable(mod, x[1:5] >= 0)
    @variable(mod, 0 <= u <= 5)
    @variable(mod, v)

    @objective(mod, Max, v)

    @constraint(mod, norm(x) <= 1)
    @constraint(mod, v^2 <= u * x[1])

    @fact solve(mod) --> :Optimal
    @fact getvalue(x) --> roughly([1,0,0,0,0], 1e-2)
    @fact getvalue(u) --> roughly(5, 1e-4)
    @fact getvalue(v) --> roughly(sqrt(5), 1e-6)
    @fact getvalue(norm(x)) --> roughly(1, 1e-4)
end; end; end


text:
### A Pluto.jl notebook ###
# v0.12.20

using Markdown
using InteractiveUtils

# ╔═╡ 17ce391a-58a1-11eb-0cc3-27ab49468914
using DifferentialEquations

# ╔═╡ 45f4efec-65f0-11eb-1a0a-3788d5efdc78
using StaticArrays

# ╔═╡ 402dc84e-65f1-11eb-2539-37f0fe257197
using Plots

# ╔═╡ 50faac0c-58a2-11eb-0b45-913e36bec28c
md"**ODEs**

We solve the following set of first order odes which describes **structure of homologus star**

$$\frac{dp}{dm} = - \frac{m}{x^4}, \frac{dx}{dm} = \frac{t^b}{x^2p^a}, \frac{dt}{dm} = - \frac{p^{an}l}{x^4 t^{3+s+bn}}, \frac{dl}{dm} = A p^{a\lambda}t^{\nu-b\lambda}$$
"

# ╔═╡ abe0e024-58a1-11eb-3d89-45c25419d716
function stellar_structure(u, params, m)
    a, b, n, s, ν, λ, A = params
    p, x, t, l = u
    dp = - (m / x^4)
    dx = (t^b / (x^2 * p^a))
    dt = - (p^(a * n) * l) / (x^4 * t^(3 + s + b * n))
    dl = A * p^(a * λ) * t^(ν - (b * λ))
	@SVector [dp, dx, dt, dl]
end

# ╔═╡ 1863311a-58a3-11eb-18ca-bfa5e090d38e
md"**Callback function**

We want to know the value of $m$ where $p$ goes to zero. For this we need to use the callback function. First we set the condtion i.e $p$ goes to zero at the event. In practical we set a value below which say that p is sufficiently small."

# ╔═╡ fd2312b8-58a1-11eb-2e96-a94a16e0e8ca
condition(u, m, integrator) =  u[1];

# ╔═╡ 6d9108e4-58a3-11eb-2bf7-e78d60fe87f4
md"We then need to specify what to do when the event is detected, i.e., the condition is satisfied. We here want to just stop the integration. This is done using the following"

# ╔═╡ 0bd12e44-58a2-11eb-0268-8b77422861ff
affect!(integrator) = terminate!(integrator);

# ╔═╡ 2a177554-58a5-11eb-21fb-f3f3112aa6d5
cb = ContinuousCallback(condition, affect!);

# ╔═╡ aa0096a8-58a3-11eb-0151-a333ecc27932
md"**Parameters**

Now to solve the set of odes we specify the values of the parameters as well as the initial values. First we set the values of the parameters. We will set A later."

# ╔═╡ c6f7d528-58a3-11eb-0286-67213e4687f7
begin
	a = 1.0
	b = 1.0
	n = 0.0
	s = 0.0
	ν = 4.0
	λ = 1.0
end

# ╔═╡ fc9efeae-58a3-11eb-28ec-857b69eb26bb
md"**Initial values**

Now we set the initial values. If we take a carefull look at the odes, then we see that $\frac{dp}{dm}$ and $\frac{dx}{dm}$ have $x^4$ and $x^2$, respectively, in the denominator. We start our integration from $m=0$, where $x$ and $l$ are zero. However this makes the gardient diverge. Therefore we take small non-zero values for $x$ instead of zero"

# ╔═╡ a0fa6b00-58a4-11eb-15c8-1540d56d1781
begin
	p0 = 1.0
	x0 = 1e-4
	t0 = 1.0
	l0 = 0.0
	u0 = @SVector [p0, x0, t0, l0]
end

# ╔═╡ be3c61d2-58a4-11eb-0b28-e7092c004530
md"We also need specify the domain of integration"

# ╔═╡ cb8fa8bc-58a4-11eb-066f-915f0c57d6fa
mspan = (0, 100.0)

# ╔═╡ dea60fd6-58a4-11eb-1656-6fe62b037ed4
md"**Solve ODE**

Now we are ready to set the ODE problem"

# ╔═╡ ec10984e-58a4-11eb-14c6-c5b8b047b955
begin
	params1 = [a, b, n, s, ν, λ, 0.5]
	problem1 = ODEProblem(stellar_structure, u0, mspan, params1);
end

# ╔═╡ 1141ef96-58a5-11eb-347e-b1a3fc705b0c
solution1 = solve(problem1, callback=cb)

# ╔═╡ 93817b8e-58aa-11eb-3116-4f4be1645bc3
solution1.t[end]

# ╔═╡ 9d037e8c-58aa-11eb-0cd2-818a684914fe
solution1.u[end]

# ╔═╡ 61558144-58a7-11eb-3b11-9dd48ad009a5
md"**Plot Solution**"

# ╔═╡ 9cdff58c-65f4-11eb-0704-47631de5b2a4
gr()

# ╔═╡ cf7cd588-65f3-11eb-0f95-97a0bc0c586d
begin
	colors = [:red, :green, :blue, :orange]
	labels = ["p", "x", "t", "m"]
	styles = [:solid, :dash, :dot, :dashdot]
end

# ╔═╡ 7c9d4d50-65f2-11eb-282b-f55027ec1222
begin
	global p = plot()
	for idx in 1:4
		global p = plot!(solution1, vars = (0, idx), color = colors[idx], ls = styles[idx], label = labels[idx])
	end
	plot!(xlim = (0, 100), ylim = (0, 1))
end

# ╔═╡ 4aec840e-58d7-11eb-2f48-93558ced3c13
md"Let us now find A for which p and t goes zero at the same value of m"

# ╔═╡ b835d0fa-65f5-11eb-34b7-8f18d3a7ef68
begin
	params2 = [a, b, n, s, ν, λ, 0.534]
	problem2 = ODEProblem(stellar_structure, u0, mspan, params2);
end

# ╔═╡ d1872548-65f5-11eb-02b5-c184e4141842
solution2 = solve(problem2, callback = cb)

# ╔═╡ e8eda41e-65f5-11eb-133b-e7140ded270b
begin
	global p2 = plot()
	for idx in 1:4
		global p2 = plot!(solution2, vars = (0, idx), color = colors[idx], ls = styles[idx], label = labels[idx])
	end
	plot!(xlim = (0, 12), ylim = (0, 1))
end

# ╔═╡ Cell order:
# ╠═17ce391a-58a1-11eb-0cc3-27ab49468914
# ╟─50faac0c-58a2-11eb-0b45-913e36bec28c
# ╠═45f4efec-65f0-11eb-1a0a-3788d5efdc78
# ╠═abe0e024-58a1-11eb-3d89-45c25419d716
# ╟─1863311a-58a3-11eb-18ca-bfa5e090d38e
# ╠═fd2312b8-58a1-11eb-2e96-a94a16e0e8ca
# ╟─6d9108e4-58a3-11eb-2bf7-e78d60fe87f4
# ╠═0bd12e44-58a2-11eb-0268-8b77422861ff
# ╠═2a177554-58a5-11eb-21fb-f3f3112aa6d5
# ╟─aa0096a8-58a3-11eb-0151-a333ecc27932
# ╠═c6f7d528-58a3-11eb-0286-67213e4687f7
# ╟─fc9efeae-58a3-11eb-28ec-857b69eb26bb
# ╠═a0fa6b00-58a4-11eb-15c8-1540d56d1781
# ╟─be3c61d2-58a4-11eb-0b28-e7092c004530
# ╠═cb8fa8bc-58a4-11eb-066f-915f0c57d6fa
# ╟─dea60fd6-58a4-11eb-1656-6fe62b037ed4
# ╠═ec10984e-58a4-11eb-14c6-c5b8b047b955
# ╠═1141ef96-58a5-11eb-347e-b1a3fc705b0c
# ╠═93817b8e-58aa-11eb-3116-4f4be1645bc3
# ╠═9d037e8c-58aa-11eb-0cd2-818a684914fe
# ╟─61558144-58a7-11eb-3b11-9dd48ad009a5
# ╠═402dc84e-65f1-11eb-2539-37f0fe257197
# ╠═9cdff58c-65f4-11eb-0704-47631de5b2a4
# ╠═cf7cd588-65f3-11eb-0f95-97a0bc0c586d
# ╠═7c9d4d50-65f2-11eb-282b-f55027ec1222
# ╟─4aec840e-58d7-11eb-2f48-93558ced3c13
# ╠═b835d0fa-65f5-11eb-34b7-8f18d3a7ef68
# ╠═d1872548-65f5-11eb-02b5-c184e4141842
# ╠═e8eda41e-65f5-11eb-133b-e7140ded270b


text:
function PR(A, α = 0.85, maxiters = 100, ϵ = 1.0e-4)
    d = reduce(+, A; dims=2)
    n = size(A, 1)
    r = GBVector(n, 1.0 / n)
    t = GBVector{Float64}(n)
    d[:, accum=/] = α
    teleport = (1 - α) / n
    for _ ∈ 1:maxiters
        temp = t; t = r; r = temp
        w = t ./ d
        r[:] = teleport
        mul!(r, A', w, (+, second), accum=+)
        t .-= r
        map!(abs, t)
        if reduce(+, t) <= ϵ
            break
        end
    end
    return r
end


text:
module StrideArraysCore

using LayoutPointers, ArrayInterface, ThreadingUtilities, ManualMemory, IfElse, Static
using ArrayInterface: StaticInt, Zero, One, StaticBool, True, False,
  OptionallyStaticUnitRange, size, strides, offsets, indices,
  static_length, static_first, static_last, axes,
  dense_dims, stride_rank, StrideIndex, contiguous_axis_indicator
using LayoutPointers:
  AbstractStridedPointer, StridedPointer, StridedBitPointer,
  bytestrides, zstridedpointer,
  val_dense_dims, val_stride_rank
using CloseOpenIntervals

using ManualMemory: preserve_buffer, offsetsize, MemoryBuffer

using SIMDTypes: NativeTypes, Bit

export PtrArray, StrideArray, StaticInt, static

@generated static_sizeof(::Type{T}) where {T} = :(StaticInt{$(Base.allocatedinline(T) ? sizeof(T) : sizeof(Int))}())
include("ptr_array.jl")
include("stridearray.jl")
include("thread_compatible.jl")
include("views.jl")
include("adjoints.jl")

# function __init__()
#     # @require LoopVectorization="bdcacae8-1622-11e9-2a5c-532679323890" @eval using StrideArrays
# end

end


text:
#=
example2:
- Julia version:
- Author: Ashley Sommer
- Date: 2020-01-03

This example gets details of a single CosmOz station
=#

using Printf
using JSON
using HTTP

const COSMOZ_API_URL = "https://esoil.io/cosmoz-data-pipeline/rest/"  # Keep the trailing slash on here.
const STATION_NUMBER = 21
# Endpoint to get a station details is "pipeline/rest/stations/{id}"
stations_endpoint = COSMOZ_API_URL * "stations"
station_endpoint = stations_endpoint * "/" * string(STATION_NUMBER)
# Add a header to specifically ask for JSON output
request_headers = Dict("Accept"=>"application/json",)
# Construct a GET request, with that URL and those headers
r = HTTP.request("GET", station_endpoint, request_headers)
payload = JSON.parse(String(r.body))
println("Showing raw payload")
println(payload)
println()
println("Station $(string(STATION_NUMBER)) details:")
for (k, v) in payload
    println("\t$(string(k)): $(string(v))")
end


text:
using PAPI, Test

mk_eventstats(events::Vector{Event}, n=10) = PAPI.EventStats(events, rand(Counts, (n, length(events))), rand(Counts, n))
mk_eventvalues(events::Vector{Event}) = PAPI.EventValues(events, rand(Counts, length(events)), rand(Counts))

function equals(x::T, y::T) where {T<:PAPI.SUPPORTED_TYPES}
    all(i->equals(getfield(x, i), getfield(y, i)), 1:fieldcount(T))
end
equals(x::Vector{Event}, y::Vector{Event}) = ==(x, y)
equals(x, y) = isapprox(x, y)

@testset "serialization" begin
    events = Event[PAPI.BR_INS, PAPI.BR_MSP, PAPI.TOT_INS, PAPI.TOT_CYC]
    stats = mk_eventstats(events)
    values = mk_eventvalues(events)

    let io = IOBuffer()
        save(io, stats, values)
        seekstart(io)
        x = load(io)
        @test length(x) == 2
        @test equals(x[1], stats)
        @test equals(x[2], values)
    end
end


text:
using EffectiveWaves

using Plots
# unicodeplots() # alternative plot backend
height=500
pyplot(linewidth=3, size=(2.0*height,height))

# for fixed total volfrac fraction
medium = Medium(ρ=3200.0,c = 2595.0)
ωs = 2.0*pi*LinRange(1.0e1,1.0e7,100)

volfrac = 0.12
r1 = 30.0e-8
r2 = 2*30.0e-6

sp1 = Specie(ρ=2329.,r=r1,c=8433.,volfrac = 0.06)
sp2 = Specie(ρ=2329.,r=r2,c=8433.,volfrac = volfrac-0.06)

vol = pi*sp1.num_density*sp1.r^2

rhoeff =  medium.ρ*(medium.ρ + sp1.ρ - vol*(medium.ρ - sp1.ρ))/
(medium.ρ + sp1.ρ + vol*(medium.ρ - sp1.ρ))

# rhoeff =  medium.ρ*(1.0-vol) + vol*sp1.ρ
# rhoeff =  medium.ρ*(1 + volfrac)/(1 - volfrac)

kTs = [ wavenumber_low_volfrac(ω, medium, [sp1,sp2]) for ω in ωs]
kTaprx =[ two_species_approx_wavenumber(ω, medium, [sp1,sp2]) for ω in ωs]

kTSs =[ wavenumber_low_volfrac(ω, medium, [sp1]) for ω in ωs]
kTLs = [
  begin
    mS = Medium(ρ=rhoeff, c= ωs[i]/kTSs[i])
    wavenumber_low_volfrac(ωs[i], mS, [sp2])
  end
for i in eachindex(ωs)];

# speed_arr = [ [ωs./real(kTs)], [0.029 .+ ωs./real(kTLs)]]
speed_arr = [ ωs./real(kTs), ωs./real(kTLs), ωs./real(kTaprx)]
atten_arr = imag([kTs,kTLs, kTaprx])

labs = reshape(["kT","kTL", "kTaprx"] ,1, 3);
p1 = plot(r1.*(ωs./real(medium.c))/(2pi), speed_arr, labels=labs, xlabel="a/λ", ylabel="wave speed");
p2 = plot(r1.*(ωs./real(medium.c))/(2pi), atten_arr, labels=labs, xlabel="a/λ", ylabel="attenuation");
plot(p1,p2)
gui()

speed_arr = [abs.(1 .- real(kTLs)./real(kTs))]
p1 = plot(r1.*(ωs./real(medium.c))/(2pi), speed_arr, labels=labs, xlabel="a/λ", ylabel="relative wave speed");


text:
module ElasticFDA

## Requirements
using Interpolations
using Dierckx
using NLopt
using ProgressMeter
using Distributions
using Printf
using Distributed
using Statistics
using LinearAlgebra
using RecipesBase
using Cxx
using Libdl

import Base. summary

export
    smooth_data!,
    smooth_data,
    f_to_srsf,
    srsf_to_f,
    optimum_reparam,
    warp_q_gamma,
    warp_f_gamma,
    vert_fPCA,
    horiz_fPCA,
    gauss_model,
    group_warping_bayes,
    pair_warping_bayes,
    pair_warping_expomap,
    elastic_distance,
    elastic_regression,
    elastic_logistic,
    elastic_prediction,
    srsf_align,
    align_fPCA,
    trapz,
    gradient,
    rgam,
    curve_karcher_mean,
    curve_srvf_align,
    curve_principal_directions,
    curve_karcher_cov,
    sample_shapes,
    curve_to_q,
    q_to_curve,
    calc_shape_dist,
    curve_pair_align,
    curve_geodesic,
    resamplecurve,
    bs,
    project_curve,
    inverse_exp_coord,
    inverse_exp,
    project_tangent

# load fdasrsf library
if (Sys.isunix())
    path = "../deps/src/fdasrsf/fdasrsf"
else
    path = "..\\deps\\fdasrsf"
end
const libfdasrsf = joinpath(dirname(@__FILE__), path)

# load gropt library
if (Sys.isunix())
    path1 = "../deps/src/gropt/gropt"
else
    path1 = "..\\deps\\gropt"
end
const libgropt = joinpath(dirname(@__FILE__), path1)

# load fdaqmap library
if (Sys.isunix())
    path2 = "../deps/src/fdaqmap/fdaqmap"
else
    path2 = "..\\deps\\fdaqmap"
end
const libfdaqmap = joinpath(dirname(@__FILE__), path2)

# Ensure library is available.
function __init__()
    if (dlopen_e(libfdasrsf) == C_NULL)
        error("libfdasrsf not properly installed. Run build(\"ElasticFDA\")")
    end

   if (dlopen_e(libgropt) == C_NULL)
        error("libgropt not properly installed. Run build(\"ElasticFDA\")")
    end

   if (dlopen_e(libfdaqmap) == C_NULL)
       error("libfdaqmap not properly installed. Run build(\"ElasticFDA\")")
   end

end

### source files
include("types.jl")
include("geometry.jl")
include("summary.jl")
include("plots.jl")
include("curve_funcs.jl")
include("curve_stats.jl")
include("srsf_funcs.jl")
include("misc_funcs.jl")
include("fPCA.jl")
include("bspline.jl")
include("dp_bayes.jl")
include("mcmc_align.jl")
include("gauss_model.jl")
include("group_warping_bayes.jl")
include("pair_warping_bayes.jl")
include("regression.jl")
include("regression_funcs.jl")
include("time_warping.jl")
include("pair_warping_expomap.jl")
include("image_funcs.jl")
include("image_stats.jl")

end # module


text:
"""
    Fill(; value=mean, context=Context())

Fills in the missing data with a specific value.
The current implementation is univariate, so each variable in a table or matrix will
be handled independently.

# Keyword Arguments
* `value::Any`: A scalar or a function that returns a scalar if
  passed the data with missing data removed (e.g, `mean`)
* `context::AbstractContext`: A context which keeps track of missing data
  summary information

# Example
"""
struct Fill{T} <: Imputor
    value::T
    context::AbstractContext
end

# TODO: Switch to using Base.@kwdef on 1.1
Fill(; value=mean, context=Context()) = Fill(value, context)

function impute!(data::AbstractVector, imp::Fill)
    imp.context() do c
        fill_val = if isa(imp.value, Function)
            # Call `deepcopy` because we can trust that it's available for all types.
            imp.value(Impute.drop(data; context=c))
        else
            imp.value
        end

        for i in eachindex(data)
            if ismissing!(c, data[i])
                data[i] = fill_val
            end
        end

        return data
    end
end


text:
#Pkg.add("Plots")
using Plots

x = -3:0.1:3
f(x) = x^2

y = f.(x)

gr()

plot(x, y, label="linea")
scatter!(x, y, label="puntos")

plotlyjs()

plot(x, y, label="line")
scatter!(x, y, label="points")

globaltemperatures = [14.4, 14.5, 14.8, 15.2, 15.5, 15.8]
numpirates = [45000, 20000, 15000, 5000, 400, 17]

# Primero plotteamos los datos
plot(numpirates, globaltemperatures, legend=false)
scatter!(numpirates, globaltemperatures, legend=false)

# Agregamos Títulos y etiquetas/labels.
xlabel!("Número de piratas [Apróx.]")
ylabel!("Temperatura Global (C)")
title!("Influencia de población de piratas en calentamiento global")

# Primero graficamos datos
plot(numpirates, globaltemperatures, legend=false)
scatter!(numpirates, globaltemperatures, legend=false)

# Este comando invierte el eje x para que podamos ver los cambios hacia adelante en el tiempo, de 1860 a 2000
xflip!()

# Add titles and labels
xlabel!("Number of Pirates [Approximate]")
ylabel!("Global Temperature (C)")
title!("Influence of pirate population on global warming")

p1 = plot(x, x)
p2 = plot(x, x.^2)
p3 = plot(x, x.^3)
p4 = plot(x, x.^4)
plot(p1,p2,p3,p4,layout=(2,2),legend=false)

max_stars_repo_name: miguelraz/JuliaTutorials

max_issues_repo_name: miguelraz/JuliaTutorials

max_forks_repo_name: miguelraz/JuliaTutorials


text:
"""
A [Julia](https://julialang.org/) threaded audio output interface to [PortAudio](https://github.com/JuliaAudio/PortAudio.jl) that allows dynamic real-time changes to your audio code while it is playing.  This is useful for quickly iterating your code in Julia's REPL or a [Jupyter](https://jupyter.org/) [notebook](https://github.com/JuliaLang/IJulia.jl).

See [documentation and examples](https://github.com/cduck/InteractiveAudio.jl).
"""
module InteractiveAudio

using Base.Threads
using Base: lock, unlock, trylock, islocked, ReentrantLock

using SampledSignals
using PortAudio

export BackgroundPlayer, play, pause, is_playing, lock_player
export AbstractAudioGenerator, NullAudioGenerator, SampleAudioGenerator,
    SineAudioGenerator, SumAudioGenerator, MutateAudioGenerator

include("audio_generator.jl")
include("background_player.jl")
include("sample_audio_generator.jl")
include("sine_audio_generator.jl")
include("sum_audio_generator.jl")
include("mutate_audio_generator.jl")

end


text:
# test_multigrid.jl : test multigrid implementation

for (d,d_name) in zip(2:3,["₂","₃"])
    @testset "Default Multigrid methods for $(d)D anisotropic problems" begin
        for (problem, problem_name) in zip(["p₁","p₂","p₃","p₄"],["     LAPLACE $(d)D      ","     ELLIPTIC $(d)D     ","   ANISOTROPIC $(d)D    ","ROTATED ANISTROPIC $(d)D"])
            if !( d == 3 && problem == "p₄" )
                println("*************************")
                println("* $(problem_name) *")
                println("*************************")
                for (method,method_name) in zip([V_cycle, W_cycle, F_cycle],["V-CYCLE", "W-CYCLE", "  FMG  "])
                    println("+-----------------------+")
                    println("|         $(method_name)       |")
                    println("+-----------------------+")
                    for n in 2 .^(1:(12-2d))
                        print("n = $(n)...")
                        A = method(eval(Symbol(problem,d_name))(n),ntuple(i->n,d))
                        b = ones(prod([n-1 for i in 1:d]))
                        x = A\b
                        @test A.resnorm[end] < 1/n^d
                        println("done ($(length(A.resnorm)-1) iterations)")
                    end
                end
            end
        end
    end
end


text:
# # File-based I/O
#
# LongwaveModePropagator provides basic propagation capabilities
# interfacing through [JSON](https://www.json.org/json-en.html) files.
# Julia is still needed to run the model, but scenarios can otherwise
# be defined and analyzed from e.g. Matlab or Python.
#
# Examples of writing and reading compatible JSON files are provided below
# for [Matlab](@ref matlab_json) and [Python](@ref python_json).
#
# Let's load the necessary packages.

using Dates
using JSON3

using LongwaveModePropagator
nothing #hide

# Throughout the examples, we'll also define `LMP` as shorthand for
# `LongwaveModePropagator` when accessing functions from the package that
# aren't exported.

const LMP = LongwaveModePropagator
nothing  #hide

# ## Inputs
#
# There are two primary ways to define [`LongwaveModePropagator.Input`](@ref)s,
# the abstract supertype for
# inputing information to the model.
#
# ### [ExponentialInput](@id basicinput_io)
#
# The first is known as a [`ExponentialInput`](@ref). It defines the ionosphere using
# Wait and Spies ``h'`` and ``\beta`` parameters.
#
# It contains the fields
#
# - `name::String`
# - `description::String`
# - `datetime::DateTime`
# - `segment_ranges::Vector{Float64}`: distance from transmitter to the beginning of each `HomogeneousWaveguide` segment in meters.
# - `hprimes::Vector{Float64}`: Wait's ``h'`` parameter for each `HomogeneousWaveguide` segment.
# - `betas::Vector{Float64}`: Wait's ``\beta`` parameter for each `HomogeneousWaveguide` segment.
# - `b_mags::Vector{Float64}`: magnetic field magnitude for each `HomogeneousWaveguide` segment.
# - `b_dips::Vector{Float64}`: magnetic field dip angles in radians for each `HomogeneousWaveguide` segment.
# - `b_azs::Vector{Float64}`: magnetic field azimuth in radians "east" of the propagation direction for each `HomogeneousWaveguide` segment.
# - `ground_sigmas::Vector{Float64}`: ground conductivity in Siemens per meter for each `HomogeneousWaveguide` segment.
# - `ground_epsrs::Vector{Int}`: ground relative permittivity for each `HomogeneousWaveguide` segment.
# - `frequency::Float64`: transmitter frequency in Hertz.
# - `output_ranges::Vector{Float64}`: distances from the transmitter at which the field will be calculated.
#
# The fields that are vectors allow the definition of a [`SegmentedWaveguide`](@ref)
# where each element of the vector is its own [`HomogeneousWaveguide`](@ref) segment.
# Single element vectors are treated as a single `HomogeneousWaveguide`.
#
# To show the equivalent JSON format, we'll build a simple, homogeneous ionosphere
# `ExponentialInput`. It's defined as a `mutable struct`, so it is simple to specify the
# fields one by one.

input = ExponentialInput()
input.name = "basic"
input.description = "Test ExponentialInput"
input.datetime = DateTime("2020-12-29T05:00:00.000")  # usually `Dates.now()`

input.segment_ranges = [0.0]
input.hprimes = [75]
input.betas = [0.35]
input.b_mags= [50e-6]
input.b_dips = [π/2]
input.b_azs = [0.0]
input.ground_sigmas = [0.001]
input.ground_epsrs = [4]
input.frequency = 24e3
input.output_ranges = collect(0:100e3:1000e3)

# Here it is formatted as JSON.

json_str = JSON3.pretty(input)

# Let's also save this to a file.

json_str = JSON3.write(input)

root_dir = dirname(dirname(pathof(LongwaveModePropagator)))
examples_dir = joinpath(root_dir, "examples")
filename = joinpath(examples_dir, "basic.json")

open(filename,"w") do f
    write(f, json_str)
end
nothing  #hide

# ### [TableInput](@id tableinput_io)
#
# The second input is the [`TableInput`](@ref). This type defines the ionosphere using
# a tabular input of number density and collision frequency as a function of altitude.
# These tables are then cubic spline interpolated when integrating the ionosphere
# reflection coefficient and wavefields.
# See also [interpolating functions](@ref interpolating-functions).
#
# The fields of the `TableInput` are
#
# - `name::String`
# - `description::String`
# - `datetime::DateTime`
# - `segment_ranges::Vector{Float64}`: distance from transmitter to the beginning of each `HomogeneousWaveguide` segment in meters.
# - `altitude::Vector{Float64}`: altitude above ground in meters for which the `density` and `collision_frequency` profiles are specified.
# - `density::Vector{Float64}`: electron density at each `altitude` in ``m⁻³``.
# - `collision_frequency::Vector{Float64}`: electron-ion collision frequency at each `altitude` in ``s⁻¹``.
# - `b_dips::Vector{Float64}`: magnetic field dip angles in radians for each `HomogeneousWaveguide` segment.
# - `b_azs::Vector{Float64}`: magnetic field azimuth in radians "east" of the propagation direction for each `HomogeneousWaveguide` segment.
# - `ground_sigmas::Vector{Float64}`: ground conductivity in Siemens per meter for each `HomogeneousWaveguide` segment.
# - `ground_epsrs::Vector{Int}`: ground relative permittivity for each `HomogeneousWaveguide` segment.
# - `frequency::Float64`: transmitter frequency in Hertz.
# - `output_ranges::Vector{Float64}`: distances from the transmitter at which the field will be calculated.
#
# Again we'll construct a `TableInput` to look at the JSON

tinput = TableInput()
tinput.name = "table"
tinput.description = "Test TableInput"
tinput.datetime = DateTime("2020-12-29T05:00:00.000")

tinput.segment_ranges = [0.0]
tinput.altitude = collect(50e3:5e3:100e3)
tinput.density = [waitprofile.(tinput.altitude, 75, 0.3)]
tinput.collision_frequency = [electroncollisionfrequency.(tinput.altitude)]
tinput.b_mags= [50e-6]
tinput.b_dips = [π/2]
tinput.b_azs = [0.0]
tinput.ground_sigmas = [0.001]
tinput.ground_epsrs = [4]
tinput.frequency = 24e3
tinput.output_ranges = collect(0:100e3:1000e3)

json_str = JSON3.pretty(tinput)

# ### [BatchInput](@id batchinput_io)
#
# Both the `ExponentialInput` and `TableInput` types can be collected together in a
# [`BatchInput`](@ref) which has fields
# for a `name`, `description`, `datetime`, and vector of `Inputs`.
# This is useful for keeping a set of scenarios together.
# See the [test/IO.jl](@__REPO_ROOT_URL__/test/IO.jl) file
# for additional help on how these should be formatted.
#
# ## Running the model from a JSON file
#
# To run the model, [`propagate`](@ref) accepts a filename input
# (see the help for optional arguments). However, instead of returning a
# tuple of complex electric field, amplitude, and phase, it returns an `Output`
# type. Additionally, it saves the output to a JSON file.

output = propagate(filename);

# ## Outputs
#
# There are only two [`LongwaveModePropagator.Output`](@ref) types:
# [`BasicOutput`](@ref) and [`BatchOutput`](@ref).
# Both `ExponentialInput`s and `TableInput`s create `BasicOutput`s, but the `BatchInput`
# creates a `BatchOutput`.
#
# The `BasicOutput` contains fields for
#
# - `name::String`
# - `description::String`
# - `datetime::DateTime`
# - `output_ranges::Vector{Float64}`
# - `amplitude::Vector{Float64}`
# - `phase::Vector{Float64}`
#
# where `name` and `description` are directly copied from the input and `datetime`
# is when the model was run.

output

# Not surprisingly, a `BatchOutput` is simply a container holding a `Vector` of
# `BasicOutput`s, as well as some additional metadata from the corresponding `BatchInput`.

# ## [JSON I/O from Matlab](@id matlab_json)
#
# Here's an example of how to encode the above `ExponentialInput` to JSON and
# decode the output using [Matlab](https://www.mathworks.com/help/matlab/json-format.html).
# It's also in the file [examples/io.m](@__REPO_ROOT_URL__/examples/io.m).
#
# ```matlab
# % Matlab script
#
# input.name = "basic";
# input.description = "Test ExponentialInput";
# input.datetime = '2020-12-28T21:06:50.501';
#
# input.segment_ranges = {0.0};
# input.hprimes = {75};
# input.betas = {0.35};
# input.b_mags = {50e-6};
# input.b_dips = {pi/2};
# input.b_azs = {0.0};
# input.ground_sigmas = {0.001};
# input.ground_epsrs = {4};
# input.frequency = 24e3;
# input.output_ranges = 0:100e3:1000e3;
#
# json_str = jsonencode(input);
#
# fid = fopen('basic_matlab.json', 'w');
# fwrite(fid, json_str, 'char');
# fclose(fid);
# ```
#
# Matlab was used to generate the file
# [`basic_matlab.json`](@__REPO_ROOT_URL__/examples/basic_matlab.json).
# We can confirm it's parsed correctly by using the internal
# LongwaveModePropagator function [`LongwaveModePropagator.parse`](@ref), which attempts to parse
# JSON files into recognized input and output formats.

matlab_input = LMP.parse(joinpath(examples_dir, "basic_matlab.json"))

# Let's run it.

matlab_output = propagate(joinpath(examples_dir, "basic_matlab.json"));

# !!! note
#     It is possible to run Julia as a script, calling it directly from a terminal
#     (see [the docs](https://docs.julialang.org/en/v1/manual/getting-started/)), but
#     it is probably easiest to just run the code from the REPL.
#
#     1. `cd` in a terminal to your working directory
#     2. Start up Julia: `julia`
#     3. It's recommended to `] activate .`, generating a new environment in this directory
#     4. If necessary, install LongwaveModePropagator.jl: `] add LongwaveModePropagator`
#     5. `using LongwaveModePropagator`
#     6. `propagate("basic_matlab.json")`
#
#     If this has been done before in the same directory, then just do steps 1, 2, 5, 6.
#
# Reading the results file from Matlab is relatively simple.
#
# ```matlab
# % Matlab script
#
# filename = 'basic_matlab_output.json';
#
# text = fileread(filename);
#
# output = jsondecode(text);
# ```
#
# ## [JSON I/O from Python](@id python_json)
#
# Here is similar code for [Python](https://docs.python.org/3/library/json.html),
# also available in the file
# [io.py](@__REPO_ROOT_URL__/examples/io.py).
#
# ```python
# # Python script
#
# import json
# import datetime
# import numpy as np
#
# input = dict()
#
# input['name'] = "basic"
# input['description'] = "Test ExponentialInput"
# input['datetime'] = datetime.datetime.now().isoformat()[:-3]
#
# input['segment_ranges'] = [0.0]
# input['hprimes'] = [75]
# input['betas'] = [0.35]
# input['b_mags'] = [50e-6]
# input['b_dips'] = [np.pi/2]
# input['b_azs'] = [0.0]
# input['ground_sigmas'] = [0.001]
# input['ground_epsrs'] = [4]
# input['frequency'] = 24e3
# input['output_ranges'] = np.arange(0, 1000e3, 100e3).tolist()
#
# json_str = json.dumps(input)
#
# with open('basic_python.json', 'w') as file:
#     file.write(json_str)
# ```
#
# Let's ensure that the JSON file is correctly parsed.

python_input = LMP.parse(joinpath(examples_dir, "basic_python.json"))

# And run the file.

python_output = propagate(joinpath(examples_dir, "basic_python.json"));

# To read the results:
#
# ```python
# with open('basic_python_output.json', 'r') as file:
#     output = json.load(file)
# ```


text:
export SimulationControllerParams, SimulationController, getSimulationControllers,
       getSimulationController, getSimulatedCoilTemperatures

Base.@kwdef struct SimulationControllerParams <: DeviceParams
  "Initial coil temperatures mapped by the tx channel IDs."
  initialCoilTemperatures::Union{Dict{String, typeof(1.0u"°C")}, Nothing} = nothing
end

SimulationControllerParams(dict::Dict) = params_from_dict(SimulationControllerParams, dict)

Base.@kwdef mutable struct SimulationController <: VirtualDevice
  "Unique device ID for this device as defined in the configuration."
  deviceID::String
  "Parameter struct for this devices read from the configuration."
  params::SimulationControllerParams
  "Flag if the device is optional."
	optional::Bool = false
  "Flag if the device is present."
  present::Bool = false
  "Vector of dependencies for this device."
  dependencies::Dict{String, Union{Device, Missing}}

  "Current coil temperatures mapped by the tx channel IDs."
  coilTemperatures::Union{Dict{String, typeof(1.0u"°C")}, Nothing} = nothing
end

function getSimulationControllers(scanner::MPIScanner)
  simulationControllers = getDevices(scanner, SimulationController)
  if length(simulationControllers) > 1
    error("The scanner has more than one simulation controller device. This should never happen.")
  else
    return simulationControllers
  end
end
getSimulationController(scanner::MPIScanner) = getSimulationControllers(scanner)[1]

function init(simCont::SimulationController)
  @debug "Initializing simulation controller with ID `$(simCont.deviceID)`."

  if !isnothing(simCont.params.initialCoilTemperatures)
    simCont.coilTemperatures = simCont.params.initialCoilTemperatures
  end

  simCont.present = true
end

neededDependencies(::SimulationController) = []
optionalDependencies(::SimulationController) = []

Base.close(simCont::SimulationController) = nothing

currentCoilTemperatures(simCont::SimulationController) = simCont.coilTemperatures
currentCoilTemperatures(simCont::SimulationController, channelID::String) = simCont.coilTemperatures[channelID]
currentCoilTemperatures(simCont::SimulationController, channelID::String, value::typeof(1.0u"K")) = simCont.coilTemperatures[channelID] = value

initialCoilTemperatures(simCont::SimulationController) = simCont.params.initialCoilTemperatures
initialCoilTemperatures(simCont::SimulationController, channelID::String) = simCont.params.initialCoilTemperatures[channelID]


text:
push!(LOAD_PATH,"../src/")

using Documenter, NastranResults

makedocs(sitename="NastranResults")

max_stars_repo_name: mgcth/SDNastran

max_issues_repo_name: mgcth/SDNastran

max_forks_repo_name: mgcth/SDNastran