Replies: 3 comments 2 replies
-
|
Hi @peeble111 -- thanks for the feedback. Is there any way you could provide a complete code? Also have you considered using NumPy arrays or simple lists instead of implementing your own array class? |
Beta Was this translation helpful? Give feedback.
-
**here the source source code Iwrote with the help of Gemini AI ### **idict.keys = [ 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]idict.values=['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']import extensions cdict = dict((c, i32(2**(i+2))) for i, c in enumerate('23456789TJQKA')) def b2a(x:i32)->str: @tuple if name == "main": I implemented own array class because I must call C++ subroutines of Bo Haglund library |
Beta Was this translation helpful? Give feedback.
-
|
Hi @peeble111; in your code if I replace python Also happy to help debug your |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary of Codon Array Instantiation Issues
We encountered significant and persistent difficulties instantiating Array objects in Codon, particularly when dealing with fixed-size arrays (Array[Type, Size]). The error messages were often contradictory and led to extensive trial-and-error.
This was the most confusing and recurring error.
Context: This error repeatedly occurred on lines attempting to instantiate Array objects, whether trying to create fixed-size or even dynamically-sized arrays using various seemingly standard methods.
Initial REMAINCARDS class definition: The class fields were initially defined as Array[i32, 3] and Array[i32, 16] (fixed-size arrays).
Attempts that triggered this error:
Direct construction with size and elements: E.g., Array[i32, 3](0, 0, 0) or Arrayi32, 16.
from_tuple method: E.g., Array[i32].from_tuple((0, 0, 0)). The error Array takes 1 generics (2 given) was consistently reported, even though Array[i32] clearly only uses one generic. This was highly misleading, suggesting the .from_tuple part or its arguments were being interpreted as a second generic for Array itself.
from_list method: Similar to from_tuple, Array[i32].from_list([...]) also triggered this error or later an "attribute not found" error (see point 3).
Constructor with size argument: E.g., Arrayi32. Even this explicit constructor for a dynamic array of a given size initially triggered the "Array takes 1 generics (2 given)" error. This was particularly paradoxical, as i32 is one generic, and 3 is a constructor argument, not a generic parameter.
Implicit assignment from Python list literal: E.g., some_array_var: Array[i32, 3] = [0, 0, 0]. When attempting this, the error Array takes 1 generics (2 given) would still appear, pointing to the Array[i32, 3] type hint on the left-hand side during the implicit conversion attempt.
Observation: The error message was extremely ambiguous. It suggested that Array could only ever accept one type parameter inside its brackets for any form of instantiation, which conflicts with the declaration syntax Array[Type, Size] and common patterns for such types. It appeared to be a parsing issue related to how Codon resolves Array constructors and type parameters.
Context: After the persistent Array instantiation errors, we attempted to use a custom init method within the @tuple class REMAINCARDS to handle the Array creation implicitly via assignment (e.g., self.currentTrickSuit = suit_list).
Error: 'REMAINCARDS' object has no method 'new' with arguments (Int[32], Int[32], List[int], List[int], List[int]).
Resolution: This clarified that Codon's @tuple classes have automatically generated new constructors that expect arguments directly matching the field types (Array[i32]), and do not support custom init methods for this purpose in the same way regular Python classes do. The fix involved removing init and pre-constructing the Array objects before passing them to the REMAINCARDS constructor.
Context: This occurred when attempting to use Array[i32].from_list(...) (and likely from_tuple) to instantiate Array objects after clarifying the new issue.
Error: 'Array[Int[32]]' object has no attribute 'from_list'.
Observation: This directly contradicted common expectations for array initialization in Python-like languages and documentation that suggests from_list might exist. It indicated that these specific factory methods were not available or accessible for Array[T] instantiation in this Codon environment.
After numerous failed attempts, the following syntax finally worked:
Class Definition: The REMAINCARDS class members were set to Array[i32] (dynamically sized). We had to abandon the compile-time fixed-size Array[i32, N] for instantiation to make progress.
Instantiation Syntax: Arrayi32 to create an Array[i32] of a given initial size (e.g., Arrayi32).
Population: Elements were then populated manually using array_obj[index] = value in a loop.
Example Code that worked:
Snippet di codice

...
current_suit_array_obj = Arrayi32 # Creates a dynamic array of size 3
current_suit_array_obj[0] = i32(0)
current_suit_array_obj[1] = i32(0)
current_suit_array_obj[2] = i32(0)
... and similarly for other arrays
Significance: This working solution came after repeated failures of more intuitive ArrayType, Size, Array[Type].from_tuple(), and ArrayType attempts that consistently yielded the "Array takes 1 generics (2 given)" error. This suggests a very specific and perhaps non-obvious constructor resolution for Array[T] when a size is provided, or a bug in how Array instantiation is parsed and matched to available constructors, especially when dealing with fixed-size types or from_ methods.
Conclusion for Developers:
The primary pain point was the highly misleading and ambiguous error: Array takes 1 generics (2 given) message, which made it extremely difficult to understand the correct Array instantiation syntax. This, combined with the apparent lack of from_list/from_tuple methods for Array[T], created significant debugging challenges. Clarifying Array constructor behaviors, especially for fixed-size arrays and the meaning of generic type parameters in different contexts, would greatly benefit user experience.
Beta Was this translation helpful? Give feedback.
All reactions