Skip to content

Use lists of lists for elements #7

Open
@sneakers-the-rat

Description

@sneakers-the-rat

Similar to: #6

Currently it seems like the elements slot is intended to store a flat list of values that are given shape by the indices, and that might bleed into the other parts of the implementation. It would be really nice to be able to use the domain-specific representation of arrays in different formats though! One way of doing this would be to make the in-memory storage totally generic w.r.t. the generator format, which I like, but since the format is YAML there is some degree of "JSON-like primacy" where the "natural" representation of data has to fit in JSON, which makes sense even if it's worth being careful about not specifying too much about serialization in the schema.

JSON-Schema actually can represent arrays natively as lists of lists! So here for a dense array for an RGB image:

# sorry for the long ass import string, still working on virtualizing imports
import json
from nwb_linkml.models.pydantic.core.v2_6_0_alpha.core_nwb_image import RGBImage

print(json.dumps(RGBImage.model_json_schema(), indent=2))
{
  "additionalProperties": false,
  "description": "A color image.",
  "properties": {
    "hdf5_path": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "The absolute path that this object is stored in an NWB file",
      "title": "Hdf5 Path"
    },
    "name": {
      "title": "Name",
      "type": "string"
    },
    "resolution": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Pixel resolution of the image, in pixels per centimeter.",
      "title": "Resolution"
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Description of the image.",
      "title": "Description"
    },
    "array": {
      "anyOf": [
        {
          "items": {
            "items": {
              "items": {
                "type": "number"
              },
              "maxItems": 3,
              "minItems": 3,
              "type": "array"
            },
            "type": "array"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Array"
    }
  },
  "required": [
    "name"
  ],
  "title": "RGBImage",
  "type": "object"
}

So i'm not sure what the current status is for in-memory JSON-like arrays, but it would be nice to use lists of lists (as has been discussed in a bunch of places over on the main linkml repo :)) instead of a flat list with indices, at least for dense arrays. Another reason why we might want to make NDArray and SparseArray separable classes too, since the flat model with adjoining indices is a perfectly good model for sparse arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions