-
Notifications
You must be signed in to change notification settings - Fork 58
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
base: dev
Are you sure you want to change the base?
Conversation
@@ -6,6 +6,7 @@ | |||
package space.kscience.kmath.structures | |||
|
|||
import kotlin.jvm.JvmInline | |||
import kotlin.random.Random.Default.nextDouble |
There was a problem hiding this comment.
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() } |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
…d into separate interface from LinearAlgebra
…ctions were added for LongArray