-
Notifications
You must be signed in to change notification settings - Fork 2
Make scalar → Tensor0 conversions work without an import, using Scala's into #169
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
35 changes: 35 additions & 0 deletions
35
core/src/main/scala/dimwit/tensor/Tensor0Conversions.scala
This file contains hidden or 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,35 @@ | ||
| package dimwit.tensor | ||
|
|
||
| import dimwit.tensor.ValueTypeClasses.IsBoolean | ||
| import dimwit.tensor.ValueTypeClasses.IsFloating | ||
| import dimwit.tensor.ValueTypeClasses.IsInteger | ||
|
|
||
| /** Conversions from Scala scalars to a `Tensor0` of the tensor's value type, e.g. for `t *! 2.0f`. | ||
| * | ||
| * Users never import them: the `Tensor` companion object exports them, so the compiler finds them automatically. | ||
| */ | ||
| private[dimwit] object Tensor0Conversions: | ||
|
|
||
| given boolean2BooleanTensor[V: IsBoolean]: Conversion[Boolean, Tensor0[V]] with | ||
| def apply(value: Boolean): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given byte2IntegerTensor[V: IsInteger]: Conversion[Byte, Tensor0[V]] with | ||
| def apply(value: Byte): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given short2IntegerTensor[V: IsInteger]: Conversion[Short, Tensor0[V]] with | ||
| def apply(value: Short): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given int2IntegerTensor[V: IsInteger]: Conversion[Int, Tensor0[V]] with | ||
| def apply(value: Int): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given int2FloatingTensor[V: IsFloating]: Conversion[Int, Tensor0[V]] with | ||
| def apply(value: Int): Tensor0[V] = Tensor0(VType[V])(value.toFloat) | ||
|
|
||
| given long2IntegerTensor[V: IsInteger]: Conversion[Long, Tensor0[V]] with | ||
| def apply(value: Long): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given float2FloatingTensor[V: IsFloating]: Conversion[Float, Tensor0[V]] with | ||
| def apply(value: Float): Tensor0[V] = Tensor0(VType[V])(value) | ||
|
|
||
| given double2FloatingTensor[V: IsFloating]: Conversion[Double, Tensor0[V]] with | ||
| def apply(value: Double): Tensor0[V] = Tensor0(VType[V])(value) |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -141,8 +141,6 @@ private[dimwit] object StructuralOps: | |
| object AxisAbsent: | ||
| given notContained[T <: Tuple, L](using NotGiven[Tuple.Contains[T, L] =:= true]): AxisAbsent[T, L] = new AxisAbsent[T, L] {} | ||
|
|
||
| import Util.* | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this change is a clean up from the previous PR |
||
|
|
||
| object TensorWhere: | ||
|
|
||
| /** Returns a new tensor selecting elements from `ifTrue` where the condition is true | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
1 change: 0 additions & 1 deletion
1
core/src/test/scala/dimwit/optimizer/GradientOptimizerSuite.scala
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 0 additions & 1 deletion
1
core/src/test/scala/dimwit/tensor/TensorOpsBroadcastSuite.scala
This file contains hidden or 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
1 change: 0 additions & 1 deletion
1
core/src/test/scala/dimwit/tensor/TensorOpsElementwiseSuite.scala
This file contains hidden or 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
1 change: 0 additions & 1 deletion
1
core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala
This file contains hidden or 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
1 change: 0 additions & 1 deletion
1
core/src/test/scala/dimwit/tensor/TensorOpsReductionSuite.scala
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 0 additions & 1 deletion
1
examples/src/main/scala/dimwit/complex/VariationalAutoencoder.scala
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package dimwit.examples.dataset | ||
|
|
||
| import dimwit.Conversions.given | ||
| import dimwit.* | ||
| import me.shadaj.scalapy.py | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 did not know that into also works on the class level. This is much more elegant than the solution I found, which would have used into in every signature that has a Tensor[T, V]. Nice.