Discussion:
[Pdl-porters] 'sec', 'ins', and 'similar_assign' in PDL::Basic
Derek Lamb
2013-08-05 21:49:28 UTC
Permalink
Karl, Christian, etc (original PDL'ers) please weigh in:

I was looking at Basic.pm over the weekend and saw three functions that were unfamiliar, perhaps because they are not documented anywhere: sec, ins, and similar_assign.

1) sec returns a slice of a piddle based on a list of border indices:
pdl> p sec(sequence(10,8),4,6,2,5);

[
[24 25 26]
[34 35 36]
[44 45 46]
[54 55 56]
]

2) ins inserts a piddle into another piddle:
pdl> p ins(sequence(10,8),pdl([4,7,1],[2,8,3]),6,2)

[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 4 7 1 29]
[30 31 32 33 34 35 2 8 3 39]
[40 41 42 43 44 45 46 47 48 49]
[50 51 52 53 54 55 56 57 58 59]
[60 61 62 63 64 65 66 67 68 69]
[70 71 72 73 74 75 76 77 78 79]
]

3) similar_assign is supposed to check that the dim list of two piddles is the same before assigning one to the other, though I am not sure how effective it actually is:
pdl> $a=xvals(5);$b=xvals(5)+3;
pdl> similar_assign($a,$b);
pdl> p $a,$b
[0 1 2 3 4] [0 1 2 3 4] #OK
pdl> $a=xvals(5);$b=xvals(4)+3;
pdl> p $a,$b
[0 1 2 3 4] [3 4 5 6]
pdl> p similar_assign($a,$b)
PDL: PDL::Ops::assgn(a,b): Parameter 'b':
Mismatched implicit thread dimension 0: should be 5, is 4
##presumably similar_assign's check should have caught that--I think it has to do with @{$from->dims} instead of just $from->dims.

Note that range() can do both sec and ins.

All three appeared in Karl's initial import of v1.99987 on 1998-09-20. They are not documented, not tested, and as far as I can tell, do not appear to be used anywhere else in active code in the PDL distribution (similar_assign is used in the defunct Gaussian.pm).

But maybe somebody has some legacy code that uses these? Given their age, I thought I'd check first before deciding to either remove them or add documentation & tests.

cheers,
Derek
Craig DeForest
2013-08-05 21:52:48 UTC
Permalink
Since range() is kind of expensive, sec() might be helpful if it uses affine transformations (for speed).

I don't see a need to keep ins, when you could just use sec() on the lhs of a ".="...
Post by Derek Lamb
I was looking at Basic.pm over the weekend and saw three functions that were unfamiliar, perhaps because they are not documented anywhere: sec, ins, and similar_assign.
pdl> p sec(sequence(10,8),4,6,2,5);
[
[24 25 26]
[34 35 36]
[44 45 46]
[54 55 56]
]
pdl> p ins(sequence(10,8),pdl([4,7,1],[2,8,3]),6,2)
[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 4 7 1 29]
[30 31 32 33 34 35 2 8 3 39]
[40 41 42 43 44 45 46 47 48 49]
[50 51 52 53 54 55 56 57 58 59]
[60 61 62 63 64 65 66 67 68 69]
[70 71 72 73 74 75 76 77 78 79]
]
pdl> $a=xvals(5);$b=xvals(5)+3;
pdl> similar_assign($a,$b);
pdl> p $a,$b
[0 1 2 3 4] [0 1 2 3 4] #OK
pdl> $a=xvals(5);$b=xvals(4)+3;
pdl> p $a,$b
[0 1 2 3 4] [3 4 5 6]
pdl> p similar_assign($a,$b)
Mismatched implicit thread dimension 0: should be 5, is 4
Note that range() can do both sec and ins.
All three appeared in Karl's initial import of v1.99987 on 1998-09-20. They are not documented, not tested, and as far as I can tell, do not appear to be used anywhere else in active code in the PDL distribution (similar_assign is used in the defunct Gaussian.pm).
But maybe somebody has some legacy code that uses these? Given their age, I thought I'd check first before deciding to either remove them or add documentation & tests.
cheers,
Derek
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Karl Glazebrook
2013-10-29 15:33:14 UTC
Permalink
Derek

Sorry for the late reply

sec() was my original v0.1 slicing function just to have something. It got replaced in PDL2 by virtual slicing with slice() by Tuomas Lukka. I don't think anyone uses it in any useful code. It can be removed I think.

I don't know about ins() or similar_assign(). Not one of mine.

Karl
Post by Derek Lamb
I was looking at Basic.pm over the weekend and saw three functions that were unfamiliar, perhaps because they are not documented anywhere: sec, ins, and similar_assign.
pdl> p sec(sequence(10,8),4,6,2,5);
[
[24 25 26]
[34 35 36]
[44 45 46]
[54 55 56]
]
pdl> p ins(sequence(10,8),pdl([4,7,1],[2,8,3]),6,2)
[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 4 7 1 29]
[30 31 32 33 34 35 2 8 3 39]
[40 41 42 43 44 45 46 47 48 49]
[50 51 52 53 54 55 56 57 58 59]
[60 61 62 63 64 65 66 67 68 69]
[70 71 72 73 74 75 76 77 78 79]
]
pdl> $a=xvals(5);$b=xvals(5)+3;
pdl> similar_assign($a,$b);
pdl> p $a,$b
[0 1 2 3 4] [0 1 2 3 4] #OK
pdl> $a=xvals(5);$b=xvals(4)+3;
pdl> p $a,$b
[0 1 2 3 4] [3 4 5 6]
pdl> p similar_assign($a,$b)
Mismatched implicit thread dimension 0: should be 5, is 4
Note that range() can do both sec and ins.
All three appeared in Karl's initial import of v1.99987 on 1998-09-20. They are not documented, not tested, and as far as I can tell, do not appear to be used anywhere else in active code in the PDL distribution (similar_assign is used in the defunct Gaussian.pm).
But maybe somebody has some legacy code that uses these? Given their age, I thought I'd check first before deciding to either remove them or add documentation & tests.
cheers,
Derek
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Doug Hunt
2013-10-29 19:37:22 UTC
Permalink
Hi all: None of my code uses any of these three.

--Doug

***@ucar.edu
Software Engineer
UCAR - COSMIC, Tel. (303) 497-2611
Post by Karl Glazebrook
Derek
Sorry for the late reply
sec() was my original v0.1 slicing function just to have something. It got replaced in PDL2 by virtual slicing with slice() by Tuomas Lukka. I don't think anyone uses it in any useful code. It can be removed I think.
I don't know about ins() or similar_assign(). Not one of mine.
Karl
Post by Derek Lamb
I was looking at Basic.pm over the weekend and saw three functions that were unfamiliar, perhaps because they are not documented anywhere: sec, ins, and similar_assign.
pdl> p sec(sequence(10,8),4,6,2,5);
[
[24 25 26]
[34 35 36]
[44 45 46]
[54 55 56]
]
pdl> p ins(sequence(10,8),pdl([4,7,1],[2,8,3]),6,2)
[
[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 4 7 1 29]
[30 31 32 33 34 35 2 8 3 39]
[40 41 42 43 44 45 46 47 48 49]
[50 51 52 53 54 55 56 57 58 59]
[60 61 62 63 64 65 66 67 68 69]
[70 71 72 73 74 75 76 77 78 79]
]
pdl> $a=xvals(5);$b=xvals(5)+3;
pdl> similar_assign($a,$b);
pdl> p $a,$b
[0 1 2 3 4] [0 1 2 3 4] #OK
pdl> $a=xvals(5);$b=xvals(4)+3;
pdl> p $a,$b
[0 1 2 3 4] [3 4 5 6]
pdl> p similar_assign($a,$b)
Mismatched implicit thread dimension 0: should be 5, is 4
Note that range() can do both sec and ins.
All three appeared in Karl's initial import of v1.99987 on 1998-09-20. They are not documented, not tested, and as far as I can tell, do not appear to be used anywhere else in active code in the PDL distribution (similar_assign is used in the defunct Gaussian.pm).
But maybe somebody has some legacy code that uses these? Given their age, I thought I'd check first before deciding to either remove them or add documentation & tests.
cheers,
Derek
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Loading...