libRmath.js: can't use rmultinom with n = 1

can’t use libRmath.Multinomial rmultinom with n = 1, only when n > 1, it will not throw error

  const result = sequence(n).map(() => _rmultinom(size, prob, rng));
                             ^
TypeError: sequence(...).map is not a function

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@jacobbogers it work without throw now

I thought u are already fix it, just waiting some other job done, so didn’t publish lol

demo code about what i saying lol

import libRmath = require('lib-r-math.js');

let rmultinomFn = libRmath.Multinomial(fakeLibRmathRng(Math.random)).rmultinom;

/**
 * n can't be 1 at current lib-r-math.js version (publish in npm)
 * 
 * and source code already change at github,
 * but not yet publish to npm
 */
let n = 1
let size = 21;

let ret = rmultinomFn(n, size, [1, 2]) // here will throw

console.log(ret);

export function fakeLibRmathRng(fn: () => number)
{
	return {
		unif_rand(n?: number)
		{
			if (n > 1)
			{
				let a = [];
				while (n--)
				{
					a[n] = fn()
				}
				return a;
			}

			return fn()
		},
	} as libRmath.IRNG
}