Skip to content

Commit

Permalink
update to 0.4, remove warnings, support ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
mykelk committed Dec 15, 2015
1 parent c9f0caf commit 55b2a52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions REQUIRE
@@ -1,2 +1,2 @@
julia 0.2-
Grid
julia 0.4
Grid
12 changes: 6 additions & 6 deletions src/GridInterpolations.jl
Expand Up @@ -34,7 +34,7 @@ dimensions(grid::RectangleGrid) = length(grid.cut_counts)

dimensions(grid::SimplexGrid) = length(grid.cut_counts)

function RectangleGrid(cutPoints::Vector{Float64}...)
function RectangleGrid(cutPoints...)
cut_counts = Int[length(cutPoints[i]) for i = 1:length(cutPoints)]
cuts = vcat(cutPoints...)
myCutPoints = Array(Vector{Float64}, length(cutPoints))
Expand All @@ -53,7 +53,7 @@ function RectangleGrid(cutPoints::Vector{Float64}...)
RectangleGrid(myCutPoints, cut_counts, cuts, index, weight, index2, weight2)
end

function SimplexGrid(cutPoints::Vector{Float64}...)
function SimplexGrid(cutPoints...)
cut_counts = Int[length(cutPoints[i]) for i = 1:length(cutPoints)]
cuts = vcat(cutPoints...)
myCutPoints = Array(Vector{Float64}, length(cutPoints))
Expand Down Expand Up @@ -122,7 +122,7 @@ function maskedInterpolate(grid::AbstractGrid, data::DenseArray, x::Vector, mask
return val / totalWeight
end

interpolate(grid::AbstractGrid, data::Matrix, x::Vector) = interpolate(grid, float64(data[:]), x)
interpolate(grid::AbstractGrid, data::Matrix, x::Vector) = interpolate(grid, map(Float64, data[:]), x)

function interpolate(grid::AbstractGrid, data::DenseArray, x::Vector)
index, weight = interpolants(grid, x)
Expand Down Expand Up @@ -249,9 +249,9 @@ function interpolants(grid::SimplexGrid, x::Vector)
end

# initialize sort indecies
for i = 1:length(n_ind); n_ind[i] = i; end
for i = 1:length(n_ind); n_ind[i] = i; end
# sort translated and scaled x values
sortperm!(n_ind, x_p, rev=true)
sortperm!(n_ind, x_p, rev=true)
x_p = x_p[n_ind]
n_ind = n_ind - 1

Expand Down Expand Up @@ -291,7 +291,7 @@ function interpolants(grid::SimplexGrid, x::Vector)
end

weight = weight ./ sum(weight)

return index::Vector{Int}, weight::Vector{Float64}
end

Expand Down
8 changes: 3 additions & 5 deletions src/interpBenchmarks.jl
Expand Up @@ -12,7 +12,7 @@ function simplexBenchmark(numDims::Int=6, pointsPerDim::Int=15, numRandomTests::
# gridData = rand(cutsDim...)

# Set up the data structures:
cutPointMat = [0:(1/(pointsPerDim-1)):1]
cutPointMat = 0:(1/(pointsPerDim-1)):1
cutPoints = [cutPointMat for i=1:numDims]
sGrid = SimplexGrid(tuple(cutPoints...)...)
sData = rand(length(sGrid))
Expand Down Expand Up @@ -43,7 +43,7 @@ function rectangleBenchmark(numDims::Int=6, pointsPerDim::Int=15, numRandomTests
# May want to include the Grid module as well, to compare with this implementation

# Set up the data structures:
cutPointMat = [0:(1/(pointsPerDim-1)):1]
cutPointMat = 0:(1/(pointsPerDim-1)):1
cutPoints = [cutPointMat for i=1:numDims]
rGrid = RectangleGrid(tuple(cutPoints...)...)
rData = rand(length(rGrid))
Expand Down Expand Up @@ -73,7 +73,7 @@ function compareBenchmarks(numDims::Int=6, pointsPerDim::Int=15, numRandomTests:
gridData = rand(cutsDim...)

# Set up the data structures:
cutPointMat = [0:(1/(pointsPerDim-1)):1]
cutPointMat = 0:(1/(pointsPerDim-1)):1
cutPoints = [cutPointMat for i=1:numDims]
rGrid = RectangleGrid(tuple(cutPoints...)...)
sGrid = SimplexGrid(tuple(cutPoints...)...)
Expand Down Expand Up @@ -117,5 +117,3 @@ function compareSpeedUp(nDims, nPoints)
end
return speed
end


18 changes: 9 additions & 9 deletions test/runtests.jl
Expand Up @@ -12,7 +12,7 @@ function compareToGrid(testType::Symbol=:random, numDims::Int=3, pointsPerDim::I

# Set up the data structures:
gridI = InterpGrid(gridData, BCnearest, InterpLinear) # This is for the Grid package
cutPointMat = [0:(1/(pointsPerDim-1)):1]
cutPointMat = 0:(1/(pointsPerDim-1)):1
cutPoints = [cutPointMat for i=1:numDims]
gridM = RectangleGrid(tuple(cutPoints...)...) # Mykel's interpolation package

Expand Down Expand Up @@ -95,7 +95,7 @@ end
function getFractionalIndexes(g::AbstractGrid, s::Array)
# Returns the fractional index of sprime within the grid-defined discretization.

fracInd = Array(Float64,length(g.cutPoints))
fracInd = Array(Int64,length(g.cutPoints))

for i=1:length(g.cutPoints)
gridDisc = g.cutPoints[i]
Expand Down Expand Up @@ -124,18 +124,18 @@ function getFracIndex(vararray::Array, value::Float64)
i+=1
end

return i+(value-vararray[i])/(vararray[i+1] - vararray[i])
return i+(value-vararray[i])÷(vararray[i+1] - vararray[i])

end

function simplexMagic(NDISC::Int=20, NPOINTS::Int=3, checkFileName::String="", eps::Float64=1e-10)
function simplexMagic(NDISC::Int=20, NPOINTS::Int=3, checkFileName::AbstractString="", eps::Float64=1e-10)
if isempty(checkFileName)
checkFileName = joinpath(Pkg.dir("GridInterpolations"), "test", "simplexMagicTest20.txt")
end

val = transpose([ [8.,1,6] [3,5,7] [4,9,2] ]) # transposed magic(3) from matlab

sGrid = SimplexGrid([1.:NPOINTS], [1.:NPOINTS])
sGrid = SimplexGrid(1.:NPOINTS, 1.:NPOINTS)
sInterpVal = zeros(NDISC, NDISC)

for i = 1:NDISC, j = 1:NDISC
Expand Down Expand Up @@ -171,14 +171,14 @@ end
function checkCounters()
dims = 2
nPts = 100
grid = RectangleGrid([1.:10], [1.:10])
grid = RectangleGrid(1.:10, 1.:10)
if length(grid) != nPts || dimensions(grid) != dims
return false
end
data = rand(10,10)
temp = interpolate(grid, data, [-1.5,1.5])
temp = interpolate(grid, data, [1.,1.])
grid = SimplexGrid([1.:10], [1.:10])
grid = SimplexGrid(1.:10, 1.:10)
if length(grid) != nPts || dimensions(grid) != dims
return false
end
Expand All @@ -192,9 +192,9 @@ end

function testMask()
x = [1.5, 1.5]
vals = [1.:9]
vals = collect(1.:9)
mask = falses(9)
grid = RectangleGrid([1.:3], [1.:3])
grid = RectangleGrid(1.:3, 1.:3)
interped = interpolate(grid, vals, x)
masked = maskedInterpolate(grid, vals, x, mask)
@test_approx_eq_eps interped masked 1e-3
Expand Down

0 comments on commit 55b2a52

Please sign in to comment.