Giter VIP home page Giter VIP logo

Comments (3)

raskr avatar raskr commented on May 19, 2024 1

Thanks for your interest in this project! This is a curious issue whereas I'm not familiar with Web Assembly at all.
Anyway, enabling array generator functions to use pre-instantiated Rng object solves this problem as you said. This abstraction is definitely useful, but I want to provide default Rng. Therefore the compromise will be something like:

let arr1 = ndarray_ext::ArrRng::default().glorot_uniform(&[2, 3]);
let arr2 = ndarray_ext::ArrRng::new(Pcg).glorot_uniform(&[2, 3]);

How do you think?
In this case, the library implementation will be as follows...

    struct ArrRng<R: Rng> {
        rng: R
    }

    impl Default for ArrRng<rand::XorShiftRng>
    {
        fn default() -> Self
        {
            ArrRng {
                rng: rand::weak_rng()
            }
        }
    }

    impl<R: Rng> ArrRng<R> {
        pub fn new(rng: R) -> Self
        {
            ArrRng {
                rng
            }
        }
    }

    impl<R: Rng> ArrRng<R>
    {
        pub fn glorot_uniform(&mut self, shape: &[usize]) -> NdArray
        {
            let s = (6. / shape[0] as f64).sqrt();
            let dist = rand::distributions::Range::new(-s, s);
            NdArray::from_shape_fn(shape, |_| dist.ind_sample(&mut self.rng) as f32)
        }
        ...
    }

from rust-autograd.

shanegibbs avatar shanegibbs commented on May 19, 2024

Yes, that would solve my problem. I like this design too 🥇

It looks like you basically have it sorted out but let me know if you would like a hand with anything.

from rust-autograd.

raskr avatar raskr commented on May 19, 2024

Ok, next version (may take several days) will contain code close to those.
Thank you I will; immediate PRs are also welcome since this is an experimental project 👍

from rust-autograd.

Related Issues (20)

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.