-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NDTensors] Fix zero for EmptyStorage (#1173)
- Loading branch information
Showing
8 changed files
with
51 additions
and
38 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
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
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,30 @@ | ||
# | ||
# Represents a number that can be set to any type. | ||
# | ||
|
||
struct EmptyNumber <: Real end | ||
|
||
zero(::Type{EmptyNumber}) = EmptyNumber() | ||
zero(n::EmptyNumber) = zero(typeof(n)) | ||
|
||
# This helps handle a lot of basic algebra, like: | ||
# EmptyNumber() + 2.3 == 2.3 | ||
convert(::Type{T}, x::EmptyNumber) where {T<:Number} = T(zero(T)) | ||
|
||
# TODO: Should this be implemented? | ||
#Complex(x::Real, ::EmptyNumber) = x | ||
|
||
# This is to help define `float(::EmptyNumber) = 0.0`. | ||
# This helps with defining `norm` of `EmptyStorage{EmptyNumber}`. | ||
AbstractFloat(::EmptyNumber) = zero(AbstractFloat) | ||
|
||
# Basic arithmetic | ||
(::EmptyNumber + ::EmptyNumber) = EmptyNumber() | ||
(::EmptyNumber - ::EmptyNumber) = EmptyNumber() | ||
(::Number * ::EmptyNumber) = EmptyNumber() | ||
(::EmptyNumber * ::Number) = EmptyNumber() | ||
(::EmptyNumber * ::EmptyNumber) = EmptyNumber() | ||
(::EmptyNumber / ::Number) = EmptyNumber() | ||
(::Number / ::EmptyNumber) = throw(DivideError()) | ||
(::EmptyNumber / ::EmptyNumber) = throw(DivideError()) | ||
-(::EmptyNumber) = EmptyNumber() |
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,6 @@ | ||
# Denotes when a storage type has no data | ||
struct NoData end | ||
|
||
size(::NoData) = (0,) | ||
length(::NoData) = 0 | ||
fill!(::NoData, ::EmptyNumber) = NoData() |
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
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