array of array of complex things

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ma740988@gmail.com

    #1

    array of array of complex things


    I'm looking for an equivalent approach to what I would do in C++ such
    to create a vector of vector of complex. I would do :

    typedef std::vector < std::complex < double complex_dvec;
    typedef std::vector < complex_dvec twod_complex_ve c;

    int main() {
    twod_complex_ve c tdv ( 3, 3 );
    for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
    {
    for ( size_t jdx ( 0 ); jdx < tdv.front().siz e(); ++jdx )
    tdv [ idx ] [ jdx ] = idx * jdx ;
    }
    }

    I'm trying to come up with an equivalent C approach to this but I'm
    going around in circles. Source snippet appreaciated.. Thanks in
    advance for

  • dbtid

    #2
    Re: array of array of complex things

    ma740988@gmail. com wrote:
    I'm looking for an equivalent approach to what I would do in C++ such
    to create a vector of vector of complex. I would do :
    >
    typedef std::vector < std::complex < double complex_dvec;
    typedef std::vector < complex_dvec twod_complex_ve c;
    >
    int main() {
    twod_complex_ve c tdv ( 3, 3 );
    for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
    {
    for ( size_t jdx ( 0 ); jdx < tdv.front().siz e(); ++jdx )
    tdv [ idx ] [ jdx ] = idx * jdx ;
    }
    }
    >
    I'm trying to come up with an equivalent C approach to this but I'm
    going around in circles. Source snippet appreaciated.. Thanks in
    advance for
    >

    Comment

    • Bill Pursell

      #3
      Re: array of array of complex things

      ma740988@gmail. com wrote:
      I'm looking for an equivalent approach to what I would do in C++ such
      to create a vector of vector of complex. I would do :
      Assuming C89 with no complex types:

      struct complex {
      double r,i;
      };

      struct vector {
      void *data;
      size_t size;
      };

      struct vector a;

      a.data = malloc(NUM_VEC) ;
      if (a.data == NULL)
      handle_error();

      a.size = NUM_VEC;
      a.data[0] = create_complex_ vector();
      .....
      push_value ( 3.4, -1, a.data[0]);

      You'll obviously want to have the ability
      to reallocate space as the vector grows, and
      you'll want a more generic "constructo r"
      than create_complex_ vector, but the
      above demonstrates some ideas. You
      wouldn't want to call malloc directly on
      a.data, for example. Instead, you'll
      want to write a function that takes perhaps
      an initial size and an allocator function ptr
      as parameters which will create the vector
      for you. You might want to make the vector
      an opaque type and hide the size_t variable
      from the user....lots of ways to do this.

      Comment

      Working...