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

[change] Move from_string to array_creation_routine module #113

Merged

Conversation

forFudan
Copy link
Collaborator

It is to partially resolve #110, Item 8.

Move from_string to array_creation_routine module.

Also make a reload of array that accepts string as object.

The unit tests failed for inverse, matmul and solve, not this one.

Example:

import numojo as nm

fn main() raises:
    var A = nm.from_string[DType.int8]("[[[1,2],[3,4]],[[5,6],[7,8]]]")
    var B = nm.from_string[DType.float16]("[[1,2,3,4],[5,6,7,8]]")
    var C = nm.from_string[DType.float32]("[0.1, -2.3, 41.5, 19.29145, -199]")
    var D = nm.from_string[DType.int32]("[0.1, -2.3, 41.5, 19.29145, -199]")

    print(A)
    print(B)
    print(C)
    print(D)

The output goes as follows. Note that the numbers are automatically
casted to the dtype of the NDArray.

[[[     1       2       ]
  [     3       4       ]]
 [[     5       6       ]
  [     7       8       ]]]
3-D array  Shape: [2, 2, 2]  DType: int8

[[      1.0     2.0     3.0     4.0     ]
 [      5.0     6.0     7.0     8.0     ]]
2-D array  Shape: [2, 4]  DType: float16

[       0.10000000149011612     2.2999999523162842      41.5    19.291450500488281      199.0   ]
1-D array  Shape: [5]  DType: float32

[       0       2       41      19      199     ]
1-D array  Shape: [5]  DType: int32

… and name it as `from_string`. Also make a reload of `array` for it.
@forFudan forFudan added the enhancement New feature or request label Sep 22, 2024
@shivasankarka
Copy link
Collaborator

@forFudan shouldn't we use fromstring instead of from_string to keep it same as numpy?

@forFudan
Copy link
Collaborator Author

@forFudan shouldn't we use fromstring instead of from_string to keep it same as numpy?

@shivasankarka You are right! I made the change.

@MadAlex1997 MadAlex1997 merged commit 63c2c9f into Mojo-Numerics-and-Algorithms-group:experimental Sep 27, 2024
0 of 3 checks passed
@forFudan forFudan deleted the fromstr branch September 30, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants