Jim LaGrone <jlagr...@cs.uh.edu> wrote on 08/26/2009 07:27:07 PM:

> I'm trying to understand how to code the distributions and arrays. Can 
> someone explain what's going on here?
> 
> This code compiles and executes.
> 
> class ComplexArrayDist {
>    public static def main(args: Rail[String] ) {
> 
>       var region: Region{rank == 1};
>       region = [0..9];
>       var dist: Dist = Dist.makeBlock(region,0);
>       var complexArray: Array[Complex](region);
>       complexArray = Array.makeVar[Complex](region,
>          ((p):Point) => new Complex() );
> 
>       for (var i:Int = 0; i < 10; i++){
>          complexArray(i) = new Complex(0,(i as double)/((i+1) as 
double));
>          Console.OUT.println(complexArray(i));
>       }
>    }
> }
> 
> But this code won't compile.
> 
> class ComplexArrayDist {
>    public static def main(args: Rail[String] ) {
> 
>       var region: Region{rank == 1};
>       region = [0..9];
>       var dist: Dist = Dist.makeBlock(region,0);
>       var complexArray: Array[Complex](dist);  //changed from region to 
dist
>       complexArray = Array.makeVar[Complex](dist,  //changed from region 
to dist
>          ((p):Point) => new Complex() );
> 
>       for (var i:Int = 0; i < 10; i++){
>          complexArray(i) = new Complex(0,(i as double)/((i+1) as 
double));
>          Console.OUT.println(complexArray(i));
>       }
>    }
> }
> 
> tests$ x10c ComplexArrayDist.x10
> delta:tests$ x10c ComplexArrayDist.x10
> /Users/jlagrone/GradSchool/Research/workspace/X10-code/tests/ 
> ComplexArrayDist.x10:15: Cannot assign to element of 
> x10.lang.Array[Complex]{}; Method set(T, 
> 
x10.lang.Point{self.x10.lang.Point#rank==x10.lang.Array#this.x10.lang.Array#dist.x10.lang.Dist#region.x10.lang.Region#rank})
 
 
> in x10.lang.Array[Complex] cannot be called with arguments (Complex, 
> x10.lang.Int); Call invalid; actual parameter of type x10.lang.Int 
> cannot be assigned to formal parameter type 
> 
x10.lang.Point{self.x10.lang.Point#rank==_2458.x10.lang.Array#dist.x10.lang.Dist#region.x10.lang.Region#rank}.
> /Users/jlagrone/GradSchool/Research/workspace/X10-code/tests/ 
> ComplexArrayDist.x10:16: Method complexArray(x10.lang.Int) not found.
> [snip duplicates]
> 4 errors.

Hi, Jim,

Granted, our error messages could be better (and there are actually two
errors, not four -- the last two are duplicates).  However, the above is
expected behavior.

Your problem is actually here:

>       var dist: Dist = Dist.makeBlock(region,0);

You've specified an explicit type for the "dist" variable.  That type
overrides the inferred type.  In this case, Dist means a distribution
with unknown rank, so when you create the array over that distribution,
the rank of that array is unknown -- thus you cannot call the set()
and apply() methods indexed by a single int (because the type system
cannot prove that the rank is 1, and so the method guards prevent it),
so the type checker attempts to find another matching method, and, of
course, fails.

When you used the region, you have constrained the rank of the region
to be 1, so the correct methods are matched.

To fix this, either omit the type of "dist" altogether and let the
type system infer it, or use "Dist(1)" (or "Dist{self.rank==1}") as
the type.

It would help us remember to fix the error messages if you opened a
JIRA (I think there is one already for the error duplication issue,
but the fact that the above errors don't mention method guards
should probably be fixed).  However, these will likely be queued
behind other, high-priority, issues in the near future.

Hope this helps,
        Igor
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to