Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

char* tensor_to_string function doesn't look right #22

Open
pl-csci opened this issue Dec 5, 2024 · 0 comments
Open

char* tensor_to_string function doesn't look right #22

pl-csci opened this issue Dec 5, 2024 · 0 comments

Comments

@pl-csci
Copy link

pl-csci commented Dec 5, 2024

I think you should remove the conditional at the top of the tensor_to_string function in tensor1d.c. Tell me if I'm wrong.
Here's the current code:

char* tensor_to_string(Tensor* t) {
    // if we already have a string representation, return it
    if (t->repr != NULL) { return t->repr; }
    // otherwise create a new string representation
    ... 
    }

However,

Tensor* tensor_setitem(Tensor* T, int ix, float val) {...}

is an in-place operation that doesn't update the string representation (t->repr) of the tensor.
Or did I miss the line somewhere else?
Adding a dirty flag at the tensor level that flips to true when t->repr would help, but not fully. Because if we have two tensors, t1 and t2, where t1->storage == t2->storage, and if we then perform an in-place operation on t1, t2 wouldn't get the memo, so to speak. We'd need a dirty flag at the storage level as well.

In a micro-implementation like this, it's probably better to nix the conditional in the tensor_to_string function, allow it to regenerate the string on the fly, since we only need it for text output, which is an infrequent task in the context of tensor ops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant