-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* better compute tensors is tough. * Hard work but a lot faster and closer to optimal. * finished up faster compute tensors.
- Loading branch information
Showing
8 changed files
with
559 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tech.v3.datatype; | ||
|
||
|
||
import clojure.lang.Keyword; | ||
|
||
|
||
public interface DoubleTensorReader extends NDBuffer { | ||
default Object elemwiseDatatype() { return Keyword.intern(null, "float64"); } | ||
default boolean ndReadBoolean(long idx) { | ||
return ndReadDouble(idx) != 0.0; | ||
} | ||
default boolean ndReadBoolean(long y, long x) { | ||
return ndReadDouble(y,x) != 0.0; | ||
} | ||
default boolean ndReadBoolean(long y, long x, long c) { | ||
return ndReadDouble(y,x,c) != 0.0; | ||
} | ||
default long ndReadLong(long idx) { | ||
return (long)ndReadDouble(idx); | ||
} | ||
default long ndReadLong(long row, long col) { | ||
return (long)ndReadDouble(row,col); | ||
} | ||
default long ndReadLong(long height, long width, long chan) { | ||
return (long)ndReadDouble(height,width,chan); | ||
} | ||
default Object ndReadObject(long c) { | ||
if (1 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 1"); | ||
} | ||
return ndReadDouble(c); | ||
} | ||
default Object ndReadObject(long y, long x) { | ||
if (2 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 2"); | ||
} | ||
return ndReadDouble(y,x); | ||
} | ||
default Object ndReadObject(long y, long x, long c) { | ||
if (3 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 3"); | ||
} | ||
return ndReadDouble(y,x,c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package tech.v3.datatype; | ||
|
||
|
||
import clojure.lang.Keyword; | ||
|
||
|
||
public interface LongTensorReader extends NDBuffer { | ||
default Object elemwiseDatatype() { return Keyword.intern(null, "int64"); } | ||
default boolean ndReadBoolean(long idx) { | ||
return ndReadLong(idx) != 0; | ||
} | ||
default boolean ndReadBoolean(long y, long x) { | ||
return ndReadLong(y,x) != 0; | ||
} | ||
default boolean ndReadBoolean(long y, long x, long c) { | ||
return ndReadLong(y,x,c) != 0; | ||
} | ||
default double ndReadDouble(long idx) { | ||
return (double)ndReadLong(idx); | ||
} | ||
default double ndReadDouble(long row, long col) { | ||
return (double)ndReadLong(row,col); | ||
} | ||
default double ndReadDouble(long height, long width, long chan) { | ||
return (double)ndReadLong(height,width,chan); | ||
} | ||
|
||
//These overloads are dangerous as the ndReadObject methods are | ||
//expected to return slices if the tensor is of greater rank | ||
//than the nd method implies. This is why NDBuffers aren't | ||
//Buffers. | ||
default Object ndReadObject(long idx) { | ||
if (1 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 1"); | ||
} | ||
return ndReadLong(idx); | ||
} | ||
default Object ndReadObject(long y, long x) { | ||
if (2 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 2"); | ||
} | ||
return ndReadLong(y,x); | ||
} | ||
default Object ndReadObject(long y, long x, long c) { | ||
if (3 != rank()) { | ||
throw new RuntimeException("Tensor is not rank 3"); | ||
} | ||
return ndReadLong(y,x,c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tech.v3.datatype; | ||
|
||
|
||
import clojure.lang.Keyword; | ||
|
||
|
||
public interface ObjectTensorReader extends NDBuffer { | ||
default Object elemwiseDatatype() { return Keyword.intern(null, "float64"); } | ||
default boolean ndReadBoolean(long idx) { | ||
return BooleanConversions.from(ndReadObject(idx)); | ||
} | ||
default boolean ndReadBoolean(long y, long x) { | ||
return BooleanConversions.from(ndReadObject(y,x)); | ||
} | ||
default boolean ndReadBoolean(long y, long x, long c) { | ||
return BooleanConversions.from(ndReadObject(y,x,c)); | ||
} | ||
default long ndReadLong(long idx) { | ||
return NumericConversions.longCast(ndReadObject(idx)); | ||
} | ||
default long ndReadLong(long row, long col) { | ||
return NumericConversions.longCast(ndReadObject(row,col)); | ||
} | ||
default long ndReadLong(long height, long width, long chan) { | ||
return NumericConversions.longCast(ndReadObject(height,width,chan)); | ||
} | ||
default double ndReadDouble(long idx) { | ||
return NumericConversions.doubleCast(ndReadObject(idx)); | ||
} | ||
default double ndReadDouble(long row, long col) { | ||
return NumericConversions.doubleCast(ndReadObject(row,col)); | ||
} | ||
default double ndReadDouble(long height, long width, long chan) { | ||
return NumericConversions.doubleCast(ndReadObject(height,width,chan)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.