Overview
Implement NumPy's type introspection and promotion functions (np.iinfo, np.finfo, np.can_cast, etc.) and consolidate NumSharp's scattered type information into a centralized, NumPy-aligned system.
Problem
NumSharp's type information is scattered across 5+ files with duplicates and inconsistencies:
| File |
What it has |
NPTypeCode.cs |
GetDefaultValue(), SizeOf(), AsType(), IsUnsigned(), IsSigned(), GetAccumulatingType() |
NumberInfo.cs |
MinValue(), MaxValue() |
TypeRules.cs |
GetTypeSize(), GetClrType(), IsUnsigned(), IsSigned(), IsFloatingPoint(), GetAccumulatingType() |
InfoOf<T> |
Size, Zero, MaxValue, MinValue (generic cached) |
ReductionTypeExtensions |
GetOneValue(), GetMinValue(), GetMaxValue() (uses infinity for floats) |
Duplicates found:
SizeOf() vs GetTypeSize() vs InfoOf<T>.Size (3 implementations)
AsType() vs GetClrType() (2 implementations)
IsUnsigned(), IsSigned() (2 implementations each)
GetAccumulatingType() (2 implementations)
MinValue()/MaxValue() vs GetMinValue()/GetMaxValue() (different semantics!)
NumPy has clean, unified APIs (np.iinfo, np.finfo) that NumSharp lacks entirely.
Proposal
Phase 1: Implement np.iinfo and np.finfo
Phase 2: Implement Type Checking Functions
Phase 3: Implement Type Promotion Functions
Phase 4: Consolidate Internal Type Info
Phase 5: Additional Type Functions
NumPy vs NumSharp Current State
| NumPy Function |
NumSharp Status |
np.iinfo(dtype) |
❌ Missing |
np.finfo(dtype) |
❌ Missing |
np.isscalar(x) |
✅ Implemented |
np.issctype(rep) |
❌ Missing |
np.issubdtype(arg1, arg2) |
❌ Missing |
np.isdtype(dtype, kind) |
❌ Missing |
np.result_type(*arrays) |
⚠️ Internal only (_FindCommonType) |
np.find_common_type(array_types, scalar_types) |
✅ Implemented |
np.promote_types(t1, t2) |
❌ Missing (internal only) |
np.can_cast(from, to) |
❌ Missing |
np.min_scalar_type(a) |
❌ Missing |
np.common_type(*arrays) |
❌ Missing |
np.isnan(x) |
✅ Implemented |
np.isinf(x) |
✅ Implemented |
np.isfinite(x) |
✅ Implemented |
np.isclose(a, b) |
✅ Implemented |
np.isreal(x) |
❌ Missing |
np.iscomplex(x) |
❌ Missing |
np.sctype2char(sctype) |
❌ Missing |
np.maximum_sctype(t) |
❌ Missing |
Evidence
NumPy source reference: src/numpy/numpy/_core/getlimits.py (iinfo, finfo)
NumPy source reference: src/numpy/numpy/_core/numerictypes.py (type functions)
NumPy source reference: src/numpy/numpy/_core/multiarray.py (can_cast, result_type, min_scalar_type)
Scope / Non-goals
In scope:
- Type introspection classes (iinfo, finfo)
- Type checking functions (issubdtype, isdtype, etc.)
- Type promotion functions (can_cast, promote_types, etc.)
- Consolidating scattered internal type info
- Removing duplicates
Out of scope:
Overview
Implement NumPy's type introspection and promotion functions (
np.iinfo,np.finfo,np.can_cast, etc.) and consolidate NumSharp's scattered type information into a centralized, NumPy-aligned system.Problem
NumSharp's type information is scattered across 5+ files with duplicates and inconsistencies:
NPTypeCode.csGetDefaultValue(),SizeOf(),AsType(),IsUnsigned(),IsSigned(),GetAccumulatingType()NumberInfo.csMinValue(),MaxValue()TypeRules.csGetTypeSize(),GetClrType(),IsUnsigned(),IsSigned(),IsFloatingPoint(),GetAccumulatingType()InfoOf<T>Size,Zero,MaxValue,MinValue(generic cached)ReductionTypeExtensionsGetOneValue(),GetMinValue(),GetMaxValue()(uses infinity for floats)Duplicates found:
SizeOf()vsGetTypeSize()vsInfoOf<T>.Size(3 implementations)AsType()vsGetClrType()(2 implementations)IsUnsigned(),IsSigned()(2 implementations each)GetAccumulatingType()(2 implementations)MinValue()/MaxValue()vsGetMinValue()/GetMaxValue()(different semantics!)NumPy has clean, unified APIs (
np.iinfo,np.finfo) that NumSharp lacks entirely.Proposal
Phase 1: Implement np.iinfo and np.finfo
Create
np.iinfo(int_type)class returning:bits- number of bits (8, 16, 32, 64)min- smallest valuemax- largest valuedtype- the NPTypeCodekind- 'i' (signed) or 'u' (unsigned)Create
np.finfo(float_type)class returning:bits- number of bitsmin,max- value rangeeps- machine epsilonepsneg- negative epsilontiny/smallest_normal- smallest positive normalsmallest_subnormal- smallest positive subnormalprecision- decimal digitsresolution- 10^-precisionmaxexp,minexp- exponent limitsdtype- the NPTypeCodePhase 2: Implement Type Checking Functions
np.issubdtype(arg1, arg2)- check dtype inheritancenp.isdtype(dtype, kind)- check dtype against kind stringnp.issctype(rep)- check if scalar typenp.issubsctype(arg1, arg2)- check scalar type inheritancenp.sctype2char(sctype)- scalar type to character codenp.maximum_sctype(t)- highest precision of same kindPhase 3: Implement Type Promotion Functions
np.can_cast(from, to, casting="safe")- check if cast is validnp.result_type(*arrays_and_dtypes)- common result type (make public)np.promote_types(type1, type2)- smallest type to hold bothnp.min_scalar_type(a)- minimum type to hold scalarnp.common_type(*arrays)- common type for arraysPhase 4: Consolidate Internal Type Info
NPTypeInfostatic class with all type metadataGetTypeSize()fromTypeRules.cs(useNPTypeCode.SizeOf())GetClrType()fromTypeRules.cs(useNPTypeCode.AsType())IsUnsigned(),IsSigned()fromTypeRules.csGetAccumulatingType()fromTypeRules.csReductionTypeExtensions.GetOneValue()toNPTypeCodeextensionsReductionTypeExtensions.GetMinValue()/GetMaxValue()separate (uses infinity - different semantics)Phase 5: Additional Type Functions
np.isreal(x)- check if array has no imaginary partnp.iscomplex(x)- check if array has imaginary partnp.iscomplexobj(x)- check if object is complex typenp.isrealobj(x)- check if object is real typeNumPy vs NumSharp Current State
np.iinfo(dtype)np.finfo(dtype)np.isscalar(x)np.issctype(rep)np.issubdtype(arg1, arg2)np.isdtype(dtype, kind)np.result_type(*arrays)_FindCommonType)np.find_common_type(array_types, scalar_types)np.promote_types(t1, t2)np.can_cast(from, to)np.min_scalar_type(a)np.common_type(*arrays)np.isnan(x)np.isinf(x)np.isfinite(x)np.isclose(a, b)np.isreal(x)np.iscomplex(x)np.sctype2char(sctype)np.maximum_sctype(t)Evidence
NumPy source reference:
src/numpy/numpy/_core/getlimits.py(iinfo, finfo)NumPy source reference:
src/numpy/numpy/_core/numerictypes.py(type functions)NumPy source reference:
src/numpy/numpy/_core/multiarray.py(can_cast, result_type, min_scalar_type)Scope / Non-goals
In scope:
Out of scope: