From fb9b75b9f6014f81e8e944f8b105ec75d9ecdc0d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 12 Jun 2021 21:35:20 -0400 Subject: Use Enclose documentation as an excuse to talk about unit arrays --- docs/doc/shape.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/doc/shape.html') diff --git a/docs/doc/shape.html b/docs/doc/shape.html index 350e3587..5852a698 100644 --- a/docs/doc/shape.html +++ b/docs/doc/shape.html @@ -45,7 +45,7 @@ ⟨ 0 1 ⟩

Units

-

A unit is an atom, or an array with no axes—rank 0. Since it doesn't have any axes, its shape should have no elements. It should be the empty list ⟨⟩ (with a fill of 0, like all shapes). As there's no first element in the shape, it's not obvious what the length should be, and a stricter language would just give an error. However, there are some good reasons to use a length of 1. First, the total number of elements is 1, meaning that if the length divides this number evenly (as it does for non-unit arrays) then the only possible natural number it can be is 1. Second, many functions that take a list for a particular argument also accept a unit, and treat it as a length-1 array. For example, 5a and 5a are identical. Defining 5 to be 1 means that =sa is always s.

+

A unit is an atom, or an array with no axes—rank 0. (See Enclose for more about unit arrays). Since it doesn't have any axes, its shape should have no elements. It should be the empty list ⟨⟩ (with a fill of 0, like all shapes). As there's no first element in the shape, it's not obvious what the length should be, and a stricter language would just give an error. However, there are some good reasons to use a length of 1. First, the total number of elements is 1, meaning that if the length divides this number evenly (as it does for non-unit arrays) then the only possible natural number it can be is 1. Second, many functions that take a list for a particular argument also accept a unit, and treat it as a length-1 array. For example, 5a and 5a are identical. Defining 5 to be 1 means that =sa is always s.

Despite this last point, it's important to remember that a unit isn't the same as a 1-element list. For example, the length-1 string "a" doesn't match <'a' but instead 'a'. And also bear in mind that having an empty shape doesn't make a unit an empty array. That would mean it has no elements, not one!

-- cgit v1.2.3