Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoubleBuffer generator was moved to DoubleBuffer file and factory fun… #485

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

apomytkina
Copy link

…ctions were added for LongArray

@@ -6,6 +6,7 @@
package space.kscience.kmath.structures

import kotlin.jvm.JvmInline
import kotlin.random.Random.Default.nextDouble
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default generator should never be used outside of tests

/**
* A chunk of doubles of given [size].
*/
public fun nextDoubleBuffer(size: Int): DoubleBuffer = DoubleBuffer(size) { nextDouble() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any reasons to add this to the core?

@@ -35,15 +36,15 @@ internal class UniformHistogram1DTest {

@Test
fun rebinDown() = runTest {
val h1 = Histogram.uniform1D(DoubleField, 0.01).produce(generator.nextDoubleBuffer(10000))
val h1 = Histogram.uniform1D(DoubleField, 0.01).produce(nextDoubleBuffer(10000))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how it helps

@@ -8,3 +8,13 @@ package space.kscience.kmath.nd4j
import space.kscience.kmath.misc.toIntExact

internal fun LongArray.toIntArray(): IntArray = IntArray(size) { this[it].toIntExact() }

internal fun LongArray.linspace(start: Long, stop: Long) = Array(this.size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try not to use Arrays in mathematics because they have some default overrides in Kotling StdLib. You should use Buffer and there are already BufferAlgebra.zero producers for that. There is a DoubleBuffer producer that uses step, we can add a similar one for Longs, but we need to be careful about naming.

@@ -23,8 +24,8 @@ public object BoxMullerSampler : NormalizedGaussianSampler {
var state = Double.NaN

override fun nextBufferBlocking(size: Int): DoubleBuffer {
val xs = generator.nextDoubleBuffer(size)
val ys = generator.nextDoubleBuffer(size)
val xs = nextDoubleBuffer(size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake. You are using the default generator instead of provided one. It will give wrong results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants