Skip to content

Conversation

@apomytkina
Copy link

…ctions were added for LongArray

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?

@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


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.

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