Skip to content

Conversation

@G-2019-11
Copy link
Owner

Summary

  • add a minimal numpy-compatible array implementation to support neural network examples without external dependencies
  • provide sigmoid and identity helper functions used by the sample

Testing

  • python - <<'PY'
    from common.function import identity,sigmoid
    import numpy as np

def init_network():
network = {}
network['W1'] = np.array([[0.1,0.3,0.5],[0.4,0.2,0.6]])
network['b1'] = np.array([0.1,0.2,0.3])
network['W2'] = np.array([[0.1,0.4],[0.3,0.1],[0.5,0.6]])
network['b2'] = np.array([0.1,0.2])
network['W3'] = np.array([[0.1,0.3],[0.2,0.4]])
network['b3'] = np.array([0.1,0.2])
return network

def forward(network, x):
W1,W2,W3 = network['W1'],network['W2'],network['W3']
b1,b2,b3 = network['b1'],network['b2'],network['b3']
a1 = np.dot(x,W1) + b1
z1 = sigmoid(a1)
a2 = np.dot(z1,W2) + b2
z2 = sigmoid(a2)
a3 = np.dot(z2,W3) + b3
return a3

network = init_network()
x = np.array([1.0,0.5])
print(forward(network,x))
PY


https://chatgpt.com/codex/tasks/task_e_68d8be3a0fac8322be3722a6ed4f243d

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +22 to +28
def _elementwise(a: Any, b: Any, op) -> Any:
if _is_sequence(a) and _is_sequence(b):
return [_elementwise(x, y, op) for x, y in zip(a, b)]
if _is_sequence(a):
return [_elementwise(x, b, op) for x in a]
if _is_sequence(b):
return [_elementwise(a, y, op) for y in b]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Guard elementwise ops against shape mismatches

Binary operators delegate to _elementwise, which walks sequences using zip without checking length. When operands differ in size, the extra elements are silently dropped instead of broadcasting or raising an error as NumPy would. For example, np.array([1, 2, 3]) + np.array([10]) currently returns array([11]), masking a shape bug and producing incorrect results. Consider validating shapes or raising a ValueError when broadcasting rules are not implemented so consumers don’t get truncated outputs.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants