Skip to content

Design the “separation” mechanism #14

Description

@sangyx

Hi, I think the task of designing the “separation” between the data dimensions and the differentiation dimensions is the key part of our project. So we need to discuss and reach a good consensus. I want to add an attribute such as data_ndim to the object DiffArray to indicate the input type. And I can imagine a simple mechanism as follows:

# target: df(v)/dv
if f(v).data_ndim == 0:
    if v.data_ndim == 0:
       diff = cal_diff_ss(f(v), v, f) # diff is a scalar 
   elif v.data_ndim == 1: 
      diff = cal_diff_st(f(v), v, f) # diff is a tensor
    elif v.data_ndim == 2:
       diff = cal_diff_sm(f(v), v, f) # diff is a matrix
elif f(v).data_ndim == 1:
    if v.data_ndim == 0:
       diff = cal_diff_vs(f(v), v, f) # diff is a vector
    elif v.data_ndim == 1:
       diff = cal_diff_vt(f(v), v, f) # diff is a matrix
    elif v.data_ndim == 2:
       diff = cal_diff_vm(f(v), v, f) # diff is a matrix
elif f(v).data_ndim == 2:
    if v.data_ndim == 0:
       diff = cal_diff_ms(f(v), v, f) # diff is a matrix
    elif v.data_ndim == 1:
       diff = cal_diff_mt(f(v), v, f) # diff is a matrix
    elif v.data_ndim == 2:
       diff = cal_diff_mm(f(v), v, f) # diff is a matrix
else:
    raise ValueError("The data_type is not supported")

But I noticed the historical information in gitter: "Depends... I’d like to do something like say that out of an n dimensional array, k dimensions are for differentiation and n - k are for data." I can't understand it. Could you give more details or examples to illustrate it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions