castano / nvidia-mesh-tools

Automatically exported from code.google.com/p/nvidia-mesh-tools
11 stars 4 forks source link

Code with a different (copyleft?) license? #7

Closed patwretchedsuspect closed 4 years ago

patwretchedsuspect commented 5 years ago

The nvidia-mesh-tools/src/nvmath/Random.h (line 279) has a notice that reads:

Random number implementation from the GNU Sci. Lib. (GSL). Adapted from Nicholas Chapman version: Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough

GNU GSL is licensed under GNU GPL, which places more restrictions on the code use than MIT/BSD licenses. The text of any of GNU GPL licenses is not present.

I am not a lawyer and I can't say how much the code is similar in a copyright sense - whether it is a derivative work requiring to comply with GPL or not - but looking at this (this is an older version from another project) they share the same commentaries. Some code logic/naming scheme is the same, compared to, for example, FreeBSD's implementation of rand48 here and there. But a lot of the names come from the formula for linear congruential generator.

I'm unable to tell whether the code is a derivative work of GSL or not (the biggest hooks are commentaries and copyright notice) and whether this is an actual issue or not.

I can suggest a rewrite/removal of the code "just in case". I've rewritten Rand48 class (see the end of the issue). The class was tested with 32-bit MinGW (MSYS2) g++ 7.4.0 on Windows 7 (after some modifications to allow the project to compile) on different seeds (0, a few random ones, 2^32-1) and on the range [0; 2^32) of seeds for the first 4 random generator outputs for every seed. It requires support for 64-bit arithmetic (uses posh library to disable the code if there is none). The license is the same as for nvidia-mesh-tools, no additional copyright notices needed. The file Random.cpp might require removal of some static variables.

The same problem with the same code exists in thekla_atlas.

/*
This code is based on nvidia-mesh-tools (https://github.com/castano/nvidia-mesh-tools/).

Hereby I, patwretchedsuspect (https://github.com/patwretchedsuspect), license this code under the
terms and conditions of the license of nvidia-mesh-tools (see https://github.com/castano/nvidia-mesh-tools/blob/a815a028ec7aa88b37b5482936434820f252ae6e/LICENSE)
without any additional terms or conditions -- 2018-02-20.
*/

/// This implementation requires 64-bit unsigned arithmetic.
#ifdef POSH_64BIT_INTEGER
/// 48-bit linear congruential generator that is intended to work like Unix's rand48.
/// Computed as: state_{n+1} = (0x5deece66d * state_n + 0xb) mod 2^48
/// Returns a 32-bit unsigned integer computed as: state_n / 2^16 mod 2^32
/// The new seed is computed as: (userProvidedSeed * 2^16) + 0x33oe
/// All calculations are unsigned.
class Rand48 : public Rand
{
public:
    /// Constructor that uses the current time as the seed.
    Rand48( time_e )
    {
        seed(randomSeed());
    }

    /// Constructor that uses the given seed (with rand48's default).
    Rand48( uint s = 0x1234abcd )
    {
        seed(s);
    }

    /// Provide a new seed.
    virtual void seed( uint s )
    {
        state = (posh_u64_t(s) << 16) | 0x330e;
    }

    /// Get a random number.
    virtual uint get()
    {
        // State is not truncated to 48 bits as the upper bits
        // do not affect the outcome.
        state = (POSH_U64(0x5deece66d) * state + 0xb);
        return state >> 16;
    }

private:
    posh_u64_t state;
};
#endif
castano commented 4 years ago

Sorry for the late reply. This project is not under active development and I don't receive notifications when issues are opened. You are right that the code referenced in the comments appears to be GPL'd. I did not base my implementation on that code, but on Nicholas Chapman's, so I wasn't aware there was a GPL predecessor. The Rand48 class is not even used in this project and can be removed easily.