•internal.Indistinguishable
This commit is contained in:
parent
cac692da89
commit
10c0e43649
@ -89,7 +89,7 @@ Argument must not be a namespace, as that is reserved for future changes.
|
|||||||
Namespace of various internal functions. May change at any time.
|
Namespace of various internal functions. May change at any time.
|
||||||
|
|
||||||
| name | description |
|
| name | description |
|
||||||
|----------------------------|-------------|
|
|-------------------------------|-------------|
|
||||||
| `•internal.GC` | Run a garbage collection cycle |
|
| `•internal.GC` | Run a garbage collection cycle |
|
||||||
| `•internal.Type` | Name of the internal type for an object |
|
| `•internal.Type` | Name of the internal type for an object |
|
||||||
| `•internal.ObjFlags` | Monadically, get the flags of `𝕩`. Dyadically, set the flags of `𝕩` to `𝕨`. |
|
| `•internal.ObjFlags` | Monadically, get the flags of `𝕩`. Dyadically, set the flags of `𝕩` to `𝕨`. |
|
||||||
@ -108,7 +108,8 @@ Namespace of various internal functions. May change at any time.
|
|||||||
| `•internal.Variation` | Convert `𝕩` to the variation specified in `𝕨` |
|
| `•internal.Variation` | Convert `𝕩` to the variation specified in `𝕨` |
|
||||||
| `•internal.ClearRefs` | Clear references `•internal.Variation` made for `*Inc` variations |
|
| `•internal.ClearRefs` | Clear references `•internal.Variation` made for `*Inc` variations |
|
||||||
| `•internal.Unshare` | Get a unique, reference count 1 version of the argument; recursively unshares array items, doesn't touch namespaces |
|
| `•internal.Unshare` | Get a unique, reference count 1 version of the argument; recursively unshares array items, doesn't touch namespaces |
|
||||||
| `•internal.EEqual` | Exactly equal (NaN equals NaN, 0 equals ¯0) |
|
| `•internal.EEqual` | Exactly equal (`𝕨≡𝕩` but NaN equals NaN) |
|
||||||
|
| `•internal.Indistinguishable` | Semantically indistinguishable (`•internal.EEqual`, plus checking fills) |
|
||||||
| `•internal.Temp` | Place to test new features or temporarily expose some internal function |
|
| `•internal.Temp` | Place to test new features or temporarily expose some internal function |
|
||||||
| `•internal.Properties` | Various build properties |
|
| `•internal.Properties` | Various build properties |
|
||||||
| `•internal.Validate` | Validate that `𝕩` has correct flags set |
|
| `•internal.Validate` | Validate that `𝕩` has correct flags set |
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
/* inverse.c*/M(setInvReg,"(SetInvReg)") M(setInvSwap,"(SetInvSwap)") M(nativeInvReg,"(NativeInvReg)") M(nativeInvSwap,"(NativeInvSwap)") \
|
/* inverse.c*/M(setInvReg,"(SetInvReg)") M(setInvSwap,"(SetInvSwap)") M(nativeInvReg,"(NativeInvReg)") M(nativeInvSwap,"(NativeInvSwap)") \
|
||||||
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") \
|
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") \
|
||||||
/*internal.c*/M(heapDump,"•internal.HeapDump") M(internalGC,"•internal.GC") M(heapStats,"•internal.HeapStats") A(iObjFlags,"•internal.ObjFlags") \
|
/*internal.c*/M(heapDump,"•internal.HeapDump") M(internalGC,"•internal.GC") M(heapStats,"•internal.HeapStats") A(iObjFlags,"•internal.ObjFlags") \
|
||||||
/*internal.c*/D(eequal,"•internal.EEqual") M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") M(iValidate,"•internal.Validate") \
|
/*internal.c*/D(eequal,"•internal.EEqual") D(indistinguishable,"•internal.Indistinguishable") M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") M(iValidate,"•internal.Validate") \
|
||||||
/*internal.c*/A(internalTemp,"•internal.Temp") M(iHasFill,"•internal.HasFill") M(iKeep,"•internal.Keep") D(iProperties,"•internal.Properties") \
|
/*internal.c*/A(internalTemp,"•internal.Temp") M(iHasFill,"•internal.HasFill") M(iKeep,"•internal.Keep") D(iProperties,"•internal.Properties") \
|
||||||
/*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare") \
|
/*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare") \
|
||||||
/* arithd.c*/D(hypot,"•math.Hypot") D(comb,"•math.Comb") D(gcd,"•math.GCD") D(lcm,"•math.LCM") D(atan2,"•math.Atan2") D(atan2ix,"•math.Atan2⁼") D(atan2iw,"•math.Atan2˜⁼") \
|
/* arithd.c*/D(hypot,"•math.Hypot") D(comb,"•math.Comb") D(gcd,"•math.GCD") D(lcm,"•math.LCM") D(atan2,"•math.Atan2") D(atan2ix,"•math.Atan2⁼") D(atan2iw,"•math.Atan2˜⁼") \
|
||||||
|
|||||||
@ -85,6 +85,29 @@ static bool atomEEqual(B w, B x) { // doesn't consume
|
|||||||
return atomEqualF(w, x);
|
return atomEqualF(w, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool indistinguishable(B w, B x) {
|
||||||
|
if (w.u == x.u) return true;
|
||||||
|
if (isAtm(w)) {
|
||||||
|
if (!isAtm(x)) return false;
|
||||||
|
if (isF64(w)) return isF64(x) && floatIndistinguishable(o2fG(w), o2fG(x));
|
||||||
|
if (!isVal(w) || !isVal(x)) return false; // incl. non-equal c32
|
||||||
|
return decomposeEqual(w, x, indistinguishable);
|
||||||
|
}
|
||||||
|
if (isAtm(x)) return false;
|
||||||
|
u8 we = TI(w,elType);
|
||||||
|
u8 xe = TI(x,elType);
|
||||||
|
if (we!=el_B && xe!=el_B) {
|
||||||
|
if (elNum(we) != elNum(xe)) return false;
|
||||||
|
return eequal(w, x); // fast path
|
||||||
|
}
|
||||||
|
if (!eqShape(w, x)) return false;
|
||||||
|
usz wia = IA(w);
|
||||||
|
SGetU(w) SGetU(x)
|
||||||
|
for (ux i = 0; i < wia; i++) if (!indistinguishable(GetU(w,i), GetU(x,i))) return false;
|
||||||
|
if (!indistinguishable(getFillN(w), getFillN(x))) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static const u8 n = 99;
|
static const u8 n = 99;
|
||||||
u8 const matchFnData[] = { // for the main diagonal, amount to shift length by; otherwise, whether to swap arguments
|
u8 const matchFnData[] = { // for the main diagonal, amount to shift length by; otherwise, whether to swap arguments
|
||||||
0,0,0,0,0,n,n,n,
|
0,0,0,0,0,n,n,n,
|
||||||
|
|||||||
@ -285,6 +285,14 @@ B eequal_c2(B t, B w, B x) {
|
|||||||
return m_i32(r);
|
return m_i32(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool indistinguishable(B w, B x);
|
||||||
|
|
||||||
|
B indistinguishable_c2(B t, B w, B x) {
|
||||||
|
bool r = indistinguishable(w, x);
|
||||||
|
dec(w); dec(x);
|
||||||
|
return m_i32(r);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEST_BITCPY
|
#ifdef TEST_BITCPY
|
||||||
#include "../utils/mut.h"
|
#include "../utils/mut.h"
|
||||||
#endif
|
#endif
|
||||||
@ -487,8 +495,8 @@ B getInternalNS(void) {
|
|||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
#define F(X) incG(bi_##X),
|
#define F(X) incG(bi_##X),
|
||||||
Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info", "keep", "purekeep","listvariations","variation","clearrefs", "hasfill","unshare","deepsqueeze","heapdump","eequal", "gc", "temp","heapstats", "objflags", "properties", "validate");
|
Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info", "keep", "purekeep","listvariations","variation","clearrefs", "hasfill","unshare","deepsqueeze","heapdump","eequal", "gc", "temp","heapstats", "objflags", "properties", "validate", "indistinguishable");
|
||||||
internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(iKeep)F(iPureKeep)F(listVariations)F(variation)F(clearRefs)F(iHasFill)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalGC)F(internalTemp)F(heapStats)F(iObjFlags)F(iProperties)F(iValidate));
|
internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(iKeep)F(iPureKeep)F(listVariations)F(variation)F(clearRefs)F(iHasFill)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalGC)F(internalTemp)F(heapStats)F(iObjFlags)F(iProperties)F(iValidate)F( indistinguishable));
|
||||||
#undef F
|
#undef F
|
||||||
gc_add(internalNS);
|
gc_add(internalNS);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1990,8 +1990,13 @@ u32* const dsv_text[] = {
|
|||||||
U"•file.Accessed",U"•file.At",U"•file.Bytes",U"•file.Chars",U"•file.Created",U"•file.CreateDir",U"•file.Exists",U"•file.Lines",U"•file.List",
|
U"•file.Accessed",U"•file.At",U"•file.Bytes",U"•file.Chars",U"•file.Created",U"•file.CreateDir",U"•file.Exists",U"•file.Lines",U"•file.List",
|
||||||
U"•file.MapBytes",U"•file.Modified",U"•file.Name",U"•file.Parent",U"•file.path",U"•file.RealPath",U"•file.Remove",U"•file.Rename",U"•file.Size",U"•file.Type",
|
U"•file.MapBytes",U"•file.Modified",U"•file.Name",U"•file.Parent",U"•file.path",U"•file.RealPath",U"•file.Remove",U"•file.Rename",U"•file.Size",U"•file.Type",
|
||||||
|
|
||||||
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.GC",U"•internal.HasFill",U"•internal.HeapDump",U"•internal.HeapStats",U"•internal.Info",U"•internal.IsPure",U"•internal.Keep",U"•internal.ListVariations",U"•internal.ObjFlags",U"•internal.PureKeep",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Validate",U"•internal.Variation",
|
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.GC",U"•internal.HasFill",U"•internal.HeapDump",
|
||||||
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Comb",U"•math.Cos",U"•math.Cosh",U"•math.Erf",U"•math.ErfC",U"•math.Expm1",U"•math.Fact",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.LogFact",U"•math.Sin",U"•math.Sinh",U"•math.Sum",U"•math.Tan",U"•math.Tanh",
|
U"•internal.HeapStats",U"•internal.Indistinguishable",U"•internal.Info",U"•internal.IsPure",U"•internal.Keep",U"•internal.ListVariations",U"•internal.ObjFlags",
|
||||||
|
U"•internal.PureKeep",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Validate",U"•internal.Variation",
|
||||||
|
|
||||||
|
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Comb",U"•math.Cos",U"•math.Cosh",
|
||||||
|
U"•math.Erf",U"•math.ErfC",U"•math.Expm1",U"•math.Fact",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.LogFact",
|
||||||
|
U"•math.Sin",U"•math.Sinh",U"•math.Sum",U"•math.Tan",U"•math.Tanh",
|
||||||
|
|
||||||
U"•ns.Get",U"•ns.Has",U"•ns.Keys",
|
U"•ns.Get",U"•ns.Has",U"•ns.Keys",
|
||||||
U"•platform.bqn.impl",U"•platform.bqn.implVersion",U"•platform.cpu.arch",U"•platform.environment",U"•platform.os",
|
U"•platform.bqn.impl",U"•platform.bqn.implVersion",U"•platform.cpu.arch",U"•platform.environment",U"•platform.os",
|
||||||
|
|||||||
@ -343,6 +343,7 @@ SHOULD_INLINE i32 floatCompare(f64 w, f64 x) { // w •Cmp x
|
|||||||
SHOULD_INLINE bool floatIndistinguishable(f64 a, f64 b) { // whether the floats are indistinguishable by BQN semantics
|
SHOULD_INLINE bool floatIndistinguishable(f64 a, f64 b) { // whether the floats are indistinguishable by BQN semantics
|
||||||
return a==b || (a!=a && b!=b);
|
return a==b || (a!=a && b!=b);
|
||||||
}
|
}
|
||||||
|
NOINLINE bool indistinguishable(B w, B x); // whether w and x are semantically indistinguishable (i.e. NaN==NaN, fill equality is checked; different internal type/metadata is tolerated)
|
||||||
|
|
||||||
NOINLINE i32 compareF(B w, B x);
|
NOINLINE i32 compareF(B w, B x);
|
||||||
static i32 compare(B w, B x) { // doesn't consume; -1 if w<x, 1 if w>x, 0 if w≡x
|
static i32 compare(B w, B x) { // doesn't consume; -1 if w<x, 1 if w>x, 0 if w≡x
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user