Skip to content

Commit

Permalink
[TENSORS] Added a simple error check.
Browse files Browse the repository at this point in the history
  • Loading branch information
eaplatanios committed Sep 18, 2018
1 parent 5406c26 commit 36a9d2b
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ object Tensor {

@throws[IllegalArgumentException]
def fromBuffer[D <: DataType](dataType: D, shape: Shape, numBytes: Long, buffer: ByteBuffer): Tensor[D] = {
if (dataType.byteSize != -1 && dataType.byteSize * shape.numElements != numBytes) {
throw InvalidArgumentException(
s"Trying to load a $dataType tensor with ${shape.numElements} elements, " +
s"each of size ${dataType.byteSize} bytes, from the first $numBytes " +
"stored in the provided byte buffer. Either change the data type or the " +
"`numBytes` argument, to an appropriate value.")
}
this synchronized {
// TODO: May behave weirdly for direct byte buffers allocated on the Scala side.
val directBuffer = {
Expand Down

0 comments on commit 36a9d2b

Please sign in to comment.