Skip to content

nn.copy does not perform a copy #2

Description

@dcuny

In line 579 of NeuralLua.lua, the nn.copy function is defined as:

function nn.copy(neural)
  local new_neural = neural
  return new_neural
end

However, this doesn't perform a copy of the table, it just returns a reference to the same table.

Might you have intended a function like this? (see here for source):

-- Perform deep copy
local function deepcopy(orig)
    local orig_type = type(orig)
    local copy
    if orig_type == 'table' then
        copy = {}
        for orig_key, orig_value in next, orig, nil do
            copy[deepcopy(orig_key)] = deepcopy(orig_value)
        end
        setmetatable(copy, deepcopy(getmetatable(orig)))
    else -- number, string, boolean, etc
        copy = orig
    end
    return copy
end

-- create a deep copy of a neural network object
function nn.copy( neural )
  return deepcopy( neural )
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions