# Dense Distances

> NumKong for JavaScript

Dense distance entrypoints work directly on the standard numeric `TypedArray` types.

```ts
import { sqeuclidean, euclidean, angular } from "numkong";

const a = new Float32Array([1, 2, 3]);
const b = new Float32Array([4, 5, 6]);

console.log(sqeuclidean(a, b)); // equivalent shape to a manual sum((a[i] - b[i]) ** 2)
console.log(euclidean(a, b));
console.log(angular(a, b));
```

When the storage type is one of the standard JS typed arrays, dtype inference is automatic.

`import * as numkong from 'numkong';`

## sqeuclidean

Computes the squared Euclidean distance between two vectors.

```typescript
function sqeuclidean(a: NumericArray, b: NumericArray): number
```

```typescript
function sqeuclidean(
    a: DistanceArray,
    b: DistanceArray,
    dtype: DType,
): number
```

```typescript
function sqeuclidean(a: TensorBase, b: TensorBase): number
```

- `a`: The first vector, as TypedArray or TensorBase.
- `b`: The second vector, matching the type and length of `a`.
- `dtype`: Optional dtype string for custom types, e.g. 'f16', 'bf16', 'e4m3'.

## euclidean

Computes the Euclidean distance between two vectors.

```typescript
function euclidean(a: NumericArray, b: NumericArray): number
```

```typescript
function euclidean(
    a: DistanceArray,
    b: DistanceArray,
    dtype: DType,
): number
```

```typescript
function euclidean(a: TensorBase, b: TensorBase): number
```

- `a`: The first vector, as TypedArray or TensorBase.
- `b`: The second vector, matching the type and length of `a`.
- `dtype`: Optional dtype string for custom types, e.g. 'f16', 'bf16', 'e4m3'.

## angular

Computes the angular distance between two vectors.

```typescript
function angular(a: NumericArray, b: NumericArray): number
```

```typescript
function angular(
    a: DistanceArray,
    b: DistanceArray,
    dtype: DType,
): number
```

```typescript
function angular(a: TensorBase, b: TensorBase): number
```

- `a`: The first vector, as TypedArray or TensorBase.
- `b`: The second vector, matching the type and length of `a`.
- `dtype`: Optional dtype string for custom types, e.g. 'f16', 'bf16', 'e4m3'.

