Add tests of kmath-memory and make all the memory operations on all the platforms use little-endian byte order #163
@ -157,9 +157,3 @@ public inline fun Memory.write(block: MemoryWriter.() -> Unit) {
|
|||||||
* Allocates the most effective platform-specific memory.
|
* Allocates the most effective platform-specific memory.
|
||||||
*/
|
*/
|
||||||
public expect fun Memory.Companion.allocate(length: Int): Memory
|
public expect fun Memory.Companion.allocate(length: Int): Memory
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied
|
|
||||||
* and could be mutated independently from the resulting [Memory].
|
|
||||||
*/
|
|
||||||
public expect fun Memory.Companion.wrap(array: ByteArray): Memory
|
|
||||||
|
@ -7,7 +7,6 @@ package space.kscience.kmath.memory
|
|||||||
|
|
||||||
import org.khronos.webgl.ArrayBuffer
|
import org.khronos.webgl.ArrayBuffer
|
||||||
import org.khronos.webgl.DataView
|
import org.khronos.webgl.DataView
|
||||||
import org.khronos.webgl.Int8Array
|
|
||||||
|
|
||||||
private class DataViewMemory(val view: DataView) : Memory {
|
private class DataViewMemory(val view: DataView) : Memory {
|
||||||
override val size: Int get() = view.byteLength
|
override val size: Int get() = view.byteLength
|
||||||
@ -91,12 +90,3 @@ public actual fun Memory.Companion.allocate(length: Int): Memory {
|
|||||||
val buffer = ArrayBuffer(length)
|
val buffer = ArrayBuffer(length)
|
||||||
return DataViewMemory(DataView(buffer, 0, length))
|
return DataViewMemory(DataView(buffer, 0, length))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied
|
|
||||||
* and could be mutated independently from the resulting [Memory].
|
|
||||||
*/
|
|
||||||
public actual fun Memory.Companion.wrap(array: ByteArray): Memory {
|
|
||||||
val int8Array = array.unsafeCast<Int8Array>()
|
|
||||||
return DataViewMemory(DataView(int8Array.buffer, int8Array.byteOffset, int8Array.length))
|
|
||||||
}
|
|
||||||
|
@ -102,13 +102,6 @@ internal class ByteBufferMemory(
|
|||||||
public actual fun Memory.Companion.allocate(length: Int): Memory =
|
public actual fun Memory.Companion.allocate(length: Int): Memory =
|
||||||
ByteBufferMemory(checkNotNull(ByteBuffer.allocate(length).order(ByteOrder.LITTLE_ENDIAN)))
|
ByteBufferMemory(checkNotNull(ByteBuffer.allocate(length).order(ByteOrder.LITTLE_ENDIAN)))
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied
|
|
||||||
* and could be mutated independently from the resulting [Memory].
|
|
||||||
*/
|
|
||||||
public actual fun Memory.Companion.wrap(array: ByteArray): Memory =
|
|
||||||
ByteBufferMemory(checkNotNull(ByteBuffer.wrap(array)))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps this [ByteBuffer] to [Memory] object.
|
* Wraps this [ByteBuffer] to [Memory] object.
|
||||||
*
|
*
|
||||||
|
@ -83,12 +83,6 @@ internal class NativeMemory(
|
|||||||
override fun writer(): MemoryWriter = writer
|
override fun writer(): MemoryWriter = writer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied
|
|
||||||
* and could be mutated independently from the resulting [Memory].
|
|
||||||
*/
|
|
||||||
public actual fun Memory.Companion.wrap(array: ByteArray): Memory = NativeMemory(array)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates the most effective platform-specific memory.
|
* Allocates the most effective platform-specific memory.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user