Skip to content

Commit 95bf91b

Browse files
authored
Discourage use on containers
1 parent 261f72c commit 95bf91b

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1111
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
1212
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
1313
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
14-
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1514
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1615
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1716

1817
[targets]
19-
test = ["Aqua", "DualNumbers", "DynamicQuantities", "Measurements", "StaticArrays", "Test", "Unitful"]
18+
test = ["Aqua", "DualNumbers", "DynamicQuantities", "Measurements", "Test", "Unitful"]

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
66

77
This package exports a tiny function `base_numeric_type` that
8-
extracts the base numeric type from a possible container type `T`:
8+
extracts the base numeric type from a numeric type `T`:
99

1010
- `base_numeric_type(::Type{T}) where {T}`
1111
- `base_numeric_type(x::T)`
@@ -16,18 +16,17 @@ For example,
1616
|---|---|
1717
| `Float32` | `Float32` |
1818
| `ComplexF32` | `Float32` |
19-
| `Array{ComplexF32,1}` | `ComplexF32` |
20-
| `Set{Float32}` | `Float32` |
2119
| `Measurement{Float32}` | `Float32` |
2220
| `Dual{BigFloat}` | `BigFloat` |
2321
| `Rational{Int8}` | `Int8` |
2422
| `Quantity{Float32,Dimensions}` | `Float32` |
2523

2624
Packages should write a method to `base_numeric_type`
27-
when the base numeric type of a container type
28-
is not the first parametric type. Otherwise,
29-
the default method will already be valid.
25+
when the base type of a numeric type
26+
is not the first parametric type.
27+
For example, if you were to create a quantity-like type
28+
`Quantity{Dimensions,NumericType}`, you would need
29+
to write a custom interface.
3030

31-
Furthermore, this is not needed for container types
32-
that inherit from `AbstractArray{T}`, as `T`
33-
will be taken as the base numeric type.
31+
But if the base type comes first,
32+
the default method will work.

src/BaseType.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ export base_numeric_type
66
base_numeric_type(::Type{T}) where {T}
77
base_numeric_type(x::T)
88
9-
Extract the base numeric type from a possible container type `T`.
9+
Extract the base numeric type from a numerical type `T` such
10+
as a measurement or a quantity.
1011
1112
For example,
1213
1314
| Input Type | Output Type |
1415
|---|---|
1516
| `Float32` | `Float32` |
1617
| `ComplexF32` | `Float32` |
17-
| `Array{ComplexF32,1}` | `ComplexF32` |
18-
| `Set{Float32}` | `Float32` |
1918
| `Measurement{Float32}` | `Float32` |
2019
| `Rational{Int8}` | `Int8` |
2120
| `Dual{BigFloat}` | `BigFloat` |
@@ -27,7 +26,4 @@ For example,
2726
end
2827
base_numeric_type(x) = base_numeric_type(typeof(x))
2928

30-
# Special cases:
31-
base_numeric_type(::Type{<:AbstractArray{T}}) where {T} = T
32-
3329
end

test/unittests.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@ using BaseType: base_numeric_type
33
using DualNumbers: DualNumbers
44
using DynamicQuantities: DynamicQuantities
55
using Measurements: ±
6-
using StaticArrays: StaticArrays
76
using Unitful: Unitful
87

98
expected_type_pairs = [
109
Float32 => Float32,
11-
Array{Float64,1} => Float64,
1210
ComplexF64 => Float64,
13-
Matrix{ComplexF64} => ComplexF64,
1411
DualNumbers.Dual{Int64} => Int64,
1512
DynamicQuantities.Quantity{Float32} => Float32,
1613
typeof(1.5DynamicQuantities.u"km/s") => Float64,
1714
typeof(1.5f0Unitful.u"km/s") => Float32,
18-
typeof(StaticArrays.SArray{Tuple{32,3}}(randn(32, 3))) => Float64,
19-
typeof(StaticArrays.SArray{Tuple{32,3}}(randn(Float32, 32, 3))) => Float32,
2015
BigFloat => BigFloat,
2116
typeof(1.5 ± 0.2) => Float64,
2217
typeof(1.5f0 ± 0.2f0) => Float32,

0 commit comments

Comments
 (0)