semantic-complexity 0.0.1-cedf2072 → 0.0.3-38ef2e6f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canonical/convergence.d.ts +56 -0
- package/dist/canonical/convergence.d.ts.map +1 -0
- package/dist/canonical/convergence.js +149 -0
- package/dist/canonical/convergence.js.map +1 -0
- package/dist/canonical/index.d.ts +11 -0
- package/dist/canonical/index.d.ts.map +1 -0
- package/dist/canonical/index.js +11 -0
- package/dist/canonical/index.js.map +1 -0
- package/dist/canonical/profiles.d.ts +40 -0
- package/dist/canonical/profiles.d.ts.map +1 -0
- package/dist/canonical/profiles.js +182 -0
- package/dist/canonical/profiles.js.map +1 -0
- package/dist/canonical/types.d.ts +124 -0
- package/dist/canonical/types.d.ts.map +1 -0
- package/dist/canonical/types.js +46 -0
- package/dist/canonical/types.js.map +1 -0
- package/dist/gates/delta.d.ts +45 -0
- package/dist/gates/delta.d.ts.map +1 -0
- package/dist/gates/delta.js +260 -0
- package/dist/gates/delta.js.map +1 -0
- package/dist/gates/index.d.ts +9 -0
- package/dist/gates/index.d.ts.map +1 -0
- package/dist/gates/index.js +9 -0
- package/dist/gates/index.js.map +1 -0
- package/dist/gates/types.d.ts +96 -0
- package/dist/gates/types.d.ts.map +1 -0
- package/dist/gates/types.js +59 -0
- package/dist/gates/types.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/meta.d.ts +90 -0
- package/dist/metrics/meta.d.ts.map +1 -0
- package/dist/metrics/meta.js +144 -0
- package/dist/metrics/meta.js.map +1 -0
- package/dist/tensor/canonical.d.ts +53 -0
- package/dist/tensor/canonical.d.ts.map +1 -0
- package/dist/tensor/canonical.js +178 -0
- package/dist/tensor/canonical.js.map +1 -0
- package/dist/tensor/index.d.ts +22 -0
- package/dist/tensor/index.d.ts.map +1 -0
- package/dist/tensor/index.js +22 -0
- package/dist/tensor/index.js.map +1 -0
- package/dist/tensor/matrix.d.ts +62 -0
- package/dist/tensor/matrix.d.ts.map +1 -0
- package/dist/tensor/matrix.js +171 -0
- package/dist/tensor/matrix.js.map +1 -0
- package/dist/tensor/scoring.d.ts +73 -0
- package/dist/tensor/scoring.d.ts.map +1 -0
- package/dist/tensor/scoring.js +206 -0
- package/dist/tensor/scoring.js.map +1 -0
- package/dist/tensor/types.d.ts +176 -0
- package/dist/tensor/types.d.ts.map +1 -0
- package/dist/tensor/types.js +15 -0
- package/dist/tensor/types.js.map +1 -0
- package/package.json +13 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 메타 차원 집계 (Meta Dimensions Aggregation)
|
|
3
|
+
*
|
|
4
|
+
* 5D 복잡도 → 3D 메타 차원 변환
|
|
5
|
+
*
|
|
6
|
+
* 햄 샌드위치 분해:
|
|
7
|
+
* - 🍞 Security: coupling + globalAccess + envDependency
|
|
8
|
+
* - 🧀 Context: cognitive + nestingDepth + callbackDepth
|
|
9
|
+
* - 🥓 Behavior: state + async + sideEffects
|
|
10
|
+
*/
|
|
11
|
+
import type { DimensionalComplexity, StateComplexity, AsyncComplexity, CouplingComplexity } from '../types.js';
|
|
12
|
+
import type { MetaDimensions, MetaWeights } from '../canonical/types.js';
|
|
13
|
+
/**
|
|
14
|
+
* 🍞 Security 집계 가중치
|
|
15
|
+
*/
|
|
16
|
+
interface SecurityAggregationWeights {
|
|
17
|
+
globalAccess: number;
|
|
18
|
+
envDependency: number;
|
|
19
|
+
implicitIO: number;
|
|
20
|
+
couplingBase: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 🧀 Context 집계 가중치
|
|
24
|
+
*/
|
|
25
|
+
interface ContextAggregationWeights {
|
|
26
|
+
cognitive: number;
|
|
27
|
+
nesting: number;
|
|
28
|
+
callbackDepth: number;
|
|
29
|
+
control: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 🥓 Behavior 집계 가중치
|
|
33
|
+
*/
|
|
34
|
+
interface BehaviorAggregationWeights {
|
|
35
|
+
stateMutations: number;
|
|
36
|
+
stateBranches: number;
|
|
37
|
+
asyncBoundaries: number;
|
|
38
|
+
sideEffects: number;
|
|
39
|
+
promiseChains: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 🍞 Security 점수 계산
|
|
43
|
+
*
|
|
44
|
+
* 구조 안정성: 외부 의존, 환경 결합, 암묵적 I/O
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculateSecurity(coupling: CouplingComplexity, weights?: SecurityAggregationWeights): number;
|
|
47
|
+
/**
|
|
48
|
+
* 🧀 Context 점수 계산
|
|
49
|
+
*
|
|
50
|
+
* 맥락 밀도: 인지 복잡도, 중첩 깊이, 콜백 깊이
|
|
51
|
+
*/
|
|
52
|
+
export declare function calculateContext(control: number, nesting: number, async: AsyncComplexity, weights?: ContextAggregationWeights): number;
|
|
53
|
+
/**
|
|
54
|
+
* 🥓 Behavior 점수 계산
|
|
55
|
+
*
|
|
56
|
+
* 행동 보존성: 상태 변이, 비동기, 부작용
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateBehavior(state: StateComplexity, async: AsyncComplexity, coupling: CouplingComplexity, weights?: BehaviorAggregationWeights): number;
|
|
59
|
+
/**
|
|
60
|
+
* DimensionalComplexity → MetaDimensions 변환
|
|
61
|
+
*
|
|
62
|
+
* 5D 복잡도를 3D 메타 차원으로 집계
|
|
63
|
+
*/
|
|
64
|
+
export declare function toMetaDimensions(dimensional: DimensionalComplexity): MetaDimensions;
|
|
65
|
+
/**
|
|
66
|
+
* 메타 차원 가중 합계
|
|
67
|
+
*/
|
|
68
|
+
export declare function calculateMetaWeightedSum(meta: MetaDimensions, weights?: MetaWeights): number;
|
|
69
|
+
/**
|
|
70
|
+
* 메타 차원 정규화 (0-1 범위)
|
|
71
|
+
*/
|
|
72
|
+
export declare function normalizeMetaDimensions(meta: MetaDimensions, maxValues?: MetaDimensions): MetaDimensions;
|
|
73
|
+
/**
|
|
74
|
+
* 두 메타 차원 간의 유클리드 거리
|
|
75
|
+
*/
|
|
76
|
+
export declare function metaDistance(a: MetaDimensions, b: MetaDimensions): number;
|
|
77
|
+
/**
|
|
78
|
+
* 메타 차원 덧셈
|
|
79
|
+
*/
|
|
80
|
+
export declare function addMetaDimensions(a: MetaDimensions, b: MetaDimensions): MetaDimensions;
|
|
81
|
+
/**
|
|
82
|
+
* 메타 차원 차이
|
|
83
|
+
*/
|
|
84
|
+
export declare function subtractMetaDimensions(a: MetaDimensions, b: MetaDimensions): MetaDimensions;
|
|
85
|
+
/**
|
|
86
|
+
* 빈 메타 차원
|
|
87
|
+
*/
|
|
88
|
+
export declare const ZERO_META: MetaDimensions;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/metrics/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,kBAAkB,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOzE;;GAEG;AACH,UAAU,0BAA0B;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AASD;;GAEG;AACH,UAAU,yBAAyB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AASD;;GAEG;AACH,UAAU,0BAA0B;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAA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원 집계 (Meta Dimensions Aggregation)
|
|
3
|
+
*
|
|
4
|
+
* 5D 복잡도 → 3D 메타 차원 변환
|
|
5
|
+
*
|
|
6
|
+
* 햄 샌드위치 분해:
|
|
7
|
+
* - 🍞 Security: coupling + globalAccess + envDependency
|
|
8
|
+
* - 🧀 Context: cognitive + nestingDepth + callbackDepth
|
|
9
|
+
* - 🥓 Behavior: state + async + sideEffects
|
|
10
|
+
*/
|
|
11
|
+
import { DEFAULT_META_WEIGHTS } from '../canonical/types.js';
|
|
12
|
+
const DEFAULT_SECURITY_WEIGHTS = {
|
|
13
|
+
globalAccess: 2.0,
|
|
14
|
+
envDependency: 1.5,
|
|
15
|
+
implicitIO: 1.0,
|
|
16
|
+
couplingBase: 0.5,
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_CONTEXT_WEIGHTS = {
|
|
19
|
+
cognitive: 1.0,
|
|
20
|
+
nesting: 1.5,
|
|
21
|
+
callbackDepth: 2.0,
|
|
22
|
+
control: 0.5,
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_BEHAVIOR_WEIGHTS = {
|
|
25
|
+
stateMutations: 2.0,
|
|
26
|
+
stateBranches: 1.5,
|
|
27
|
+
asyncBoundaries: 1.0,
|
|
28
|
+
sideEffects: 2.5,
|
|
29
|
+
promiseChains: 1.0,
|
|
30
|
+
};
|
|
31
|
+
// ─────────────────────────────────────────────────────────────────
|
|
32
|
+
// 개별 차원 계산
|
|
33
|
+
// ─────────────────────────────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* 🍞 Security 점수 계산
|
|
36
|
+
*
|
|
37
|
+
* 구조 안정성: 외부 의존, 환경 결합, 암묵적 I/O
|
|
38
|
+
*/
|
|
39
|
+
export function calculateSecurity(coupling, weights = DEFAULT_SECURITY_WEIGHTS) {
|
|
40
|
+
const globalScore = coupling.globalAccess.length * weights.globalAccess;
|
|
41
|
+
const envScore = coupling.envDependency.length * weights.envDependency;
|
|
42
|
+
const ioScore = coupling.implicitIO.length * weights.implicitIO;
|
|
43
|
+
const baseScore = (coupling.sideEffects.length +
|
|
44
|
+
coupling.closureCaptures.length) * weights.couplingBase;
|
|
45
|
+
return Math.round((globalScore + envScore + ioScore + baseScore) * 10) / 10;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 🧀 Context 점수 계산
|
|
49
|
+
*
|
|
50
|
+
* 맥락 밀도: 인지 복잡도, 중첩 깊이, 콜백 깊이
|
|
51
|
+
*/
|
|
52
|
+
export function calculateContext(control, nesting, async, weights = DEFAULT_CONTEXT_WEIGHTS) {
|
|
53
|
+
// cognitive ≈ control + nesting 기반 추정
|
|
54
|
+
const cognitiveEstimate = control + nesting;
|
|
55
|
+
const score = cognitiveEstimate * weights.cognitive +
|
|
56
|
+
nesting * weights.nesting +
|
|
57
|
+
async.callbackDepth * weights.callbackDepth +
|
|
58
|
+
control * weights.control;
|
|
59
|
+
return Math.round(score * 10) / 10;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 🥓 Behavior 점수 계산
|
|
63
|
+
*
|
|
64
|
+
* 행동 보존성: 상태 변이, 비동기, 부작용
|
|
65
|
+
*/
|
|
66
|
+
export function calculateBehavior(state, async, coupling, weights = DEFAULT_BEHAVIOR_WEIGHTS) {
|
|
67
|
+
const stateScore = state.stateMutations * weights.stateMutations +
|
|
68
|
+
state.stateBranches * weights.stateBranches;
|
|
69
|
+
const asyncScore = async.asyncBoundaries * weights.asyncBoundaries +
|
|
70
|
+
async.promiseChains * weights.promiseChains;
|
|
71
|
+
const sideEffectScore = coupling.sideEffects.length * weights.sideEffects;
|
|
72
|
+
return Math.round((stateScore + asyncScore + sideEffectScore) * 10) / 10;
|
|
73
|
+
}
|
|
74
|
+
// ─────────────────────────────────────────────────────────────────
|
|
75
|
+
// 통합 변환
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────
|
|
77
|
+
/**
|
|
78
|
+
* DimensionalComplexity → MetaDimensions 변환
|
|
79
|
+
*
|
|
80
|
+
* 5D 복잡도를 3D 메타 차원으로 집계
|
|
81
|
+
*/
|
|
82
|
+
export function toMetaDimensions(dimensional) {
|
|
83
|
+
return {
|
|
84
|
+
security: calculateSecurity(dimensional.coupling),
|
|
85
|
+
context: calculateContext(dimensional.control, dimensional.nesting, dimensional.async),
|
|
86
|
+
behavior: calculateBehavior(dimensional.state, dimensional.async, dimensional.coupling),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 메타 차원 가중 합계
|
|
91
|
+
*/
|
|
92
|
+
export function calculateMetaWeightedSum(meta, weights = DEFAULT_META_WEIGHTS) {
|
|
93
|
+
return (meta.security * weights.security +
|
|
94
|
+
meta.context * weights.context +
|
|
95
|
+
meta.behavior * weights.behavior);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 메타 차원 정규화 (0-1 범위)
|
|
99
|
+
*/
|
|
100
|
+
export function normalizeMetaDimensions(meta, maxValues = { security: 50, context: 100, behavior: 50 }) {
|
|
101
|
+
return {
|
|
102
|
+
security: Math.min(meta.security / maxValues.security, 1),
|
|
103
|
+
context: Math.min(meta.context / maxValues.context, 1),
|
|
104
|
+
behavior: Math.min(meta.behavior / maxValues.behavior, 1),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 두 메타 차원 간의 유클리드 거리
|
|
109
|
+
*/
|
|
110
|
+
export function metaDistance(a, b) {
|
|
111
|
+
const dx = a.security - b.security;
|
|
112
|
+
const dy = a.context - b.context;
|
|
113
|
+
const dz = a.behavior - b.behavior;
|
|
114
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 메타 차원 덧셈
|
|
118
|
+
*/
|
|
119
|
+
export function addMetaDimensions(a, b) {
|
|
120
|
+
return {
|
|
121
|
+
security: a.security + b.security,
|
|
122
|
+
context: a.context + b.context,
|
|
123
|
+
behavior: a.behavior + b.behavior,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 메타 차원 차이
|
|
128
|
+
*/
|
|
129
|
+
export function subtractMetaDimensions(a, b) {
|
|
130
|
+
return {
|
|
131
|
+
security: a.security - b.security,
|
|
132
|
+
context: a.context - b.context,
|
|
133
|
+
behavior: a.behavior - b.behavior,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 빈 메타 차원
|
|
138
|
+
*/
|
|
139
|
+
export const ZERO_META = {
|
|
140
|
+
security: 0,
|
|
141
|
+
context: 0,
|
|
142
|
+
behavior: 0,
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/metrics/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAgB7D,MAAM,wBAAwB,GAA+B;IAC3D,YAAY,EAAE,GAAG;IACjB,aAAa,EAAE,GAAG;IAClB,UAAU,EAAE,GAAG;IACf,YAAY,EAAE,GAAG;CAClB,CAAC;AAYF,MAAM,uBAAuB,GAA8B;IACzD,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,GAAG;IAClB,OAAO,EAAE,GAAG;CACb,CAAC;AAaF,MAAM,wBAAwB,GAA+B;IAC3D,cAAc,EAAE,GAAG;IACnB,aAAa,EAAE,GAAG;IAClB,eAAe,EAAE,GAAG;IACpB,WAAW,EAAE,GAAG;IAChB,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,oEAAoE;AACpE,WAAW;AACX,oEAAoE;AAEpE;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAA4B,EAC5B,UAAsC,wBAAwB;IAE9D,MAAM,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,GAAG,OAAO,CAAC,Y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AC;IACV,QAAQ,EAAE,CAAC;CACZ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Canonical Profiles and Deviation Analysis
|
|
3
|
+
*
|
|
4
|
+
* Φ: ModuleType → CanonicalProfile
|
|
5
|
+
* δ(v, Φ(τ)) = ‖v - Φ(τ)‖_M (Mahalanobis-like distance)
|
|
6
|
+
*/
|
|
7
|
+
import type { Vector5D, ModuleType, DeviationResult } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Canonical profile bounds for a module type
|
|
10
|
+
*/
|
|
11
|
+
export interface CanonicalBounds {
|
|
12
|
+
control: [number, number];
|
|
13
|
+
nesting: [number, number];
|
|
14
|
+
state: [number, number];
|
|
15
|
+
async: [number, number];
|
|
16
|
+
coupling: [number, number];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Canonical profiles per module type (based on v0.0.3 spec)
|
|
20
|
+
*/
|
|
21
|
+
export declare const CANONICAL_5D_PROFILES: Record<ModuleType, CanonicalBounds>;
|
|
22
|
+
/**
|
|
23
|
+
* Get canonical profile for module type
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCanonicalProfile(moduleType: ModuleType): CanonicalBounds;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate centroid of canonical profile
|
|
28
|
+
*/
|
|
29
|
+
export declare function getProfileCentroid(profile: CanonicalBounds): Vector5D;
|
|
30
|
+
/**
|
|
31
|
+
* Check if vector is within canonical bounds
|
|
32
|
+
*/
|
|
33
|
+
export declare function isWithinCanonicalBounds(vector: Vector5D, profile: CanonicalBounds): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get dimensions that violate canonical bounds
|
|
36
|
+
*/
|
|
37
|
+
export declare function getViolationDimensions(vector: Vector5D, profile: CanonicalBounds): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Check if vector is orphan (outside ALL canonical regions)
|
|
40
|
+
*/
|
|
41
|
+
export declare function isOrphan(vector: Vector5D): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Analyze deviation from canonical form
|
|
44
|
+
*/
|
|
45
|
+
export declare function analyzeDeviation(vector: Vector5D, moduleType?: ModuleType): DeviationResult;
|
|
46
|
+
/**
|
|
47
|
+
* Find the best fitting module type for a vector
|
|
48
|
+
*/
|
|
49
|
+
export declare function findBestModuleType(vector: Vector5D): {
|
|
50
|
+
type: ModuleType;
|
|
51
|
+
distance: number;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/tensor/canonical.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQxE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,UAAU,EAAE,eAAe,CA2CrE,CAAC;AAEF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAE3E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAQrE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,eAAe,GACvB,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,eAAe,GACvB,MAAM,EAAE,CAaV;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CASlD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,QAAQ,EAChB,UAAU,GAAE,UAAsB,GACjC,eAAe,CA2CjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAsB3F"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Canonical Profiles and Deviation Analysis
|
|
3
|
+
*
|
|
4
|
+
* Φ: ModuleType → CanonicalProfile
|
|
5
|
+
* δ(v, Φ(τ)) = ‖v - Φ(τ)‖_M (Mahalanobis-like distance)
|
|
6
|
+
*/
|
|
7
|
+
import { getInteractionMatrix, euclideanDistance, mahalanobisDistance, vectorToArray, } from './matrix.js';
|
|
8
|
+
/**
|
|
9
|
+
* Canonical profiles per module type (based on v0.0.3 spec)
|
|
10
|
+
*/
|
|
11
|
+
export const CANONICAL_5D_PROFILES = {
|
|
12
|
+
api: {
|
|
13
|
+
control: [0, 5], // low: thin controllers
|
|
14
|
+
nesting: [0, 3], // low: flat structure
|
|
15
|
+
state: [0, 2], // low: stateless preferred
|
|
16
|
+
async: [0, 3], // low: simple I/O
|
|
17
|
+
coupling: [0, 3], // low: explicit deps
|
|
18
|
+
},
|
|
19
|
+
lib: {
|
|
20
|
+
control: [0, 10], // medium: algorithmic complexity ok
|
|
21
|
+
nesting: [0, 5], // medium: some depth acceptable
|
|
22
|
+
state: [0, 2], // low: pure functions preferred
|
|
23
|
+
async: [0, 2], // low: sync preferred
|
|
24
|
+
coupling: [0, 2], // low: minimal deps
|
|
25
|
+
},
|
|
26
|
+
app: {
|
|
27
|
+
control: [0, 10], // medium: business logic
|
|
28
|
+
nesting: [0, 5], // medium: reasonable depth
|
|
29
|
+
state: [0, 8], // medium: stateful ok
|
|
30
|
+
async: [0, 8], // medium: async workflows
|
|
31
|
+
coupling: [0, 5], // low: controlled deps
|
|
32
|
+
},
|
|
33
|
+
web: {
|
|
34
|
+
control: [0, 8], // medium: UI logic
|
|
35
|
+
nesting: [0, 10], // higher: component hierarchy
|
|
36
|
+
state: [0, 5], // medium: UI state
|
|
37
|
+
async: [0, 5], // medium: data fetching
|
|
38
|
+
coupling: [0, 3], // low: component isolation
|
|
39
|
+
},
|
|
40
|
+
deploy: {
|
|
41
|
+
control: [0, 3], // low: simple scripts
|
|
42
|
+
nesting: [0, 2], // low: flat
|
|
43
|
+
state: [0, 2], // low: idempotent
|
|
44
|
+
async: [0, 2], // low: sequential
|
|
45
|
+
coupling: [0, 3], // low: explicit config
|
|
46
|
+
},
|
|
47
|
+
unknown: {
|
|
48
|
+
control: [0, 15], // permissive
|
|
49
|
+
nesting: [0, 10],
|
|
50
|
+
state: [0, 10],
|
|
51
|
+
async: [0, 10],
|
|
52
|
+
coupling: [0, 10],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get canonical profile for module type
|
|
57
|
+
*/
|
|
58
|
+
export function getCanonicalProfile(moduleType) {
|
|
59
|
+
return CANONICAL_5D_PROFILES[moduleType] ?? CANONICAL_5D_PROFILES.unknown;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calculate centroid of canonical profile
|
|
63
|
+
*/
|
|
64
|
+
export function getProfileCentroid(profile) {
|
|
65
|
+
return {
|
|
66
|
+
control: (profile.control[0] + profile.control[1]) / 2,
|
|
67
|
+
nesting: (profile.nesting[0] + profile.nesting[1]) / 2,
|
|
68
|
+
state: (profile.state[0] + profile.state[1]) / 2,
|
|
69
|
+
async: (profile.async[0] + profile.async[1]) / 2,
|
|
70
|
+
coupling: (profile.coupling[0] + profile.coupling[1]) / 2,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if vector is within canonical bounds
|
|
75
|
+
*/
|
|
76
|
+
export function isWithinCanonicalBounds(vector, profile) {
|
|
77
|
+
return (vector.control >= profile.control[0] && vector.control <= profile.control[1] &&
|
|
78
|
+
vector.nesting >= profile.nesting[0] && vector.nesting <= profile.nesting[1] &&
|
|
79
|
+
vector.state >= profile.state[0] && vector.state <= profile.state[1] &&
|
|
80
|
+
vector.async >= profile.async[0] && vector.async <= profile.async[1] &&
|
|
81
|
+
vector.coupling >= profile.coupling[0] && vector.coupling <= profile.coupling[1]);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get dimensions that violate canonical bounds
|
|
85
|
+
*/
|
|
86
|
+
export function getViolationDimensions(vector, profile) {
|
|
87
|
+
const violations = [];
|
|
88
|
+
const dims = ['control', 'nesting', 'state', 'async', 'coupling'];
|
|
89
|
+
for (const dim of dims) {
|
|
90
|
+
const value = vector[dim];
|
|
91
|
+
const [min, max] = profile[dim];
|
|
92
|
+
if (value < min || value > max) {
|
|
93
|
+
violations.push(dim);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return violations;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if vector is orphan (outside ALL canonical regions)
|
|
100
|
+
*/
|
|
101
|
+
export function isOrphan(vector) {
|
|
102
|
+
for (const moduleType of Object.keys(CANONICAL_5D_PROFILES)) {
|
|
103
|
+
if (moduleType === 'unknown')
|
|
104
|
+
continue;
|
|
105
|
+
const profile = CANONICAL_5D_PROFILES[moduleType];
|
|
106
|
+
if (isWithinCanonicalBounds(vector, profile)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Analyze deviation from canonical form
|
|
114
|
+
*/
|
|
115
|
+
export function analyzeDeviation(vector, moduleType = 'unknown') {
|
|
116
|
+
const profile = getCanonicalProfile(moduleType);
|
|
117
|
+
const centroid = getProfileCentroid(profile);
|
|
118
|
+
const matrix = getInteractionMatrix(moduleType);
|
|
119
|
+
// Calculate distances
|
|
120
|
+
const eucDist = euclideanDistance(vector, centroid);
|
|
121
|
+
const mahDist = mahalanobisDistance(vector, centroid, matrix);
|
|
122
|
+
// Max dimension deviation
|
|
123
|
+
const arr = vectorToArray(vector);
|
|
124
|
+
const centArr = vectorToArray(centroid);
|
|
125
|
+
const maxDev = Math.max(...arr.map((v, i) => Math.abs(v - centArr[i])));
|
|
126
|
+
// Normalize to 0-1 scale (assuming max reasonable deviation is 50)
|
|
127
|
+
const normDev = Math.min(1.0, mahDist / 50.0);
|
|
128
|
+
// Check canonical bounds
|
|
129
|
+
const withinBounds = isWithinCanonicalBounds(vector, profile);
|
|
130
|
+
const violations = getViolationDimensions(vector, profile);
|
|
131
|
+
const orphan = isOrphan(vector);
|
|
132
|
+
let status;
|
|
133
|
+
if (withinBounds) {
|
|
134
|
+
status = 'canonical';
|
|
135
|
+
}
|
|
136
|
+
else if (orphan) {
|
|
137
|
+
status = 'orphan';
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
status = 'deviated';
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
euclideanDistance: Math.round(eucDist * 1000) / 1000,
|
|
144
|
+
mahalanobisDistance: Math.round(mahDist * 1000) / 1000,
|
|
145
|
+
maxDimensionDeviation: Math.round(maxDev * 1000) / 1000,
|
|
146
|
+
normalizedDeviation: Math.round(normDev * 1000) / 1000,
|
|
147
|
+
isCanonical: withinBounds,
|
|
148
|
+
isOrphan: orphan,
|
|
149
|
+
moduleType,
|
|
150
|
+
vector,
|
|
151
|
+
violationDimensions: violations,
|
|
152
|
+
status,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Find the best fitting module type for a vector
|
|
157
|
+
*/
|
|
158
|
+
export function findBestModuleType(vector) {
|
|
159
|
+
let bestType = 'unknown';
|
|
160
|
+
let bestDist = Infinity;
|
|
161
|
+
for (const moduleType of Object.keys(CANONICAL_5D_PROFILES)) {
|
|
162
|
+
if (moduleType === 'unknown')
|
|
163
|
+
continue;
|
|
164
|
+
const profile = CANONICAL_5D_PROFILES[moduleType];
|
|
165
|
+
const centroid = getProfileCentroid(profile);
|
|
166
|
+
const matrix = getInteractionMatrix(moduleType);
|
|
167
|
+
const dist = mahalanobisDistance(vector, centroid, matrix);
|
|
168
|
+
if (dist < bestDist) {
|
|
169
|
+
bestDist = dist;
|
|
170
|
+
bestType = moduleType;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
type: bestType,
|
|
175
|
+
distance: Math.round(bestDist * 1000) / 1000,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/tensor/canonical.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AAarB;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAwC;IACxE,GAAG,EAAE;QACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAO,wBAAwB;QAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAO,sBAAsB;QAC5C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,2BAA2B;QACjD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,kBAAkB;QACxC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAM,qBAAqB;KAC5C;IACD,GAAG,EAAE;QACH,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAM,oCAAoC;QAC1D,OAA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AC,OAAO,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAEhD,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YACpB,QAAQ,GAAG,IAAI,CAAC;YAChB,QAAQ,GAAG,UAAU,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,IAAI;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Tensor-based Complexity Analysis
|
|
3
|
+
*
|
|
4
|
+
* Second-order tensor framework for multi-dimensional code complexity.
|
|
5
|
+
*
|
|
6
|
+
* Mathematical foundation:
|
|
7
|
+
* score = v^T M v + <v, w> + ε‖v‖²
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - 5D complexity vector: [Control, Nesting, State, Async, Coupling]
|
|
11
|
+
* - Interaction matrix M for dimension cross-effects
|
|
12
|
+
* - ε-regularization for convergence guarantee
|
|
13
|
+
* - Module-type canonical profiles
|
|
14
|
+
* - Hodge decomposition of complexity space
|
|
15
|
+
*/
|
|
16
|
+
export type { Vector5D, ModuleType, Matrix5x5, TensorScore, ConvergenceStatus, ConvergenceAnalysis, HodgeDecomposition, ComplexityLevel, DeviationResult, RefactoringRecommendation, } from './types.js';
|
|
17
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, } from './types.js';
|
|
18
|
+
export { DEFAULT_MATRIX, MODULE_MATRICES, getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './matrix.js';
|
|
19
|
+
export { DEFAULT_WEIGHTS, calculateTensorScore, convergenceScore, estimateLipschitz, analyzeConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './scoring.js';
|
|
20
|
+
export type { CanonicalBounds } from './canonical.js';
|
|
21
|
+
export { CANONICAL_5D_PROFILES, getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType, } from './canonical.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tensor/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,YAAY,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,WAAW,GACZ,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Tensor-based Complexity Analysis
|
|
3
|
+
*
|
|
4
|
+
* Second-order tensor framework for multi-dimensional code complexity.
|
|
5
|
+
*
|
|
6
|
+
* Mathematical foundation:
|
|
7
|
+
* score = v^T M v + <v, w> + ε‖v‖²
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - 5D complexity vector: [Control, Nesting, State, Async, Coupling]
|
|
11
|
+
* - Interaction matrix M for dimension cross-effects
|
|
12
|
+
* - ε-regularization for convergence guarantee
|
|
13
|
+
* - Module-type canonical profiles
|
|
14
|
+
* - Hodge decomposition of complexity space
|
|
15
|
+
*/
|
|
16
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, } from './types.js';
|
|
17
|
+
// Matrix operations
|
|
18
|
+
export { DEFAULT_MATRIX, MODULE_MATRICES, getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './matrix.js';
|
|
19
|
+
// Scoring
|
|
20
|
+
export { DEFAULT_WEIGHTS, calculateTensorScore, convergenceScore, estimateLipschitz, analyzeConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './scoring.js';
|
|
21
|
+
export { CANONICAL_5D_PROFILES, getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType, } from './canonical.js';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tensor/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgBH,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,oBAAoB;AACpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,UAAU;AACV,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,WAAW,GACZ,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Interaction Matrix for Second-Order Tensor Analysis
|
|
3
|
+
*
|
|
4
|
+
* M[i,j] represents the interaction strength between dimensions i and j.
|
|
5
|
+
* - Diagonal: self-interaction (typically 1.0)
|
|
6
|
+
* - Off-diagonal: cross-dimension interaction
|
|
7
|
+
*/
|
|
8
|
+
import type { Matrix5x5, ModuleType, Vector5D } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default interaction matrix (symmetric, positive semi-definite)
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_MATRIX: Matrix5x5;
|
|
13
|
+
/**
|
|
14
|
+
* Module-type specific interaction matrices
|
|
15
|
+
*/
|
|
16
|
+
export declare const MODULE_MATRICES: Record<ModuleType, Matrix5x5>;
|
|
17
|
+
/**
|
|
18
|
+
* Get interaction matrix for module type
|
|
19
|
+
*/
|
|
20
|
+
export declare function getInteractionMatrix(moduleType: ModuleType): Matrix5x5;
|
|
21
|
+
/**
|
|
22
|
+
* Convert Vector5D to array
|
|
23
|
+
*/
|
|
24
|
+
export declare function vectorToArray(v: Vector5D): number[];
|
|
25
|
+
/**
|
|
26
|
+
* Create Vector5D from array
|
|
27
|
+
*/
|
|
28
|
+
export declare function arrayToVector(arr: number[]): Vector5D;
|
|
29
|
+
/**
|
|
30
|
+
* Create zero vector
|
|
31
|
+
*/
|
|
32
|
+
export declare function zeroVector(): Vector5D;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate L2 norm of vector
|
|
35
|
+
*/
|
|
36
|
+
export declare function vectorNorm(v: Vector5D): number;
|
|
37
|
+
/**
|
|
38
|
+
* Calculate dot product of two vectors
|
|
39
|
+
*/
|
|
40
|
+
export declare function dotProduct(v1: Vector5D, v2: Vector5D): number;
|
|
41
|
+
/**
|
|
42
|
+
* Calculate quadratic form: v^T M v
|
|
43
|
+
*
|
|
44
|
+
* This captures dimension interactions.
|
|
45
|
+
*/
|
|
46
|
+
export declare function quadraticForm(v: Vector5D, matrix: Matrix5x5): number;
|
|
47
|
+
/**
|
|
48
|
+
* Check if matrix is positive semi-definite using diagonal dominance
|
|
49
|
+
* (conservative approximation)
|
|
50
|
+
*/
|
|
51
|
+
export declare function isPositiveSemidefinite(matrix: Matrix5x5): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Euclidean distance between two vectors
|
|
54
|
+
*/
|
|
55
|
+
export declare function euclideanDistance(v1: Vector5D, v2: Vector5D): number;
|
|
56
|
+
/**
|
|
57
|
+
* Mahalanobis-like distance using interaction matrix
|
|
58
|
+
*
|
|
59
|
+
* δ(v, target) = sqrt((v - target)^T M (v - target))
|
|
60
|
+
*/
|
|
61
|
+
export declare function mahalanobisDistance(v: Vector5D, target: Vector5D, matrix: Matrix5x5): number;
|
|
62
|
+
//# sourceMappingURL=matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../../src/tensor/matrix.ts"],"names":[],"mappings":"A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