Code Monkey home page Code Monkey logo

Comments (7)

rafaqz avatar rafaqz commented on September 10, 2024 1

Also apologies I'm busy and on the road at the moment, so I'm missing all the fun. But should have some time for this in a few days.

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

Oops

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

@gottacatchenall used a solution where he allocated a temporary square array big enough to hold the non-square one - might make sense to choose the same approach in the two places?

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

@mkborregaard I agree - @gottacatchenall is this already a function that @rafaqz can re-use?

from neutrallandscapes.jl.

gottacatchenall avatar gottacatchenall commented on September 10, 2024

not quite, i check the size via

function _landscape!(mat, alg::Union{DiamondSquare, MidpointDisplacement}; kw...) where {IT <: Integer}
    rightSize::Bool = _isPowerOfTwo(size(mat)[1]-1) && _isPowerOfTwo(size(mat)[2]-1)

    dsMat = mat
    if !rightSize
        dim1, dim2 = size(mat)
        smallestContainingLattice::Int = 2^ceil(log2(max(dim1, dim2))) + 1
        @warn "$alg cannot be run on the input dimensions ($dim1 x $dim2),
                and will instead run on the next smallest valid size ($smallestContainingLattice x $smallestContainingLattice).
                This can slow performance as it involves additional memory allocation."
        dsMat = zeros(smallestContainingLattice, smallestContainingLattice)
    end
    _diamondsquare!(dsMat, alg)

    mat .= dsMat[1:size(mat)[1], 1:size(mat)[2]]
end

which enforeces it must be square but has the additional condition that the size must be (2^n)+1, although this could be implemented in to something more general like

function _landscape!(mat, alg)
  matPointer = mat
  if !rightSize(mat, alg) 
     # allocation correct size matrix to matPointer
  end 
  mat[:] .= matPointer[1:size(mat)[1], 1:size(mat)[2]] 
end

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

Thats what happens already, I just messed it up somehow

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

This was closed via faaeed5

from neutrallandscapes.jl.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.